Skip to content Skip to navigation

Mass Taxonomy Term Transfer

Posted by: 
Topics: 
Tags: 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>STEP Taxonomy Term Migration</title>
</head>
 
<body>
<?php
 
if (isset($_POST['submitted'])) { //if the form has been submitted, handle it
 
	//check required form fields
	if (!empty($_POST['tid_orig']) AND (!empty($_POST['tid_new'])) AND (!empty($_POST['tid_parent'])) ){
 
		//MySQL connection information
		require_once('../mysqli_connect.inc.php');
 
		//Establish variables
		$orig = $_POST['tid_orig'];
		$new = $_POST['tid_new'];
		$parent = $_POST['tid_parent'];
 
		//Create the query
		$q = "SELECT nid FROM term_node WHERE tid = $orig";
 
		//Execute the query
		$r = mysqli_query($dbc, $q);
 
		//Return number of rows affected
		$num_rows = mysqli_affected_rows($dbc);
		echo "<h2>Taxonomy Term Results</h2>";
		echo "<strong>$num_rows</strong> rows affected <br />";
 
		//Pull the query results into a numeric array
		while($row = mysqli_fetch_row($r)) {
			$nid_array[] = $row[0];
		}
 
		//Create INSERT query for new tid
		foreach($nid_array as $nid) {
		$q2 = "INSERT IGNORE INTO term_node VALUES ($nid, $new)";
		echo " The query is <em>$q2</em><br />";
 
		//Run the query
		$r2 = mysqli_query($dbc, $q2); 	
		}
 
		//Create INSERT query for parent tid
		foreach($nid_array as $nid) {
		$q3 = "INSERT IGNORE INTO term_node VALUES ($nid, $parent)";
		echo " The query is <em>$q3</em><br />";
 
		//Run the query
		$r3 = mysqli_query($dbc, $q3); 	
		}
 
		//Create DELETE query for parent tid
		$q4 = "DELETE FROM term_node WHERE tid = $orig";
		echo " The query is <em>$q4</em><br />";
		//Run the query
		$r4 = mysqli_query($dbc, $q4); 	
	/*
	*
	* Now we process the Views
	*
	*/
		//Background View
		if (!empty($_POST['vid_background'])){
			$vid_background = $_POST['vid_background'];
 
			//Create DELETE query for the vid
			$q5 = "DELETE FROM view_filter WHERE vid = $vid_background";
 
			//Execute the query
			$r5 = mysqli_query($dbc, $q5);
 
			//Return number of rows affected
			$num_rows = mysqli_affected_rows($dbc);
			echo "<h2>Views Results</h2>";
			echo "<strong>$num_rows</strong> rows deleted <br />";
 
			//Create DELETE query for the vid
			$q6 = "INSERT IGNORE INTO view_filter VALUES ($vid_background, '', 'node.status', 1, '=', '', 0)";
			$q7 = "INSERT IGNORE INTO view_filter VALUES ($vid_background, '', 'node.type', 'biblio', 'OR', '', 1)";		
			$q8 = "INSERT IGNORE INTO view_filter VALUES ($vid_background, '', 'term_node_14.tid', $new, 'OR', '', 2)";		
			$q9 = "INSERT IGNORE INTO view_filter VALUES ($vid_background, '', 'term_node_8.tid', $parent, 'OR', '', 3)";
 
			//Report output
			//Return number of rows affected
			$num_rows = mysqli_affected_rows($dbc);
			echo "<strong>$num_rows</strong> rows inserted <br />";
			//Report queries
			echo "The first SQL query was <em>$q5</em><br />";
			echo "The second SQL query was <em>$q6</em><br />";
			echo "The third SQL query was <em>$q7</em><br />";
			echo "The fourth SQL query was <em>$q8</em><br />";
			echo "The fifth SQL query was <em>$q9</em><br />";
 
			//Execute the query
			$r6 = mysqli_query($dbc, $q6);
			$r7 = mysqli_query($dbc, $q7);
			$r8 = mysqli_query($dbc, $q8);
			$r9 = mysqli_query($dbc, $q9);			
 
		}
 
		//Curriculum View
		if (!empty($_POST['vid_curriculum'])){
			$vid_curriculum = $_POST['vid_curriculum'];
 
			//Create DELETE query for the vid
			$q10 = "DELETE FROM view_filter WHERE vid = $vid_curriculum";
 
			//Execute the query
			$r10 = mysqli_query($dbc, $q10);
 
			//Return number of rows affected
			$num_rows = mysqli_affected_rows($dbc);
			echo "<h2>Views Results</h2>";
			echo "<strong>$num_rows</strong> rows deleted <br />";
 
			//Create DELETE query for the vid
			$q11 = "INSERT IGNORE INTO view_filter VALUES ($vid_curriculum, '', 'node.status', 1, '=', '', 0)";
			$q12 = "INSERT IGNORE INTO view_filter VALUES ($vid_curriculum, '', 'node.type', 'biblio,weblink', 'OR', '', 1)";		
			$q13 = "INSERT IGNORE INTO view_filter VALUES ($vid_curriculum, '', 'term_node_14.tid', $new, 'OR', '', 2)";		
			$q14 = "INSERT IGNORE INTO view_filter VALUES ($vid_curriculum, '', 'term_node_8.tid', $parent, 'OR', '', 3)";
 
			//Report output
			//Return number of rows affected
			$num_rows = mysqli_affected_rows($dbc);
			echo "<strong>$num_rows</strong> rows inserted <br />";
			//Report queries
			echo "The first SQL query was <em>$q10</em><br />";
			echo "The second SQL query was <em>$q11</em><br />";
			echo "The third SQL query was <em>$q12</em><br />";
			echo "The fourth SQL query was <em>$q13</em><br />";
			echo "The fifth SQL query was <em>$q14</em><br />";
 
			//Execute the query
			$r11 = mysqli_query($dbc, $q11);
			$r12 = mysqli_query($dbc, $q12);
			$r13 = mysqli_query($dbc, $q13);
			$r14 = mysqli_query($dbc, $q14);			
 
		}
 
		//Websites View
		if (!empty($_POST['vid_websites'])){
			$vid_websites = $_POST['vid_websites'];
 
			//Create DELETE query for the vid
			$q15 = "DELETE FROM view_filter WHERE vid = $vid_websites";
 
			//Execute the query
			$r15 = mysqli_query($dbc, $q15);
 
			//Return number of rows affected
			$num_rows = mysqli_affected_rows($dbc);
			echo "<h2>Views Results</h2>";
			echo "<strong>$num_rows</strong> rows deleted <br />";
 
			//Create DELETE query for the vid
			$q16 = "INSERT IGNORE INTO view_filter VALUES ($vid_websites, '', 'node.status', 1, '=', '', 0)";
			$q17 = "INSERT IGNORE INTO view_filter VALUES ($vid_websites, '', 'node.type', 'weblink', 'OR', '', 1)";		
			$q18 = "INSERT IGNORE INTO view_filter VALUES ($vid_websites, '', 'term_node_14.tid', $new, 'OR', '', 2)";		
			$q19 = "INSERT IGNORE INTO view_filter VALUES ($vid_websites, '', 'term_node_8.tid', $parent, 'OR', '', 3)";
 
			//Report output
			//Return number of rows affected
			$num_rows = mysqli_affected_rows($dbc);
			echo "<strong>$num_rows</strong> rows inserted <br />";
			//Report queries
			echo "The first SQL query was <em>$q15</em><br />";
			echo "The second SQL query was <em>$q16</em><br />";
			echo "The third SQL query was <em>$q17</em><br />";
			echo "The fourth SQL query was <em>$q18</em><br />";
			echo "The fifth SQL query was <em>$q19</em><br />";
 
			//Execute the query
			$r16 = mysqli_query($dbc, $q16);
			$r17 = mysqli_query($dbc, $q17);
			$r18 = mysqli_query($dbc, $q18);
			$r19 = mysqli_query($dbc, $q19);			
 
		}
 
	} else {
		echo "You must fill out an original, a parent, and a new tid.<br />\n<a href=\"taxonomy_term.php\">Go Back</a>";
	}
 
} 
?>
<h2>STEP Taxonomy Terms</h2>
<p>Choose a STEP taxonomy term to change:</p>
<form action="taxonomy_term.php" method="post">
<strong>Original</strong> term <strong>tid</strong>: <br />
<input type="text" name="tid_orig" size="4" maxlength="4" /><br />
<strong>New</strong> term <strong>tid</strong>: <br />
<input type="text" name="tid_new" size="4" maxlength="4" /><br />
<strong>Parent</strong> term <strong>tid</strong>: <br />
<input type="text" name="tid_parent" size="4" maxlength="4" /><br />
<hr />
<h2>Views (optional)</h2>
 
