From 9631f1575c8292949763013109ff158cc31afb5e Mon Sep 17 00:00:00 2001 From: James Cocker Date: Wed, 21 Jul 2021 12:00:18 +0100 Subject: [PATCH] Added upgrade script --- code/UpgradeBasicGalleriesTask.php | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 code/UpgradeBasicGalleriesTask.php diff --git a/code/UpgradeBasicGalleriesTask.php b/code/UpgradeBasicGalleriesTask.php new file mode 100644 index 0000000..2d171de --- /dev/null +++ b/code/UpgradeBasicGalleriesTask.php @@ -0,0 +1,53 @@ +setFrom('PhotoGalleryImage'); + $sqlQuery->selectField('PhotoGalleryPageID'); + $result = $sqlQuery->execute(); + + $updatecount = 0; + + foreach($result as $row) { + if(isset($row['PhotoGalleryPageID']) && $row['PhotoGalleryPageID']) { + $page = SiteTree::get()->byID($row['PhotoGalleryPageID']); + if($page->exists()) { + $pageClassname = $page->ClassName; + $update = SQLUpdate::create('"PhotoGalleryImage"')->addWhere(['ID' => $row['ID']]); + $update->assign('"AlbumID"', $row['PhotoGalleryPageID']); + $update->assign('"AlbumClass"', $pageClassname); + $update->assign('"PhotoGalleryPageID"', 0); + $update->execute(); + $updatecount++; + } + } + if(isset($row['PhotoGalleryBlockID']) && $row['PhotoGalleryBlockID']) { + $update = SQLUpdate::create('"PhotoGalleryImage"')->addWhere(['ID' => $row['ID']]); + $update->assign('"AlbumID"', $row['PhotoGalleryBlockID']); + $update->assign('"AlbumClass"', "PurpleSpider\ElementalBasicGallery\ImageGalleryBlock"); + $update->assign('"PhotoGalleryBlockID"', 0); + $update->execute(); + $updatecount++; + } + } + + echo($updatecount." records updated."); + + } + +} \ No newline at end of file