Script to fix old numeric IDs to new text IDs
--- a/admin/fixoldamend.php
+++ b/admin/fixoldamend.php
@@ -1,3 +1,26 @@
<?php
-$query = 'select "CNID" from contractnotice where "CNID" like \'%00_\' and "parentCN" is not null and length("CNID") > 6';
+include_once("../lib/common.inc.php");
+$query = 'update contractnotice set "parentCN" = null where "parentCN" = \'0\'';
+$result = $conn->prepare($query);
+$result->execute();
+$query = 'update contractnotice set "childCN" = null where "childCN" = \'0\'';
+$result = $conn->prepare($query);
+$result->execute();
+$query = 'select "CNID","parentCN" from contractnotice where "CNID" like \'%00_\' and "parentCN" is not null';
+$result = $conn->prepare($query);
+$result->execute();
+foreach ($result->fetchAll() as $record) {
+ $oldCN = $record['CNID'];
+ $parentCN = substr($oldCN,0,-3);
+ if ($parentCN == $record['parentCN']) {
+ $newCN = $parentCN . "-A". substr($oldCN,-1);
+ $updateresult = $conn->exec('UPDATE contractnotice SET "CNID" =
+\'' . $newCN . '\' where "CNID" = \'' . $oldCN . '\';');
+ echo "$oldCN => $newCN (from parent CN $parentCN) <br>\n";
+ }
+ else {
+ echo "parent CN unexpected - $oldCN doesn't look like child of {$record['parentCN']} <br>\n";
+ }
+}
+