Skip to content

Instantly share code, notes, and snippets.

@radheymkumar
Created December 21, 2018 09:37
Show Gist options
  • Save radheymkumar/f039b8d915a8a21ffefcd0ad3ebc1046 to your computer and use it in GitHub Desktop.
Save radheymkumar/f039b8d915a8a21ffefcd0ad3ebc1046 to your computer and use it in GitHub Desktop.
Cron update Code
/**
* Implements hook_cron().
*/
function csv_uploader_cron() {
$end_date = strtotime(date('Y-m-d H:i:s'));
$start_date = strtotime(date('Y-m-d H:i:s', strtotime("-2 days")));
$query = \Drupal::database()->select('node_field_data','n');
$query->leftjoin('node__field_roles','r', 'n.nid=r.entity_id');
$query->fields('n', ['nid','title','created','type']);
$query->fields('r',['field_roles_value']);
$query->condition('n.status',1);
$query->condition('r.field_roles_value','free','=');
//$query->condition('n.created',array($start_date, $end_date), 'BETWEEN');
$query->condition('n.created', $start_date, '<');
$query->condition('n.type','article','=');
$result = $query->execute()->fetchAll();
foreach ($result as $rows) {
$node = Node::load($rows->nid);
$node->set("field_roles", "pay");
$node->setPublished();
$node->save();
drupal_set_message('Update PAY Roles');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment