Last active
March 3, 2021 13:03
-
-
Save victorkane/17a48e549795d187b92299dde8cf951d to your computer and use it in GitHub Desktop.
DurableDrupal Content Migration Rescue content inventory and extraction scripts
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
#!/usr/local/bin/drush | |
# place system drush PATH on shabang! | |
##!/usr/bin/drush | |
/** | |
* dd-list-content-by-content-type.php | |
* list content types. | |
* see https://drupal.stackexchange.com/questions/97642/how-can-i-get-a-list-of-content-types-with-drush | |
* | |
* While this functionality is more readily available via | |
* drush views-data-export content_audit views_data_export_1 data/inv_content_audit.csv | |
* we still want to implement it as a way of preparing to upsert to SCS | |
* iinstead of merely listing data | |
* | |
* Sample execution from document root: | |
* | |
* ./scripts/dd-list-content-by-content-type.php | |
* ./scripts/dd-list-content-by-content-type.php > scripts/data/inv-content-by-conetent-type.txt | |
* | |
* Sample execution from document root (full, with node_load): | |
* | |
* ./scripts/dd-list-content-by-content-type.php full | |
* ./scripts/dd-list-content-by-content-type.php full > scripts/data/inv-content-by-conetent-type-full.txt | |
*/ | |
$args = drush_get_arguments(); | |
$full = $args[2]; | |
print("Machine name | Name (Description)\n"); | |
print("----------------------------------\n"); | |
// d7: $the_content_types = node_type_get_types(); | |
$the_content_types = node_get_types(); | |
//print_r($the_content_types); | |
foreach($the_content_types as $key => $value) { | |
$node_type = $key; | |
print($key . ': ' . $value->name . ' (' . $value->description . ")\n"); | |
print("----------------------------------\n"); | |
/* d6 | |
*/ | |
$result = db_query('SELECT nid FROM node WHERE type = "%s"', $node_type); | |
$nids = array(); | |
$ncount = 0; | |
while ($obj = db_fetch_object($result)) { | |
$ncount++; | |
$nids[] = $obj->nid; | |
$node = node_load($obj->nid); | |
print('nid ' . $node->nid . ' [status ' . $node->status . ']: ' . $node->title . "\n"); | |
($full) ? print_r($node) : NULL; | |
} | |
print('Count: ' . '[' . $node_type . ': ' . $ncount . ']' . "\n"); | |
/* d7 | |
$result = db_query("SELECT nid FROM node WHERE type = :nodeType ", array(':nodeType'=>$node_type)); | |
$nids = array(); | |
foreach ($result as $obj) { | |
$nids[] = $obj->nid; | |
//print_r($obj); | |
$node = node_load($obj->nid); | |
print('nid ' . $node->nid . ': ' . $node->title . "\n"); | |
} | |
*/ | |
print("----------------------------------\n"); | |
} |
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
#!/usr/local/bin/drush | |
# place system drush PATH on shabang! | |
##!/usr/bin/drush | |
/** | |
* Execute from Drupal 6 document root: | |
* | |
* .scripts/dd-list-content-types-and-item-count.php > scripts/data/inv-content-types-with-item-count.txt | |
*/ | |
$the_content_types = node_get_types(); | |
// print_r($the_content_types); | |
foreach($the_content_types as $the_content_type) { | |
$node_type = $the_content_type->type; | |
$node_name = $the_content_type->name; | |
$node_description = $the_content_type->description; | |
$num = 0; | |
$num_pub = 0; | |
$result = db_query('SELECT nid, title, status FROM node WHERE type = "%s" ', $node_type); | |
while ($obj = db_fetch_object($result)) { | |
// print_r($obj); | |
$num++; | |
if ($obj->status > 0) $num_pub++; | |
} | |
print($node_type . ' (' . $node_name . '): ' . $num_pub . ' of ' . $num . " published items\n"); | |
print($node_description . "\n\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment