Created
May 26, 2012 20:23
-
-
Save mattmcmanus/2795200 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Assumptions - READ ME | |
// ==================================== | |
// * You have terms setup, which are literal academic terms setup as taxonomy terms. Ie: 2011 - Spring, 2012 - Spring | |
// * You have another taxonmy setup for academic units. For this site, there are Units 1-23 | |
// | |
// What does this do? | |
// ==================================== | |
// It duplicates specific nodes. For example: | |
// * Duplicate Units 5-9,15-20 and PT800 from spring 2011 to spring 2012 | |
// | |
// How to run | |
// =================================== | |
// drush @pt php-script ~/scripts/pt-semester-duplicate.php | |
// | |
// | |
// Enter your variables | |
$oldTermID = 85; // The ID of the term you want to duplicate, "2011 - Spring" for example | |
$newTermID = 88; // The newly created (IE, you just made it) ID for term you want to duplicate TO, "2012 - Spring" | |
$unitsToDuplicate = array(81,51,52,53); // the tids of the of the units to duplicate from the Class Year taxaonomy | |
print "\n\n= = = = = = = = Beginning semester duplicate script = = = = = = = = = = =\n"; | |
print "= = = Written by Matthew McManus ([email protected]) July 2010 = = =\n"; | |
print "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n"; | |
// Generate the query | |
$query = "select distinct n.nid from node n inner join term_node semester on n.vid = semester.vid inner join term_node unit on n.vid = unit.vid where semester.tid = $oldTermID and n.type = 'lecture' and ("; | |
$or = ''; | |
foreach ($unitsToDuplicate as $unit) { | |
$query .= "$or unit.tid = $unit"; | |
$or = ' or'; | |
} | |
$query .= ") order by n.nid;"; | |
// Grab the NIDs | |
$nidsToDuplicate = db_query($query); | |
print " * Old semester NIDs selected\n"; | |
print " * Duplicating NID: "; | |
// Iterate through each node | |
while( $nid = db_result($nidsToDuplicate) ){ | |
$node = node_load($nid); // Load the old node | |
// Clean out old identifiers | |
$node->nid = null; $node->vid = null; | |
// Do standard drupal prep on a node | |
if( !function_exists("node_object_prepare")) { | |
include_once(drupal_get_path('module', 'node') . '/node.pages.inc'); | |
} | |
node_object_prepare(&$node); | |
// Switch Semester Taxonomy | |
$node->taxonomy[$newTermID]['tid'] = $newTermID; // Adding new term | |
unset($node->taxonomy[$oldTermID]); // Removing the old | |
$node->uid = 3;// Set Joanies UID | |
$node->status = 0; // Save it as a draft | |
$node->path = null; // Clear the old path | |
node_save(&$node); // Take it home! | |
print $nid.", "; | |
unset($node); | |
} | |
print "\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n"; | |
print "= = = = = = = = = = = = = = = SUCCESS ! = = = = = = = = = = = = = = = = =\n"; | |
print "= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment