-
Notifications
You must be signed in to change notification settings - Fork 68
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
DEP Upgrade legue/flysystem to version 3.0 #524
DEP Upgrade legue/flysystem to version 3.0 #524
Conversation
0267ab7
to
a9d03d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove the Extended
prefix on the new classes ExtendedFilesystem
and ExtendedLocalFilesystemAdapter
and instead prefix League
to the import statement on the league class e.g.
use League\Flysystem\Filesystem as LeagueFilesystem;
We do a similar thing with Email
- https://github.com/silverstripe/silverstripe-framework/blob/5/src/Control/Email/Email.php#L23
try { | ||
$callback($fs, $parsedFileID->getFileID()); | ||
} catch (UnableToWriteFile $exception) { | ||
throw new UnableToWriteFile("Could not save {$filename}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try { | |
$callback($fs, $parsedFileID->getFileID()); | |
} catch (UnableToWriteFile $exception) { | |
throw new UnableToWriteFile("Could not save {$filename}"); | |
$result = $callback($fs, $parsedFileID->getFileID()); | |
if (!$result) { | |
throw new UnableToWriteFile("Could not save {$filename}"); |
If there's a UnableToWriteFile
exception thrown from $callback()
there's no need to catch it only to re-throw a new UnableToWriteFile
exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since new filesystem operations no longer return boolean value, if filesystem operation was a success or not. Now they throw UnableTo*File
exceptions and we should process these exceptions.
I implemented this changes following this Docs "No more success result booleans" paragraph and
Filesystem API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
src/Util.php
Outdated
} | ||
} | ||
|
||
public static function isSeekableStream($resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static function isSeekableStream($resource) | |
public static function isSeekableStream(resource $resource): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
I cannot add resource
as a type hint.
Warning: "resource" is not a supported builtin type and will be interpreted as a class name.
See https://wiki.php.net/rfc/scalar_type_hints :
No type hint for resources is added, as this would prevent moving from resources to objects for existing extensions, which some have already done (e.g. GMP).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is in the Util class, may as well just add the following (adapted from this):
private static function checkIsResource($resource): void
{
if (!is_resource($resource)) {
throw new \InvalidArgumentException('$resource argument is not a valid resource');
}
}
And then type check within rewindStream()
and isSeekableStream()
I don't this we need to worry about the object
scenario since stream_get_meta_data() is type hinted for resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
src/Util.php
Outdated
|
||
class Util | ||
{ | ||
public static function rewindStream($resource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static function rewindStream($resource) | |
public static function rewindStream(resource $resource): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot add resource
as a type hint.
Warning: "resource" is not a supported builtin type and will be interpreted as a class name.
See https://wiki.php.net/rfc/scalar_type_hints :
No type hint for resources is added, as this would prevent moving from resources to objects for existing extensions, which some have already done (e.g. GMP).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, check use a new checkIsResource()
method to type check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
887b96b
to
9b2f268
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more code changes requested
- See comments in the Files changed tab
Some possible references to removed methods may still exist
This list is largely for my own testing.
Looking at the list of methods removed in https://flysystem.thephpleague.com/docs/upgrade-from-1.x/
I tried searching for the following strings in ./vendor/silverstripe/**/*.php
- the idea being that there may be some classes that haven't yet been updated and either weren't covered by unit tests in the assets module, or, they are called from different modules and possibly would get caught if we ran that PR against silverstripe/installer
(more about that in the section below).
Looks like most things have been correctly updated.
->getMetaData(
- (none I think, though there's also multiple
getMetaData()
methods on other silverstripe classes)
['basename']
- HashFileIDHelper::parseFileID()
- LegacyFileIDHelper::parseFileID()
- LegacyFileIDHelper::parseSilverStripe30VariantFileID()
- NaturalFileIDHelper::parseFileID()
->rename(
- (none I think, though there's FlysystemAssetStore::rename())
->createDir(
- (none)
->update(
- (none I think, though there's also DataObject::update(), MemoryConfigCollection::update() and Config_ForClass::update())
->updateStream(
- (none)
->put(
- (none)
->putStream(
- (none)
->getTimestamp(
- (none I think, though there DBDate::getTimestamp())
->has(
- (large number of uses, though it doesn't look like it's been depracated or removed in 3.x)
->getMimetype(
- (none I think, though there is DBFile::getMimeType())
->getSize(
- (none I think, though there is File::getSize())
->getVisibility(
- (none I think, though there is File::getVisibility() and FlystemAssetStore::getVisibility())
May be worth testing with silverstripe/installer before merge
It may be worth running this through the silverstripe/installer
CI using vendor-code-patcher
Unlike the last time we tried this, adding "league/flysystem": "3.9.0 as 1.99.99"
to composer.json on the new branch of silverstripe/installer
should work since it doesn't have any conflicting subdependencies
I'm not sure how much other modules such as asset-admin actually call league/flysystem methods directly, so there is some risk with merging this without it going via installer. However If you don't think it's worth doing this though, I'm OK with skipping this step
try { | ||
$callback($fs, $parsedFileID->getFileID()); | ||
} catch (UnableToWriteFile $exception) { | ||
throw $exception; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try { | |
$callback($fs, $parsedFileID->getFileID()); | |
} catch (UnableToWriteFile $exception) { | |
throw $exception; | |
} | |
$callback($fs, $parsedFileID->getFileID()); |
If all we're doing is re-throwing the exception after catching it, we may as well not bother catching it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE
15d8f3f
to
0c64d54
Compare
@emteknetnz, I went through your list and this is a small report about my investigation: Before I've started to work on upgrading new deps, I've checked do we use
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried running this PR using installer, there's single failing unit test on framework - https://github.com/emteknetnz/silverstripe-installer/actions/runs/3343823971/jobs/5537884602
I've fixed this on my local - could you please update GeneratedAssets::removeContent()
:
public function removeContent($filename)
{
$filesystem = $this->getFilesystem();
if ($filesystem->directoryExists($filename)) {
$filesystem->deleteDirectory($filename);
} elseif ($filesystem->fileExists($filename)) {
$filesystem->delete($filename);
}
}
6bece47
to
11d4da5
Compare
11d4da5
to
88b62be
Compare
Issue
#497
Description
ExtendedFilesystem extends Filesystem
to providegetAdapter()
method, that was removed from mainlegue/flysystem
Filesystem
class (GitHub discussion)ExtendedLocalFilesystemAdapter extends LocalFilesystemAdapter
to provideprefixPath
method that replacesapplyPathPrefix
method from removedabstract class AbstractAdapter
(GitHub discussion)SilverStripe\Assets\Util
to replace removedLeague\Flysystem\Util
and implement some of required methods.Notes:
Filesystem has()
method to more appropriateddirectoryExists
orfileExists
, sincehas
checks both casesdirectoryExists
orfileExists
and returnstrue
, if one of them returnstrue
;listContents
method returnsDirectoryListing
, but previous version returnedarray
. For this case, invoketoArray
method on result to returnarray
to support existing functionality.