2015-09-15 04:52:02 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Dev\Tasks;
|
|
|
|
|
2017-09-27 05:49:11 +02:00
|
|
|
use SilverStripe\AssetAdmin\Helper\ImageThumbnailHelper;
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DB;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Assets\FileMigrationHelper;
|
|
|
|
use SilverStripe\Dev\BuildTask;
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2015-09-15 04:52:02 +02:00
|
|
|
/**
|
|
|
|
* Migrates all 3.x file dataobjects to use the new DBFile field.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class MigrateFileTask extends BuildTask
|
|
|
|
{
|
2015-09-15 04:52:02 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
private static $segment = 'MigrateFileTask';
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
protected $title = 'Migrate File dataobjects from 3.x';
|
2015-09-15 04:52:02 +02:00
|
|
|
|
2019-01-23 06:40:15 +01:00
|
|
|
protected $description =
|
|
|
|
'Imports all files referenced by File dataobjects into the new Asset Persistence Layer introduced in 4.0. ' .
|
|
|
|
'If the task fails or times out, run it again and it will start where it left off.';
|
2015-09-15 04:52:02 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
public function run($request)
|
|
|
|
{
|
2017-09-27 05:49:11 +02:00
|
|
|
if (!class_exists(FileMigrationHelper::class)) {
|
|
|
|
DB::alteration_message("No file migration helper detected", "notice");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-23 06:40:15 +01:00
|
|
|
DB::alteration_message(
|
|
|
|
'If the task fails or times out, run it again and it will start where it left off.',
|
|
|
|
"info"
|
|
|
|
);
|
|
|
|
|
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");
|
|
|
|
}
|
2017-09-27 05:49:11 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2015-09-15 04:52:02 +02:00
|
|
|
}
|