Start graph and import refactoring
[contractdashboard.git] / admin / linkAmendments.php
blob:a/admin/linkAmendments.php -> blob:b/admin/linkAmendments.php
--- a/admin/linkAmendments.php
+++ b/admin/linkAmendments.php
@@ -1,17 +1,22 @@
 <?php
 include_once ("../lib/common.inc.php");
-$query = 'SELECT "CNID","parentCN","amendmentReason" FROM contractnotice WHERE
-"parentCN" > 0 ';
+$query = 'SELECT c."CNID",c."parentCN",c."amendmentReason",p."childCN" FROM contractnotice as c  LEFT OUTER JOIN contractnotice as p on c."parentCN" = p."CNID"
+WHERE
+c."parentCN" > 0 AND p."childCN" IS NULL ';
 $query = $conn->prepare($query);
 	$query->execute();
 	if (!$query) {
 		databaseError($conn->errorInfo());
 	}
 foreach ($query->fetchAll() as $row) {
-  $conn->exec('UPDATE contractnotice SET childCN = "' .
-			 $row['CNID'] . '", amendmentReason = "' .
-			 $row['amendmentReason'] . '" where "CNID" = "' .
-			 $row['parentCN'] . '";');
+  $conn->exec('UPDATE contractnotice SET "childCN" = \'' .
+			 $row['CNID'] . '\', "amendmentReason" = \'' .
+			 $row['amendmentReason'] . '\' where "CNID" = \'' .
+			 $row['parentCN'] . '\';');
+			 echo 'UPDATE contractnotice SET "childCN" = \'' .
+			 $row['CNID'] . '\', "amendmentReason" = \'' .
+			 $row['amendmentReason'] . '\' where "CNID" = \'' .
+			 $row['parentCN'] . '\';';
     $errors = $conn->errorInfo();
               
               if ($errors[1] == 7 || $errors[1] ==0)