Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Stop using deprecated API #526

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Dev/Tasks/FileMigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class FileMigrationHelper

public function __construct()
{
Deprecation::notice('1.12.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS);
Deprecation::withNoReplacement(function () {
Deprecation::notice('1.12.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS);
});
$this->logger = new NullLogger();
}

Expand Down
4 changes: 3 additions & 1 deletion src/Dev/Tasks/NormaliseAccessMigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class NormaliseAccessMigrationHelper
*/
public function __construct($base = '')
{
Deprecation::notice('1.12.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS);
Deprecation::withNoReplacement(function () {
Deprecation::notice('1.12.0', 'Will be removed without equivalent functionality to replace it', Deprecation::SCOPE_CLASS);
});
$this->logger = new NullLogger();
if ($base) {
$this->basePath = $base;
Expand Down
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
8 changes: 7 additions & 1 deletion src/FilenameParsing/LegacyFileIDHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ class LegacyFileIDHelper implements FileIDHelper
*/
public function __construct($failNewerVariant = true)
{
Deprecation::notice('1.12.0', 'Legacy file names will not be supported in Silverstripe CMS 5', Deprecation::SCOPE_CLASS);
Deprecation::withNoReplacement(function () {
Deprecation::notice(
'1.12.0',
'Legacy file names will not be supported in Silverstripe CMS 5',
Deprecation::SCOPE_CLASS
);
});
$this->failNewerVariant = $failNewerVariant;
}

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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this variable because it was confusing me

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
9 changes: 5 additions & 4 deletions src/Upload_Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Assets;

use SilverStripe\Core\Convert;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Injector\Injectable;
Expand Down Expand Up @@ -121,8 +122,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 +166,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
10 changes: 10 additions & 0 deletions tests/php/Dev/Tasks/FileMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\Queries\SQLUpdate;
use SilverStripe\Dev\Deprecation;

/**
* Ensures that File dataobjects can be safely migrated from 3.x
Expand Down Expand Up @@ -176,6 +177,9 @@ protected function tearDown(): void
*/
public function testMigration()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$this->preCondition();

// The EXE file, extensionless file and missing file won't be migrated
Expand Down Expand Up @@ -428,6 +432,9 @@ private function missingFiles()
*/
public function testMigrationWithLegacyFilenames()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
Config::modify()->set(FlysystemAssetStore::class, 'legacy_filenames', true);
$this->testMigration();
}
Expand All @@ -438,6 +445,9 @@ public function testMigrationWithLegacyFilenames()
*/
public function testInvalidAssetStoreStrategy()
{
if (Deprecation::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$strategy = FileIDHelperResolutionStrategy::create();
$strategy->setDefaultFileIDHelper(new HashFileIDHelper());
$strategy->setResolutionFileIDHelpers([new HashFileIDHelper()]);
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::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
$task = new FixFolderPermissionsHelper();
$updated = $task->run();

Expand Down
10 changes: 10 additions & 0 deletions tests/php/Dev/Tasks/LegacyThumbnailMigrationHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SilverStripe\Assets\Storage\AssetStore;
use SilverStripe\Assets\Tests\Dev\Tasks\FileMigrationHelperTest\Extension;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;

sabina-talipova marked this conversation as resolved.
Show resolved Hide resolved
class LegacyThumbnailMigrationHelperTest extends SapphireTest
Expand Down Expand Up @@ -73,6 +74,9 @@ protected function tearDown(): void
*/
public function testMigratesWithExistingThumbnailInNewLocation($coreVersion)
{
if (Deprecation::isEnabled()) {
$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::isEnabled()) {
$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::isEnabled()) {
$this->markTestSkipped('Test calls deprecated code');
}
/** @var TestAssetStore $store */
$store = singleton(AssetStore::class); // will use TestAssetStore

Expand Down
Loading