-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silverstripe 3 to 4 migration feature review
- Loading branch information
1 parent
74ed315
commit e5af4d2
Showing
29 changed files
with
1,792 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace App\BatchPublish\Asset; | ||
|
||
use App\Queue; | ||
use SilverStripe\Assets\File; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class Job extends Queue\Job | ||
{ | ||
|
||
public function getTitle(): string | ||
{ | ||
return 'Batch publish asset'; | ||
} | ||
|
||
public function hydrate(array $items): void | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
/** | ||
* @param mixed $item | ||
*/ | ||
protected function processItem($item): void | ||
{ | ||
Versioned::withVersionedMode(function () use ($item): void { | ||
Versioned::set_stage(Versioned::DRAFT); | ||
|
||
/** @var File $file */ | ||
$file = File::get()->byID($item); | ||
|
||
if (!$file || !$file->exists()) { | ||
$this->addMessage('File not found ' . $item); | ||
|
||
return; | ||
} | ||
|
||
$file->write(); | ||
|
||
// force new version to be written | ||
$file->copyVersionToStage(Versioned::DRAFT, Versioned::DRAFT); | ||
|
||
$file->publishRecursive(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\BatchPublish\Asset; | ||
|
||
use App\Queue\Factory; | ||
use SilverStripe\Assets\File; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class Task extends Factory\Task | ||
{ | ||
|
||
private const CHUNK_SIZE = 5; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $segment = 'batch-publish-asset-task'; | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'Generate asset publish jobs'; | ||
} | ||
|
||
/** | ||
* @param HTTPRequest $request | ||
*/ | ||
public function run($request): void // phpcs:ignore SlevomatCodingStandard.TypeHints | ||
{ | ||
Versioned::withVersionedMode(function () use ($request): void { | ||
Versioned::set_stage(Versioned::LIVE); | ||
|
||
$list = File::get()->sort('ID', 'ASC'); | ||
$this->queueJobsFromList($request, $list, Job::class, self::CHUNK_SIZE); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\BatchPublish\Folder; | ||
|
||
use App\Queue; | ||
use SilverStripe\Assets\Folder; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class Job extends Queue\Job | ||
{ | ||
|
||
public function getTitle(): string | ||
{ | ||
return 'Batch publish folder'; | ||
} | ||
|
||
public function hydrate(array $items): void | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
/** | ||
* @param mixed $item | ||
*/ | ||
protected function processItem($item): void | ||
{ | ||
Versioned::withVersionedMode(function () use ($item): void { | ||
Versioned::set_stage(Versioned::DRAFT); | ||
|
||
/** @var Folder $folder */ | ||
$folder = Folder::get()->byID($item); | ||
|
||
if (!$folder) { | ||
$this->addMessage('Folder not found ' . $item); | ||
|
||
return; | ||
} | ||
|
||
if ($folder->isPublished()) { | ||
return; | ||
} | ||
|
||
$folder->write(); | ||
|
||
// force new version to be written | ||
$folder->copyVersionToStage(Versioned::DRAFT, Versioned::DRAFT); | ||
|
||
$folder->publishRecursive(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace App\BatchPublish\Folder; | ||
|
||
use App\Queue\Factory; | ||
use SilverStripe\Assets\Folder; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class Task extends Factory\Task | ||
{ | ||
|
||
private const CHUNK_SIZE = 1; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $segment = 'batch-publish-folder-task'; | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'Generate folder publish jobs'; | ||
} | ||
|
||
/** | ||
* @param HTTPRequest $request | ||
*/ | ||
public function run($request): void // phpcs:ignore SlevomatCodingStandard.TypeHints | ||
{ | ||
Versioned::withVersionedMode(function () use ($request): void { | ||
Versioned::set_stage(Versioned::DRAFT); | ||
|
||
$list = Folder::get() | ||
->sort('ID', 'ASC'); | ||
|
||
$this->queueJobsFromList($request, $list, Job::class, self::CHUNK_SIZE); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace App\BatchPublish\Page; | ||
|
||
use App\Queue; | ||
use Page; | ||
use SilverStripe\CMS\Model\SiteTree; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class Job extends Queue\Job | ||
{ | ||
|
||
public function getTitle(): string | ||
{ | ||
return 'Batch publish page'; | ||
} | ||
|
||
public function hydrate(array $items): void | ||
{ | ||
$this->items = $items; | ||
} | ||
|
||
/** | ||
* @param mixed $item | ||
*/ | ||
protected function processItem($item): void | ||
{ | ||
Versioned::withVersionedMode(function () use ($item): void { | ||
Versioned::set_stage(Versioned::DRAFT); | ||
|
||
/** @var SiteTree $page */ | ||
$page = SiteTree::get()->byID($item); | ||
|
||
if ($page === null) { | ||
$this->addMessage('Page not found ' . $item); | ||
|
||
return; | ||
} | ||
|
||
Page::singleton()->withSkippedSiblingSortPublish(static function () use ($page): void { | ||
$page->write(); | ||
|
||
// force new version to be written | ||
$page->copyVersionToStage(Versioned::DRAFT, Versioned::DRAFT); | ||
|
||
$page->publishRecursive(); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\BatchPublish\Page; | ||
|
||
use App\Queue\Factory; | ||
use SilverStripe\CMS\Model\SiteTree; | ||
use SilverStripe\Control\HTTPRequest; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class Task extends Factory\Task | ||
{ | ||
|
||
private const CHUNK_SIZE = 1; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private static $segment = 'batch-publish-page-task'; | ||
|
||
public function getDescription(): string | ||
{ | ||
return 'Generate page publish jobs'; | ||
} | ||
|
||
/** | ||
* @param HTTPRequest $request | ||
*/ | ||
public function run($request): void // phpcs:ignore SlevomatCodingStandard.TypeHints | ||
{ | ||
Versioned::withVersionedMode(function () use ($request): void { | ||
Versioned::set_stage(Versioned::LIVE); | ||
|
||
$list = SiteTree::get()->sort('ID', 'ASC'); | ||
$this->queueJobsFromList($request, $list, Job::class, self::CHUNK_SIZE); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace App\FileMigration\FileBinary; | ||
|
||
use Generator; | ||
use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper; | ||
use SilverStripe\Assets\File; | ||
use SilverStripe\ORM\DataList; | ||
|
||
class Helper extends FileMigrationHelper | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $ids = []; | ||
|
||
public function setIds(array $ids): self | ||
{ | ||
$this->ids = $ids; | ||
|
||
return $this; | ||
} | ||
|
||
public function getFileQuery(): DataList | ||
{ | ||
// public scope change | ||
return parent::getFileQuery(); | ||
} | ||
|
||
/** | ||
* Code taken from @see FileMigrationHelper::chunk() | ||
* | ||
* @param DataList $query | ||
* @return Generator | ||
*/ | ||
protected function chunk(DataList $query): Generator | ||
{ | ||
// only select specified files | ||
$query = $query->byIDs($this->ids); | ||
|
||
// the rest of the code is just a copy from base | ||
$chunkSize = 100; | ||
$greaterThanID = 0; | ||
$query = $query->limit($chunkSize)->sort('ID'); | ||
|
||
while ($chunk = $query->filter('ID:GreaterThan', $greaterThanID)) { | ||
/** @var File $file */ | ||
foreach ($chunk as $file) { | ||
yield $file; | ||
} | ||
|
||
if ($chunk->count() === 0) { | ||
break; | ||
} | ||
|
||
$greaterThanID = $file->ID; | ||
} | ||
} | ||
} |
Oops, something went wrong.