silverstripe-framework/src/Dev/Tasks/MigrateFileTask.php

45 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\Dev\Tasks;
use SilverStripe\AssetAdmin\Helper\ImageThumbnailHelper;
use SilverStripe\ORM\DB;
use SilverStripe\Assets\FileMigrationHelper;
use SilverStripe\Dev\BuildTask;
/**
* Migrates all 3.x file dataobjects to use the new DBFile field.
*/
2016-11-29 00:31:16 +01:00
class MigrateFileTask extends BuildTask
{
2016-11-29 00:31:16 +01:00
private static $segment = 'MigrateFileTask';
2016-11-29 00:31:16 +01:00
protected $title = 'Migrate File dataobjects from 3.x';
2016-11-29 00:31:16 +01:00
protected $description
= 'Imports all files referenced by File dataobjects into the new Asset Persistence Layer introduced in 4.0';
2016-11-29 00:31:16 +01:00
public function run($request)
{
if (!class_exists(FileMigrationHelper::class)) {
DB::alteration_message("No file migration helper detected", "notice");
return;
}
2016-11-29 00:31:16 +01:00
$migrated = FileMigrationHelper::singleton()->run();
if ($migrated) {
DB::alteration_message("{$migrated} File DataObjects upgraded", "changed");
} else {
DB::alteration_message("No File DataObjects need upgrading", "notice");
}
if (!class_exists(ImageThumbnailHelper::class)) {
DB::alteration_message("No image thumbnail helper detected", "notice");
return;
}
ImageThumbnailHelper::singleton()->run();
2016-11-29 00:31:16 +01:00
}
}