Created
March 4, 2019 21:13
-
-
Save keithpotter21/524aa7a9dd30362c2d561348bf8291d7 to your computer and use it in GitHub Desktop.
Ways to select nodes from Drupal 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
ini_set('display_errors', 'Off'); | |
ini_set('display_startup_errors', 'Off'); | |
//Bootstrap Drupal | |
chdir(getcwd() . '/../'); | |
define('DRUPAL_ROOT', getcwd()); | |
require_once(DRUPAL_ROOT . '/includes/bootstrap.inc'); | |
drupal_override_server_variables(); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
$result = db_query('SELECT n.nid, n.title FROM {node} n, {field_revision_field_schedule} s WHERE n.nid = s.entity_id AND s.field_schedule_value2 <= :now', array(':now' => date('Y-m-d H:m:s'))); | |
foreach ($result as $record) { | |
echo "Deleting nid: " . $record->nid . " " . $record->title; | |
node_delete($nid); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
ini_set('display_errors', 'Off'); | |
ini_set('display_startup_errors', 'Off'); | |
//Bootstrap Drupal | |
chdir(getcwd() . '/../'); | |
define('DRUPAL_ROOT', getcwd()); | |
require_once(DRUPAL_ROOT . '/includes/bootstrap.inc'); | |
drupal_override_server_variables(); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
$query = db_select('node','n'); | |
$query->join('field_revision_field_schedule', 's', 'n.nid = s.entity_id'); | |
$nodes = $query->fields('n',array('nid', 'title')) | |
->condition('s.field_schedule_value2', date('Y-m-d H:m:s'),'<=') | |
->execute() | |
->fetchAll(); | |
foreach ($nodes as $node) { | |
echo "Deleting nid: " . $node->nid . " " . $node->title; | |
node_delete($nid); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
ini_set('display_errors', 'Off'); | |
ini_set('display_startup_errors', 'Off'); | |
//Bootstrap Drupal | |
chdir(getcwd() . '/../'); | |
define('DRUPAL_ROOT', getcwd()); | |
require_once(DRUPAL_ROOT . '/includes/bootstrap.inc'); | |
drupal_override_server_variables(); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
$query = db_select('node','n'); | |
$query->join('field_revision_field_schedule', 's', 'n.nid = s.entity_id'); | |
$query->fields('n',array('nid', 'title')); | |
$query->condition('s.field_schedule_value2', date('Y-m-d H:m:s'),'<='); | |
$nodes2 = $query->execute()->fetchAll(); | |
foreach ($nodes2 as $node2) { | |
echo "Deleting nid: " . $node2->nid . " " . $node2->title; | |
node_delete($nid); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
ini_set('display_errors', 'Off'); | |
ini_set('display_startup_errors', 'Off'); | |
//Bootstrap Drupal | |
chdir(getcwd() . '/../'); | |
define('DRUPAL_ROOT', getcwd()); | |
require_once(DRUPAL_ROOT . '/includes/bootstrap.inc'); | |
drupal_override_server_variables(); | |
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | |
$query = new EntityFieldQuery(); | |
$query->entityCondition('entity_type', 'node') | |
->propertyCondition('type', 'alert') | |
->propertyCondition('status', NODE_PUBLISHED) | |
->fieldCondition('field_schedule', 'value2', date('Y-m-d H:i:s'), '<=') | |
->range(0, 10) | |
->addMetaData('account', user_load(1)); | |
$result = $query->execute(); | |
if (isset($result['node'])) { | |
$nids = array_keys($result['node']); | |
foreach ($nids as $nid) { | |
node_delete($nid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment