comparison core/modules/history/history.module @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
7 * @todo 7 * @todo
8 * - Generic helper for _forum_user_last_visit() + history_read(). 8 * - Generic helper for _forum_user_last_visit() + history_read().
9 * - Generic helper for node_mark(). 9 * - Generic helper for node_mark().
10 */ 10 */
11 11
12 use Drupal\Core\Url;
12 use Drupal\Core\Entity\EntityInterface; 13 use Drupal\Core\Entity\EntityInterface;
13 use Drupal\Core\Entity\Display\EntityViewDisplayInterface; 14 use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
14 use Drupal\Core\Routing\RouteMatchInterface; 15 use Drupal\Core\Routing\RouteMatchInterface;
15 use Drupal\user\UserInterface; 16 use Drupal\user\UserInterface;
16 17
27 */ 28 */
28 function history_help($route_name, RouteMatchInterface $route_match) { 29 function history_help($route_name, RouteMatchInterface $route_match) {
29 switch ($route_name) { 30 switch ($route_name) {
30 case 'help.page.history': 31 case 'help.page.history':
31 $output = '<h3>' . t('About') . '</h3>'; 32 $output = '<h3>' . t('About') . '</h3>';
32 $output .= '<p>' . t('The History module keeps track of which content a user has read. It marks content as <em>new</em> or <em>updated</em> depending on the last time the user viewed it. History records that are older than one month are removed during cron, which means that content older than one month is always considered <em>read</em>. The History module does not have a user interface but it provides a filter to <a href=":views-help">Views</a> to show new or updated content. For more information, see the <a href=":url">online documentation for the History module</a>.', [':views-help' => (\Drupal::moduleHandler()->moduleExists('views')) ? \Drupal::url('help.page', ['name' => 'views']) : '#', ':url' => 'https://www.drupal.org/documentation/modules/history']) . '</p>'; 33 $output .= '<p>' . t('The History module keeps track of which content a user has read. It marks content as <em>new</em> or <em>updated</em> depending on the last time the user viewed it. History records that are older than one month are removed during cron, which means that content older than one month is always considered <em>read</em>. The History module does not have a user interface but it provides a filter to <a href=":views-help">Views</a> to show new or updated content. For more information, see the <a href=":url">online documentation for the History module</a>.', [':views-help' => (\Drupal::moduleHandler()->moduleExists('views')) ? Url::fromRoute('help.page', ['name' => 'views'])->toString() : '#', ':url' => 'https://www.drupal.org/documentation/modules/history']) . '</p>';
33 return $output; 34 return $output;
34 } 35 }
35 } 36 }
36 37
37 /** 38 /**
106 if (!isset($account)) { 107 if (!isset($account)) {
107 $account = \Drupal::currentUser(); 108 $account = \Drupal::currentUser();
108 } 109 }
109 110
110 if ($account->isAuthenticated()) { 111 if ($account->isAuthenticated()) {
111 db_merge('history') 112 \Drupal::database()->merge('history')
112 ->keys([ 113 ->keys([
113 'uid' => $account->id(), 114 'uid' => $account->id(),
114 'nid' => $nid, 115 'nid' => $nid,
115 ]) 116 ])
116 ->fields(['timestamp' => REQUEST_TIME]) 117 ->fields(['timestamp' => REQUEST_TIME])
123 124
124 /** 125 /**
125 * Implements hook_cron(). 126 * Implements hook_cron().
126 */ 127 */
127 function history_cron() { 128 function history_cron() {
128 db_delete('history') 129 \Drupal::database()->delete('history')
129 ->condition('timestamp', HISTORY_READ_LIMIT, '<') 130 ->condition('timestamp', HISTORY_READ_LIMIT, '<')
130 ->execute(); 131 ->execute();
131 } 132 }
132 133
133 /** 134 /**
150 151
151 /** 152 /**
152 * Implements hook_ENTITY_TYPE_delete() for node entities. 153 * Implements hook_ENTITY_TYPE_delete() for node entities.
153 */ 154 */
154 function history_node_delete(EntityInterface $node) { 155 function history_node_delete(EntityInterface $node) {
155 db_delete('history') 156 \Drupal::database()->delete('history')
156 ->condition('nid', $node->id()) 157 ->condition('nid', $node->id())
157 ->execute(); 158 ->execute();
158 } 159 }
159 160
160 /** 161 /**
161 * Implements hook_user_cancel(). 162 * Implements hook_user_cancel().
162 */ 163 */
163 function history_user_cancel($edit, UserInterface $account, $method) { 164 function history_user_cancel($edit, UserInterface $account, $method) {
164 switch ($method) { 165 switch ($method) {
165 case 'user_cancel_reassign': 166 case 'user_cancel_reassign':
166 db_delete('history') 167 \Drupal::database()->delete('history')
167 ->condition('uid', $account->id()) 168 ->condition('uid', $account->id())
168 ->execute(); 169 ->execute();
169 break; 170 break;
170 } 171 }
171 } 172 }
172 173
173 /** 174 /**
174 * Implements hook_ENTITY_TYPE_delete() for user entities. 175 * Implements hook_ENTITY_TYPE_delete() for user entities.
175 */ 176 */
176 function history_user_delete($account) { 177 function history_user_delete($account) {
177 db_delete('history') 178 \Drupal::database()->delete('history')
178 ->condition('uid', $account->id()) 179 ->condition('uid', $account->id())
179 ->execute(); 180 ->execute();
180 } 181 }
181 182
182 /** 183 /**