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