function requireDefaultRecords() { parent::requireDefaultRecords(); if (isset($_GET["updatepayment"])) { DB::query("\n\t\t\t\tUPDATE \"Payment\"\n\t\t\t\tSET \"AmountAmount\" = \"Amount\"\n\t\t\t\tWHERE\n\t\t\t\t\t\"Amount\" > 0\n\t\t\t\t\tAND (\n\t\t\t\t\t\t\"AmountAmount\" IS NULL\n\t\t\t\t\t\tOR \"AmountAmount\" = 0\n\t\t\t\t\t)\n\t\t\t"); $countAmountChanges = DB::affectedRows(); if ($countAmountChanges) { DB::alteration_message("Updated Payment.Amount field to 2.4 - {$countAmountChanges} rows updated", "edited"); } DB::query("\n\t\t\t\tUPDATE \"Payment\"\n\t\t\t\tSET \"AmountCurrency\" = \"Currency\"\n\t\t\t\tWHERE\n\t\t\t\t\t\"Currency\" <> ''\n\t\t\t\t\tAND \"Currency\" IS NOT NULL\n\t\t\t\t\tAND (\n\t\t\t\t\t\t\"AmountCurrency\" IS NULL\n\t\t\t\t\t\tOR \"AmountCurrency\" = ''\n\t\t\t\t\t)\n\t\t\t"); $countCurrencyChanges = DB::affectedRows(); if ($countCurrencyChanges) { DB::alteration_message("Updated Payment.Currency field to 2.4 - {$countCurrencyChanges} rows updated", "edited"); } if ($countAmountChanges != $countCurrencyChanges) { DB::alteration_message("Potential error in Payment fields update to 2.4, please review data", "deleted"); } } }
function requireDefaultRecords() { parent::requireDefaultRecords(); $bt = defined('DB::USE_ANSI_SQL') ? '"' : '`'; $update = array(); $siteConfig = DataObject::get_one('SiteConfig'); $folder = Folder::findOrMake(self::get_folder_name()); if ($siteConfig && $folder) { $fullArray = self::get_images_to_replace(); //copying .... if ($fullArray) { foreach ($fullArray as $key => $array) { $className = $array["ClassName"]; $fieldName = $array["FieldName"] . "ID"; if (class_exists($className)) { $dataObject = singleton($className); $dbFieldName = $array["DBFieldName"]; $fileName = basename($array["CopyFromPath"]); $fromLocationLong = Director::baseFolder() . '/' . $array["CopyFromPath"]; $toLocationShort = "assets/" . self::get_folder_name() . "/{$fileName}"; $toLocationLong = Director::baseFolder() . '/' . $toLocationShort; $image = DataObject::get_one('Image', "Filename='{$toLocationShort}' AND ParentID = " . $folder->ID); if (!$image) { if (!file_exists($toLocationLong)) { copy($fromLocationLong, $toLocationLong); } $image = new Image(); $image->ParentID = $folder->ID; $image->FileName = $toLocationShort; $image->setName($fileName); $image->write(); } elseif (!$image && file_exists($toLocationLong)) { debug::show("need to update files"); } if ($image && $image->ID) { if (!$siteConfig->{$dbFieldName}) { $siteConfig->{$dbFieldName} = $image->ID; $update[] = "created placeholder image for {$key}"; } $updateSQL = " UPDATE {$bt}" . $className . "{$bt}"; if (isset($_GET["removeplaceholderimages"])) { $setSQL = " SET {$bt}" . $fieldName . "{$bt} = 0"; $whereSQL = " WHERE {$bt}" . $fieldName . "{$bt} = " . $image->ID; DB::alteration_message("removing " . $className . "." . $fieldName . " placeholder images", 'deleted'); } else { DB::alteration_message("adding " . $className . "." . $fieldName . " placeholder images", 'created'); $setSQL = " SET {$bt}" . $fieldName . "{$bt} = " . $image->ID; if (!isset($_GET["forceplaceholder"])) { $whereSQL = " WHERE {$bt}" . $fieldName . "{$bt} IS NULL OR {$bt}" . $fieldName . "{$bt} = 0"; } else { $whereSQL = ''; } } $sql = $updateSQL . $setSQL . $whereSQL; DB::query($sql); $versioningPresent = false; $array = $dataObject->stat('extensions'); if (is_array($array) && count($array)) { if (in_array("Versioned('Stage', 'Live')", $array)) { $versioningPresent = true; } } if ($dataObject->stat('versioning')) { $versioningPresent = true; } if ($versioningPresent) { $sql = str_replace("{$bt}{$className}{$bt}", "{$bt}{$className}_Live{$bt}", $sql); DB::query($sql); } } else { debug::show("could not create image!" . print_r($array)); } } else { debug::show("bad classname reference " . $className); } } } if (count($update)) { $siteConfig->write(); DB::alteration_message($siteConfig->ClassName . " created/updated: " . implode(" --- ", $update), 'created'); } } elseif (!$folder) { debug::show("COULD NOT CREATE FOLDER: " . self::get_folder_name()); } }