How to re-publish nodes after unpublishing with hook_cron? Good morning, 

I'm running some tests with hook_cron in Drupal 8. My goal is to unpublish nodes of a specific content type ('event'), and once I enabled my module, I was able to accomplish this. However, after setting $node->setPublished to 'true,' I was unable to accomplish publishing said nodes again after running cron, running Drush CR, and restarting Apache.

Anyone know of any good hooks to resolve this?

function scheduler_publish_cron() {
  $nids = \Drupal::entityQuery("node")
    -&gt;condition('type', 'event')
    -&gt;execute();
$storage_handler = \Drupal::entityTypeManager()-&gt;getStorage("node");
$nodes = $storage_handler-&gt;loadMultiple($nids);
foreach ($nodes as $node) {
// Unpublish nodes
// $node-&gt;setPublished(false);
 // Publish nodes
$node-&gt;setPublished(true);
    $node-&gt;save();
  }
}
Try to disable access checking in the second run, because after unpublishing the node you might no longer have access to them (depending on the user account the code runs with):

$nids = \Drupal::entityQuery('node')
  -&gt;condition('type', 'event')
  -&gt;accessCheck(FALSE)
  -&gt;execute();