Example #1
0
 /**
  * Implements hook_cron().
  */
 public static function hookCron()
 {
     $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
     if ($handle_content_expiry != 2) {
         $result = DbHandler::selectExpired();
     } else {
         $result = DbHandler::selectExpiredNonFlagged();
     }
     // $nids = array();
     // Create NodeTypesConfigHandler once for whole cycle.
     $config_handler = new NodeTypesConfigHandler();
     foreach ($result as $record) {
         // Try to handle the record.
         try {
             // $nids[] = $record->nid;
             $node_type = $record->type;
             $action_type = $config_handler->getActionType($node_type);
             $nid = $record->nid;
             DbHandler::setExpired($nid);
             // $node = node_load($record->nid);
             // rules_invoke_event('node_expired', $node);
             ActionsHandler::doAction($action_type, $nid);
         } catch (\Exception $e) {
             // TODO: Add configurable logging.
         }
     }
 }
Example #2
0
 /**
  * Implements hook_node_update() and hook_node_insert().
  */
 private static function doNodeUpdateInsert(&$ntype, $node)
 {
     $handle_content_expiry = ConfigHandler::getHandleContentExpiry();
     if ($handle_content_expiry == 0) {
         // Old (legacy) style of processing.
         // Has the expiration been removed, or does it exist?
         if (isset($node->expire)) {
             DbHandler::deleteNodeExpire($node->nid);
             // Should we create a new record?
             if ($node->expire) {
                 if (strtotime($node->expire)) {
                     $node->expire = strtotime($node->expire);
                 }
                 $node->expired = FALSE;
                 drupal_write_record('node_expire', $node);
             }
         }
     } else {
         if (!isset($ntype['enabled']) || !$ntype['enabled']) {
             return;
         }
         // Create a proper $node_expire stdClass.
         $node_expire = new \stdClass();
         $node_expire->nid = $node->nid;
         // For compatibility with Node Clone module.
         // Set default $node->expire value if it is not set.
         if (!isset($node->expire)) {
             // _node_expire_node_prepare($ntype, $node);
             self::doNodePrepare($ntype, $node);
         }
         // Expire.
         $date_expire = TimestampUtils::dateStrToDb($node->expire, $ntype);
         $node_expire->expire = $date_expire;
         // Lastnotify.
         if (isset($node->lastnotify)) {
             $node_expire->lastnotify = $node->lastnotify;
         } else {
             // Default value.
             $node_expire->lastnotify = 0;
         }
         // Expired.
         if (isset($node->expired)) {
             $node_expire->new_record = 0;
             $node_expire->expired = $node->expired;
             if ($node_expire->expire >= NODE_EXPIRE_NO_EXPIRE) {
                 // No expiry for this node.
                 $node_expire->expired = 0;
             }
         } elseif (isset($node->original->expired)) {
             // For VBO (Views Bulk Operations) compatibility.
             // With VBO it is necessary to get all Node expire information
             // from $node->original instead of $node.
             $node_expire->new_record = 0;
             $node_expire->expired = $node->original->expired;
             // Also get other Node expire values.
             // Expire.
             $date_expire = TimestampUtils::dateStrToDb($node->original->expire, $ntype);
             $node_expire->expire = $date_expire;
             // Lastnotify.
             if (isset($node->original->lastnotify)) {
                 $node_expire->lastnotify = $node->original->lastnotify;
             } else {
                 // Default value.
                 $node_expire->lastnotify = 0;
             }
             if ($node_expire->expire >= NODE_EXPIRE_NO_EXPIRE) {
                 // No expiry for this node.
                 $node_expire->expired = 0;
             }
         } else {
             // No record in the database yet.
             $node_expire->new_record = 1;
             // Default value.
             $node_expire->expired = 0;
         }
         // Write the record.
         DbHandler::writeRecord($node_expire, $node->nid);
     }
 }