1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Dev\Tasks; |
4
|
|
|
|
5
|
|
|
use Monolog\Handler\StreamHandler; |
6
|
|
|
use Monolog\Logger; |
7
|
|
|
use Psr\Log\LoggerInterface; |
8
|
|
|
use SilverStripe\AssetAdmin\Helper\ImageThumbnailHelper; |
|
|
|
|
9
|
|
|
use SilverStripe\Control\Director; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Logging\PreformattedEchoHandler; |
12
|
|
|
use SilverStripe\ORM\DB; |
13
|
|
|
use SilverStripe\Assets\FileMigrationHelper; |
14
|
|
|
use SilverStripe\Dev\BuildTask; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Migrates all 3.x file dataobjects to use the new DBFile field. |
18
|
|
|
*/ |
19
|
|
|
class MigrateFileTask extends BuildTask |
20
|
|
|
{ |
21
|
|
|
private static $segment = 'MigrateFileTask'; |
|
|
|
|
22
|
|
|
|
23
|
|
|
protected $title = 'Migrate File dataobjects from 3.x'; |
24
|
|
|
|
25
|
|
|
protected $description = |
26
|
|
|
'Imports all files referenced by File dataobjects into the new Asset Persistence Layer introduced in 4.0. ' . |
27
|
|
|
'If the task fails or times out, run it again and it will start where it left off.'; |
28
|
|
|
|
29
|
|
|
public function run($request) |
30
|
|
|
{ |
31
|
|
|
$this->addLogHandlers(); |
32
|
|
|
|
33
|
|
|
if (!class_exists(FileMigrationHelper::class)) { |
34
|
|
|
DB::alteration_message("No file migration helper detected", "notice"); |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
DB::alteration_message( |
39
|
|
|
'If the task fails or times out, run it again and it will start where it left off.', |
40
|
|
|
"info" |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$migrated = FileMigrationHelper::singleton()->run(); |
44
|
|
|
if ($migrated) { |
45
|
|
|
DB::alteration_message("{$migrated} File DataObjects upgraded", "changed"); |
46
|
|
|
} else { |
47
|
|
|
DB::alteration_message("No File DataObjects need upgrading", "notice"); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (!class_exists(ImageThumbnailHelper::class)) { |
51
|
|
|
DB::alteration_message("No image thumbnail helper detected", "notice"); |
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
ImageThumbnailHelper::singleton()->run(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* TODO Refactor this whole mess into Symfony Console on a TaskRunner level, |
59
|
|
|
* with a thin wrapper to show coloured console output via a browser: |
60
|
|
|
* https://github.com/silverstripe/silverstripe-framework/issues/5542 |
61
|
|
|
* @throws \Exception |
62
|
|
|
*/ |
63
|
|
|
protected function addLogHandlers() |
64
|
|
|
{ |
65
|
|
|
if ($logger = Injector::inst()->get(LoggerInterface::class)) { |
66
|
|
|
if (Director::is_cli()) { |
67
|
|
|
$logger->pushHandler(new StreamHandler('php://stdout')); |
68
|
|
|
$logger->pushHandler(new StreamHandler('php://stderr', Logger::WARNING)); |
69
|
|
|
} else { |
70
|
|
|
$logger->pushHandler(new PreformattedEchoHandler()); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths