public static function PhotosAlbum::resetCount in Album Photos 8.4
Same name and namespace in other branches
- 8.5 src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::resetCount()
- 6.0.x src/PhotosAlbum.php \Drupal\photos\PhotosAlbum::resetCount()
Update count.
1 call to PhotosAlbum::resetCount()
- photos_cron in ./
photos.module - Implements hook_cron().
File
- src/
PhotosAlbum.php, line 540
Class
- PhotosAlbum
- Create an album object.
Namespace
Drupal\photosCode
public static function resetCount($cron = 0) {
PhotosAlbum::setCount('site_album');
PhotosAlbum::setCount('site_image');
$time = $cron ? 7200 : 0;
// @todo optimize. Check if new images since last count.
$cron_last = \Drupal::state()
->get('system.cron_last', 0);
if (\Drupal::time()
->getRequestTime() - $cron_last > $time) {
$db = \Drupal::database();
$result = $db
->query('SELECT uid FROM {users} WHERE uid <> 0');
foreach ($result as $t) {
PhotosAlbum::setCount('user_image', $t->uid);
PhotosAlbum::setCount('user_album', $t->uid);
}
$result = $db
->query('SELECT pid FROM {photos_album}');
foreach ($result as $t) {
PhotosAlbum::setCount('node_album', $t->pid);
}
$result = $db
->query('SELECT DISTINCT(nid) FROM {photos_node}');
foreach ($result as $t) {
PhotosAlbum::setCount('node_node', $t->nid);
}
}
}