Skip to content

Commit

Permalink
API Stop using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 6, 2022
1 parent aeca7ea commit 576e180
Show file tree
Hide file tree
Showing 22 changed files with 587 additions and 134 deletions.
3 changes: 1 addition & 2 deletions src/Dev/TestAssetStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public static function activate($basedir)
Injector::inst()->registerService($generated, GeneratedAssetHandler::class);
Requirements::backend()->setAssetHandler($generated);

// Disable legacy and set defaults
FlysystemAssetStore::config()->set('legacy_filenames', false);
// Set defaults
Director::config()->set('alternate_base_url', '/');
DBFile::config()->set('force_resample', false);
File::config()->set('force_resample', false);
Expand Down
4 changes: 4 additions & 0 deletions src/FileMigrationHelper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

/**
* @see FileMigrationHelper class
* @deprecated 1.12.0 Will be removed without equivalent functionality to replace it
*/
use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper;

if (!class_exists('SilverStripe\\Assets\\FileMigrationHelper')) {
Expand Down
2 changes: 1 addition & 1 deletion src/FilenameParsing/FileIDHelperResolutionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function resolveWithHash(ParsedFileID $parsedFileID)
$versionFilters['"WasPublished"'] = true;
}

$oldVersionCount = $file->Versions($versionFilters, "", 1)->count();
$oldVersionCount = $file->allVersions($versionFilters, "", 1)->count();
// Our hash was published at some other stage
if ($oldVersionCount > 0) {
return new ParsedFileID($file->getFilename(), $file->getHash(), $parsedFileID->getVariant());
Expand Down
1 change: 0 additions & 1 deletion src/Flysystem/FlysystemAssetStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public function setProtectedResolutionStrategy(FileResolutionStrategy $protected
* Return the store that contains the given fileID
*
* @param string $fileID Internal file identifier
* @deprecated 1.4.0 Use `applyToFileIDOnFilesystem()` instead
* @return Filesystem
*/
protected function getFilesystemFor($fileID)
Expand Down
10 changes: 5 additions & 5 deletions src/ImageBackendFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ public function __construct(Factory $creator)
*/
public function create($service, array $params = [])
{
/** @var AssetContainer */
$store = reset($params);
if (!$store instanceof AssetContainer) {
/** @var AssetContainer $assetContainer */
$assetContainer = reset($params);
if (!$assetContainer instanceof AssetContainer) {
throw new BadMethodCallException("Can only create Image_Backend for " . AssetContainer::class);
}

// Check cache
$key = sha1($store->getHash().'-'.$store->getVariant());
$key = sha1($assetContainer->getHash().'-'.$assetContainer->getVariant());
if (array_key_exists($key, $this->cache ?? [])) {
return $this->cache[$key];
}

// Verify file exists before creating backend
$backend = null;
if ($store->exists() && $store->getIsImage()) {
if ($assetContainer->exists() && $assetContainer->getIsImage()) {
$backend = $this->creator->create($service, $params);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Upload_Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public function getAllowedMaxFileSize($ext = null)
$this->setAllowedMaxFileSize($fileSize);
} else {
// When no default is present, use maximum set by PHP
$maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
$maxPost = File::ini2bytes(ini_get('post_max_size'));
$maxUpload = Convert::memstring2bytes(ini_get('upload_max_filesize'));
$maxPost = Convert::memstring2bytes(ini_get('post_max_size'));
$this->setAllowedMaxFileSize(min($maxUpload, $maxPost));
}
}
Expand Down Expand Up @@ -165,15 +165,15 @@ public function setAllowedMaxFileSize($rules)
if (is_numeric($value)) {
$tmpSize = $value;
} else {
$tmpSize = File::ini2bytes($value);
$tmpSize = Convert::memstring2bytes($value);
}

$finalRules[$rule] = (int)$tmpSize;
}

$this->allowedMaxFileSize = $finalRules;
} elseif (is_string($rules)) {
$this->allowedMaxFileSize['*'] = File::ini2bytes($rules);
$this->allowedMaxFileSize['*'] = Convert::memstring2bytes($rules);
} elseif ((int)$rules > 0) {
$this->allowedMaxFileSize['*'] = (int)$rules;
}
Expand Down
30 changes: 17 additions & 13 deletions tests/php/Dev/Tasks/FileMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

namespace SilverStripe\Assets\Tests\Dev\Tasks;

use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper;
use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy;
use SilverStripe\Assets\FilenameParsing\HashFileIDHelper;
use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Assets\Flysystem\FlysystemAssetStore;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Storage\FileHashingService;
use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Assets\Folder;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\Core\Injector\Injector;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Storage\FileHashingService;
use SilverStripe\Assets\Dev\Tasks\FileMigrationHelper;
use SilverStripe\Assets\Flysystem\FlysystemAssetStore;
use SilverStripe\Assets\FilenameParsing\HashFileIDHelper;
use SilverStripe\Assets\FilenameParsing\NaturalFileIDHelper;
use SilverStripe\Assets\FilenameParsing\FileIDHelperResolutionStrategy;
use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension;

/**
* Ensures that File dataobjects can be safely migrated from 3.x
Expand Down Expand Up @@ -428,6 +429,9 @@ private function missingFiles()
*/
public function testMigrationWithLegacyFilenames()
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
Config::modify()->set(FlysystemAssetStore::class, 'legacy_filenames', true);
$this->testMigration();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Dev/Tasks/FixFolderPermissionsHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\Assets\Tests\Dev\Tasks;

use SilverStripe\Assets\Folder;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\Tasks\FixFolderPermissionsHelper;

Expand All @@ -15,6 +16,9 @@ class FixFolderPermissionsHelperTest extends SapphireTest

public function testTask()
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$task = new FixFolderPermissionsHelper();
$updated = $task->run();

Expand Down
22 changes: 16 additions & 6 deletions tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace SilverStripe\Assets\Tests\Dev\Tasks;

use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\File;
use SilverStripe\Assets\Filesystem;
use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Dev\Tasks\LegacyThumbnailMigrationHelper;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension;
use SilverStripe\Core\Convert;
use SilverStripe\Assets\Folder;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Assets\Filesystem;
use Silverstripe\Assets\Dev\TestAssetStore;
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Dev\Tasks\LegacyThumbnailMigrationHelper;
use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension;

class LegacyThumbnailMigrationHelperTest extends SapphireTest
{
Expand Down Expand Up @@ -73,6 +74,9 @@ protected function tearDown(): void
*/
public function testMigratesWithExistingThumbnailInNewLocation($coreVersion)
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var TestAssetStore $store */
$store = singleton(AssetStore::class); // will use TestAssetStore

Expand Down Expand Up @@ -105,6 +109,9 @@ public function testMigratesWithExistingThumbnailInNewLocation($coreVersion)
*/
public function testMigratesMultipleFilesInSameFolder($coreVersion)
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var TestAssetStore $store */
$store = singleton(AssetStore::class); // will use TestAssetStore

Expand Down Expand Up @@ -148,6 +155,9 @@ public function testMigratesMultipleFilesInSameFolder($coreVersion)
*/
public function testMigrate($fixtureId, $formats, $coreVersion)
{
if (Deprecation::get_is_enabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var TestAssetStore $store */
$store = singleton(AssetStore::class); // will use TestAssetStore

Expand Down
Loading

0 comments on commit 576e180

Please sign in to comment.