function heartbeat_cron in Heartbeat 8
Same name and namespace in other branches
- 6.4 heartbeat.module \heartbeat_cron()
- 7 heartbeat.module \heartbeat_cron()
Implements hook_cron().
File
- ./
heartbeat.module, line 293 - Contains heartbeat.module.
Code
function heartbeat_cron() {
//Iterate over the Heartbeat Types and ensure that the weight of bundle-specific types are lower than that of their
//parent type. This will allow us to ensure Bundle specific types end up being published as opposed to
//Types which represent all content types
$heartbeatTypes = \Drupal::service('entity.query')
->get('heartbeat_type')
->condition('mainentity', 'node')
->execute();
foreach ($heartbeatTypes as $heartbeatType) {
$entity = \Drupal::service('entity_type.manager')
->getStorage('heartbeat_type')
->load($heartbeatType);
if ($entity
->getBundle() === null) {
$entity
->setWeight(99);
$entity
->save();
}
else {
$entity
->setWeight(0);
$entity
->save();
}
if ($entity
->getMainEntity() === 'flagging') {
$friendship = true;
$flagService = \Drupal::service('flag');
foreach ($flagService
->getAllFlags('user') as $flag) {
if ($flag
->id() === 'friendship') {
$flaggings = \Drupal\Core\Database\Database::getConnection()
->select('flagging', 'f')
->fields('f', array(
'entity_id',
'uid',
))
->condition('flag_id', $flag
->id())
->execute();
foreach ($flaggings
->fetchAll() as $flagging) {
$friendship = \Drupal\Core\Database\Database::getConnection()
->select('heartbeat_friendship', 'hf')
->fields(array(
'status',
))
->condition('uid', $flagging->uid)
->condition('uid_target', $flagging->entity_id)
->execute();
if ($friendship = $friendship
->fetchObject()) {
$status = $friendship->status;
$revFriendship = \Drupal\Core\Database\Database::getConnection()
->select('heartbeat_friendship', 'hf')
->fields(array(
'status',
))
->condition('uid', $flagging->entity_id)
->condition('uid_target', $flagging->uid)
->execute();
if ($revFriendship = $revFriendship
->fetchObject()) {
$revStatus = $revFriendship->status;
}
}
}
}
}
}
// $entityQuery = \Drupal::service('entity.query')->get('flag
// foreach ($flagService->)
}
heartbeat_friendship_maintenance();
}