<!--<input type="checkbox" name="vt_background" value="background" /> 
Background<br />-->
<input type="text" name="vid_background" size="4" maxlength="4" />
Background View vid: <br /><br/>
<!--<input type="checkbox" name="vt_books" value="books" />
Books <br />
<input type="text" name="vid_books" size="4" maxlength="4" />
Books View vid: <br /><br/>
<input type="checkbox" name="vt_ebooks" value="ebooks" />
E-books<br/>
<input type="text" name="vid_ebooks" size="4" maxlength="4" />
E-books View vid: <br /><br/>
<input type="checkbox" name="vt_journals" value="journals" />
Journals<br/>
<input type="text" name="vid_journals" size="4" maxlength="4" />
Journals View vid: <br /><br/>
<input type="checkbox" name="vt_databases" value="databases" />
Databases<br/>
<input type="text" name="vid_databases" size="4" maxlength="4" />
Databases View vid: <br /><br/>
<input type="checkbox" name="vt_curriculum" value="curriculum" />
Curriculum<br/>-->
<input type="text" name="vid_curriculum" size="4" maxlength="4" />
Curriculum View vid: <br /><br/>
<!--<input type="checkbox" name="vt_websites" value="websites" />
Websites<br/>-->
<input type="text" name="vid_websites" size="4" maxlength="4" />
Websites View vid: <br /><br/>
 
<input type="hidden" name="submitted" value="true" />
<input type="submit" name="submit" value="Submit it, Johnny!" />
</form>
 
 
</body>
</html>