mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 09:06:02 +00:00
Merge pull request #62 from open-sausages/pulls/4/file-maker-thumbs
NEW Generate thumbs in FTFileMakerTask
This commit is contained in:
commit
120c3155df
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
use SilverStripe\Assets\Folder;
|
use SilverStripe\Assets\Folder;
|
||||||
|
use SilverStripe\Assets\Image;
|
||||||
use SilverStripe\Dev\BuildTask;
|
use SilverStripe\Dev\BuildTask;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
@ -31,6 +32,8 @@ class FTFileMakerTask extends BuildTask
|
|||||||
|
|
||||||
protected $fixtureFileBaseUrl = "https://s3-ap-southeast-2.amazonaws.com/silverstripe-frameworktest-assets/";
|
protected $fixtureFileBaseUrl = "https://s3-ap-southeast-2.amazonaws.com/silverstripe-frameworktest-assets/";
|
||||||
|
|
||||||
|
protected $defaultImageFileName = 'image-huge-tall.jpg';
|
||||||
|
|
||||||
protected $fixtureFileNames = [
|
protected $fixtureFileNames = [
|
||||||
'archive.zip',
|
'archive.zip',
|
||||||
'animated.gif',
|
'animated.gif',
|
||||||
@ -90,13 +93,17 @@ class FTFileMakerTask extends BuildTask
|
|||||||
|
|
||||||
public function run($request)
|
public function run($request)
|
||||||
{
|
{
|
||||||
echo "Making files\n";
|
|
||||||
|
|
||||||
if ($request->getVar('reset')) {
|
if ($request->getVar('reset')) {
|
||||||
$this->reset();
|
$this->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo "Downloading fixtures\n";
|
||||||
$fixtureFilePaths = $this->downloadFixtureFiles();
|
$fixtureFilePaths = $this->downloadFixtureFiles();
|
||||||
|
|
||||||
|
echo "Generate thumbnails\n";
|
||||||
|
$this->generateThumbnails($fixtureFilePaths);
|
||||||
|
|
||||||
|
echo "Generate files\n";
|
||||||
$this->generateFiles($fixtureFilePaths);
|
$this->generateFiles($fixtureFilePaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +113,7 @@ class FTFileMakerTask extends BuildTask
|
|||||||
|
|
||||||
DB::query('TRUNCATE "File"');
|
DB::query('TRUNCATE "File"');
|
||||||
DB::query('TRUNCATE "File_Live"');
|
DB::query('TRUNCATE "File_Live"');
|
||||||
DB::query('TRUNCATE "File_versions"');
|
DB::query('TRUNCATE "File_Versions"');
|
||||||
|
|
||||||
if (file_exists(ASSETS_PATH) && ASSETS_PATH && ASSETS_PATH !== '/') {
|
if (file_exists(ASSETS_PATH) && ASSETS_PATH && ASSETS_PATH !== '/') {
|
||||||
exec("rm -rf " . ASSETS_PATH);
|
exec("rm -rf " . ASSETS_PATH);
|
||||||
@ -139,6 +146,33 @@ class FTFileMakerTask extends BuildTask
|
|||||||
return $paths;
|
return $paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates thumbnails of sample images
|
||||||
|
*
|
||||||
|
* @param array $fixtureFilePaths
|
||||||
|
*/
|
||||||
|
protected function generateThumbnails($fixtureFilePaths)
|
||||||
|
{
|
||||||
|
$folder = Folder::find_or_make('testfolder-thumbnail');
|
||||||
|
$fileName = $this->defaultImageFileName;
|
||||||
|
|
||||||
|
foreach(['draft', 'published'] as $state) {
|
||||||
|
$file = new Image([
|
||||||
|
'ParentID' => $folder->ID,
|
||||||
|
'Title' => "{$fileName} {$state}",
|
||||||
|
'Name' => $fileName,
|
||||||
|
]);
|
||||||
|
$file->File->setFromLocalFile($fixtureFilePaths[$fileName], $folder->getFilename() . $fileName);
|
||||||
|
$file->write();
|
||||||
|
|
||||||
|
if ($state === 'published') {
|
||||||
|
$file->publishFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
$file->Pad(60,60)->CropHeight(30);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $parentID = 0)
|
protected function generateFiles($fixtureFilePaths, $depth = 0, $prefix = "0", $parentID = 0)
|
||||||
{
|
{
|
||||||
$folderCount = $this->folderCountByDepth[$depth];
|
$folderCount = $this->folderCountByDepth[$depth];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user