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
[5.2] Refactor all instances of File to use framework #43362
Open
Hackwar
wants to merge
6
commits into
joomla:5.2-dev
Choose a base branch
from
Hackwar:5.2-filesystem-file
base: 5.2-dev
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a3432e9
Refactor all occurences of File to use framework
Hackwar 3a1a6d2
Refactoring some error handling
Hackwar 26967fd
Merge branch '5.2-dev' into 5.2-filesystem-file
Hackwar 3953380
Codestyle
Hackwar be59171
Codestyle
Hackwar 597c20b
Merge branch '5.2-dev' into 5.2-filesystem-file
Hackwar File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
use Joomla\CMS\Component\ComponentHelper; | ||
use Joomla\CMS\Extension\ExtensionHelper; | ||
use Joomla\CMS\Factory; | ||
use Joomla\CMS\Filesystem\File as FileCMS; | ||
use Joomla\CMS\Filter\InputFilter; | ||
use Joomla\CMS\Http\Http; | ||
use Joomla\CMS\Http\HttpFactory; | ||
|
@@ -30,6 +29,7 @@ | |
use Joomla\CMS\User\UserHelper; | ||
use Joomla\CMS\Version; | ||
use Joomla\Database\ParameterType; | ||
use Joomla\Filesystem\Exception\FilesystemException; | ||
use Joomla\Filesystem\File; | ||
use Joomla\Registry\Registry; | ||
use Joomla\Utilities\ArrayHelper; | ||
|
@@ -508,7 +508,11 @@ protected function downloadPackage($url, $target) | |
|
||
// Make sure the target does not exist. | ||
if (is_file($target)) { | ||
File::delete($target); | ||
try { | ||
File::delete($target); | ||
} catch (FilesystemException $exception) { | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have logging 5 lines above, maybe log the exception? |
||
} | ||
|
||
// Download the package | ||
|
@@ -526,9 +530,9 @@ protected function downloadPackage($url, $target) | |
$body = $result->body; | ||
|
||
// Write the file to disk | ||
$result = File::write($target, $body); | ||
|
||
if (!$result) { | ||
try { | ||
File::write($target, $body); | ||
} catch (FilesystemException $exception) { | ||
return false; | ||
} | ||
|
||
|
@@ -611,14 +615,18 @@ public function createUpdateFile($basename = null): bool | |
$configpath = JPATH_COMPONENT_ADMINISTRATOR . '/update.php'; | ||
|
||
if (is_file($configpath)) { | ||
File::delete($configpath); | ||
try { | ||
File::delete($configpath); | ||
} catch (FilesystemException $exception) { | ||
|
||
} | ||
} | ||
|
||
// Write new file. First try with File. | ||
$result = File::write($configpath, $data); | ||
|
||
// In case File failed but direct access could help. | ||
if (!$result) { | ||
try { | ||
$result = File::write($configpath, $data); | ||
} catch (FilesystemException $exception) { | ||
// In case File failed but direct access could help. | ||
$fp = @fopen($configpath, 'wt'); | ||
|
||
if ($fp !== false) { | ||
|
@@ -889,18 +897,22 @@ public function cleanUp() | |
|
||
$file = $app->getUserState('com_joomlaupdate.file', null); | ||
|
||
if (is_file($tempdir . '/' . $file)) { | ||
File::delete($tempdir . '/' . $file); | ||
} | ||
try { | ||
if (is_file($tempdir . '/' . $file)) { | ||
File::delete($tempdir . '/' . $file); | ||
} | ||
|
||
// Remove the update.php file used in Joomla 4.0.3 and later. | ||
if (is_file(JPATH_COMPONENT_ADMINISTRATOR . '/update.php')) { | ||
File::delete(JPATH_COMPONENT_ADMINISTRATOR . '/update.php'); | ||
} | ||
// Remove the update.php file used in Joomla 4.0.3 and later. | ||
if (is_file(JPATH_COMPONENT_ADMINISTRATOR . '/update.php')) { | ||
File::delete(JPATH_COMPONENT_ADMINISTRATOR . '/update.php'); | ||
} | ||
|
||
// Remove joomla.xml from the site's root. | ||
if (is_file(JPATH_ROOT . '/joomla.xml')) { | ||
File::delete(JPATH_ROOT . '/joomla.xml'); | ||
} | ||
} catch (FilesystemException $exception) { | ||
|
||
// Remove joomla.xml from the site's root. | ||
if (is_file(JPATH_ROOT . '/joomla.xml')) { | ||
File::delete(JPATH_ROOT . '/joomla.xml'); | ||
} | ||
|
||
// Unset the update filename from the session. | ||
|
@@ -983,9 +995,9 @@ public function upload() | |
$tmp_src = $userfile['tmp_name']; | ||
|
||
// Move uploaded file. | ||
$result = FileCMS::upload($tmp_src, $tmp_dest, false, true); | ||
|
||
if (!$result) { | ||
try { | ||
File::upload($tmp_src, $tmp_dest, false); | ||
} catch (FilesystemException $exception) { | ||
throw new \RuntimeException(Text::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLUPLOADERROR'), 500); | ||
} | ||
|
||
|
@@ -1061,7 +1073,11 @@ public function removePackageFiles() | |
|
||
foreach ($files as $file) { | ||
if ($file !== null && is_file($file)) { | ||
File::delete($file); | ||
try { | ||
File::delete($file); | ||
} catch (FilesystemException $exception) { | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When the upload fails, we should stop the execution...