We recently upgraded to Drupal 9.3.0 using a Composer file layout. The resulting website is working correctly and is now running in the publish domain. We have a set of utilities that we run as Drush scripts. One of these unpublishes content that we do not want google and other search engines to find -- yet.
I moved into the directory that contains composer.json -- one level above the webroot. I ran composer require drush/drush
which added "drush/drush": "^11.0",
to composer.json and updated the vendor directory accordingly. I then created a small php script to unpublish a node -- named x.php:
<?php
use Drupal\node\Entity\Node;
print "Top\n";
$node = Node::load('1881');
$node->setPublished(FALSE);
$node->save();
print "Bot\n";
I ran vendor/drush/drush/drush scr x.php
. The script runs without error and prints "Top" and "Bot" as expected. However, running this commend Did Not unpublish nid = 1881. I ran the command again with the -d
switch which gave me lots of output -- but no error messages to work with. I checked the error_log for the website -- nothing. I added a var_dump($node);
after the $node = Node::load('1881');
and can see the node is being loaded.
I need to unpublish over 700 nodes and do not want to do this manually. Any suggestions on how to proceed?