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

[5.1] Migrating Joomla\CMS\Filesystem\Folder::exists() to is_dir() #40131

Merged
merged 16 commits into from
Mar 2, 2024
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
3 changes: 2 additions & 1 deletion administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Joomla\CMS\Table\Table;
use Joomla\CMS\Uri\Uri;
use Joomla\Database\ParameterType;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -2458,7 +2459,7 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false)
}

foreach ($folders as $folder) {
if ($folderExists = Folder::exists(JPATH_ROOT . $folder)) {
if ($folderExists = is_dir(Path::clean(JPATH_ROOT . $folder))) {
$status['folders_exist'][] = $folder;

if ($dryRun === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public function save($data)
$data['session_filesystem_path'] = Path::clean($data['session_filesystem_path']);

if ($currentPath !== $data['session_filesystem_path']) {
if (!Folder::exists($data['session_filesystem_path']) && !Folder::create($data['session_filesystem_path'])) {
if (!is_dir(Path::clean($data['session_filesystem_path'])) && !Folder::create($data['session_filesystem_path'])) {
try {
Log::add(
Text::sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public static function getPresets()

$folder = JPATH_ADMINISTRATOR . '/components/' . $component->option . '/presets/';

if (!Folder::exists($folder)) {
if (!is_dir($folder)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public function copy()
// Delete new folder if it exists
$toPath = $this->getState('to_path');

if (Folder::exists($toPath)) {
if (is_dir(Path::clean($toPath))) {
if (!Folder::delete($toPath)) {
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_COULD_NOT_WRITE'), 'error');

Expand Down Expand Up @@ -1145,7 +1145,7 @@ public function createOverride($override)
}

// Check Html folder, create if not exist
if (!Folder::exists($htmlPath) && !Folder::create($htmlPath)) {
if (!is_dir(Path::clean($htmlPath)) && !Folder::create($htmlPath)) {
$app->enqueueMessage(Text::_('COM_TEMPLATES_FOLDER_ERROR'), 'error');

return false;
Expand Down Expand Up @@ -1203,7 +1203,7 @@ public function createTemplateOverride($overridePath, $htmlPath)
foreach ($folders as $folder) {
$htmlFolder = $htmlPath . str_replace($overridePath, '', $folder);

if (!Folder::exists($htmlFolder)) {
if (!is_dir(Path::clean($htmlFolder))) {
Folder::create($htmlFolder);
}
}
Expand Down Expand Up @@ -1864,7 +1864,7 @@ public function child()
// Delete new folder if it exists
$toPath = $this->getState('to_path');

if (Folder::exists($toPath)) {
if (is_dir(Path::clean($toPath))) {
if (!Folder::delete($toPath)) {
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_COULD_NOT_WRITE'), 'error');

Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Form/Field/ChromestyleField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\Database\ParameterType;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -189,7 +190,7 @@ protected function getTemplateModuleStyles()
foreach ($templates as $template) {
$chromeLayoutPath = $path . '/templates/' . $template->element . '/html/layouts/chromes';

if (!Folder::exists($chromeLayoutPath)) {
if (!is_dir(Path::clean($chromeLayoutPath))) {
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions libraries/src/Form/Rule/FolderPathExistsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Joomla\CMS\Form\Rule;

use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Form\Form;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
Expand Down Expand Up @@ -64,6 +63,6 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry
return false;
}

return Folder::exists($pathCleaned);
return is_dir(Path::clean($pathCleaned));
Hackwar marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 4 additions & 4 deletions libraries/src/Installer/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function copyBaseFiles()

// Now that we have folder list, lets start creating them
foreach ($this->folderList as $folder) {
if (!Folder::exists($folder)) {
if (!is_dir(Path::clean($folder))) {
if (!$created = Folder::create($folder)) {
throw new \RuntimeException(
Text::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $folder)
Expand Down Expand Up @@ -308,7 +308,7 @@ protected function removeExtensionFiles()
// Lastly, remove the extension_root
$folder = $this->parent->getPath('extension_root');

if (Folder::exists($folder)) {
if (is_dir(Path::clean($folder))) {
Folder::delete($folder);
}

Expand Down Expand Up @@ -515,7 +515,7 @@ protected function populateFilesAndFolderList()
$folderName .= '/' . $dir;

// Check if folder exists, if not then add to the array for folder creation
if (!Folder::exists($folderName)) {
if (!is_dir(Path::clean($folderName))) {
$this->folderList[] = $folderName;
}
}
Expand All @@ -525,7 +525,7 @@ protected function populateFilesAndFolderList()
$targetFolder = empty($target) ? $jRootPath : $jRootPath . '/' . $target;

// Check if source folder exists
if (!Folder::exists($sourceFolder)) {
if (!is_dir(Path::clean($sourceFolder))) {
Log::add(Text::sprintf('JLIB_INSTALLER_ABORT_FILE_INSTALL_FAIL_SOURCE_DIRECTORY', $sourceFolder), Log::WARNING, 'jerror');

// If installation fails, rollback
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Installer/Adapter/LanguageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\Update;
use Joomla\Database\ParameterType;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -201,7 +202,7 @@ protected function setupUninstall()
$this->parent->setPath('source', $path);

// Check it exists
if (!Folder::exists($path)) {
if (!is_dir(Path::clean($path))) {
// If the folder doesn't exist lets just nuke the row as well and presume the user killed it for us
$this->extension->delete();

Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Installer/Adapter/LibraryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Joomla\CMS\Table\Update;
use Joomla\Database\ParameterType;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -282,7 +283,7 @@ protected function removeExtensionFiles()

// @todo: Change this so it walked up the path backwards so we clobber multiple empties
// If the folder is empty, let's delete it
if (Folder::exists($this->parent->getPath('extension_root'))) {
if (is_dir(Path::clean($this->parent->getPath('extension_root')))) {
if (is_dir($this->parent->getPath('extension_root'))) {
$files = Folder::files($this->parent->getPath('extension_root'));

Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Installer/Adapter/PackageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Joomla\Database\ParameterType;
use Joomla\Event\Event;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -336,7 +337,7 @@ protected function finaliseUninstall(): bool

$folder = $this->parent->getPath('extension_root');

if (Folder::exists($folder)) {
if (is_dir(Path::clean($folder))) {
Folder::delete($folder);
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Installer/Adapter/TemplateAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\Update;
use Joomla\Database\ParameterType;
use Joomla\Filesystem\Path;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -392,7 +393,7 @@ protected function removeExtensionFiles()
$this->parent->removeFiles($this->getManifest()->languages, $this->extension->client_id);

// Delete the template directory
if (Folder::exists($this->parent->getPath('extension_root'))) {
if (is_dir(Path::clean($this->parent->getPath('extension_root')))) {
Folder::delete($this->parent->getPath('extension_root'));
} else {
Log::add(Text::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY'), Log::WARNING, 'jerror');
Expand Down
10 changes: 5 additions & 5 deletions libraries/src/Installer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public function abort($msg = null, $type = null)
*/
public function install($path = null)
{
if ($path && Folder::exists($path)) {
if ($path && is_dir(Path::clean($path))) {
$this->setPath('source', $path);
} else {
$this->abort(Text::_('JLIB_INSTALLER_ABORT_NOINSTALLPATH'));
Expand Down Expand Up @@ -803,7 +803,7 @@ public function discover()
*/
public function update($path = null)
{
if ($path && Folder::exists($path)) {
if ($path && is_dir(Path::clean($path))) {
$this->setPath('source', $path);
} else {
$this->abort(Text::_('JLIB_INSTALLER_ABORT_NOUPDATEPATH'));
Expand Down Expand Up @@ -1579,7 +1579,7 @@ public function parseLanguages(\SimpleXMLElement $element, $cid = 0)
}

// If the language folder is not present, then the core pack hasn't been installed... ignore
if (!Folder::exists(\dirname($path['dest']))) {
if (!is_dir(Path::clean(\dirname($path['dest'])))) {
continue;
}
} else {
Expand Down Expand Up @@ -1947,7 +1947,7 @@ public function removeFiles($element, $cid = 0)
}

// If the language folder is not present, then the core pack hasn't been installed... ignore
if (!Folder::exists(\dirname($path))) {
if (!is_dir(Path::clean(\dirname($path)))) {
continue;
}
} else {
Expand Down Expand Up @@ -2012,7 +2012,7 @@ public function copyManifest($cid = 1)
public function findManifest()
{
// Do nothing if folder does not exist for some reason
if (!Folder::exists($this->getPath('source'))) {
if (!is_dir(Path::clean($this->getPath('source')))) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Installer/InstallerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static function unpack($packageFilename, $alwaysReturnArray = false)
$dirList = array_merge((array) Folder::files($extractdir, ''), (array) Folder::folders($extractdir, ''));

if (\count($dirList) === 1) {
if (Folder::exists($extractdir . '/' . $dirList[0])) {
if (is_dir(Path::clean($extractdir . '/' . $dirList[0]))) {
$extractdir = Path::clean($extractdir . '/' . $dirList[0]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Installer/InstallerScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function removeFiles()

if (!empty($this->deleteFolders)) {
foreach ($this->deleteFolders as $folder) {
if (Folder::exists(JPATH_ROOT . $folder) && !Folder::delete(JPATH_ROOT . $folder)) {
if (is_dir(Path::clean(JPATH_ROOT . $folder)) && !Folder::delete(JPATH_ROOT . $folder)) {
echo Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $folder) . '<br>';
}
}
Expand Down
5 changes: 2 additions & 3 deletions plugins/editors/tinymce/src/PluginTraits/DisplayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

namespace Joomla\Plugin\Editors\TinyMCE\PluginTraits;

use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
Expand Down Expand Up @@ -178,8 +177,8 @@ public function display(string $name, string $content = '', array $attributes =
$skinDark = $levelParams->get($app->isClient('administrator') ? 'skin_admin_dark' : 'skin_dark', 'oxide-dark');

// Check that selected skin exists.
$skin = Folder::exists(JPATH_ROOT . '/media/vendor/tinymce/skins/ui/' . $skin) ? $skin : 'oxide';
$skinDark = Folder::exists(JPATH_ROOT . '/media/vendor/tinymce/skins/ui/' . $skinDark) ? $skinDark : 'oxide-dark';
$skin = is_dir(JPATH_ROOT . '/media/vendor/tinymce/skins/ui/' . $skin) ? $skin : 'oxide';
$skinDark = is_dir(JPATH_ROOT . '/media/vendor/tinymce/skins/ui/' . $skinDark) ? $skinDark : 'oxide-dark';

if (!$levelParams->get('lang_mode', 1)) {
// Admin selected language
Expand Down
2 changes: 1 addition & 1 deletion plugins/filesystem/local/src/Adapter/LocalAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public function delete(string $path)

$success = File::delete($localPath);
} else {
if (!Folder::exists($localPath)) {
if (!is_dir(Path::clean($localPath))) {
throw new FileNotFoundException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Language\LanguageHelper;
Expand Down Expand Up @@ -606,7 +605,7 @@ public function onUserLogin($user, $options = [])
if (
!\array_key_exists($lang_code, $this->lang_codes)
|| !\array_key_exists($lang_code, Multilanguage::getSiteHomePages())
|| !Folder::exists(JPATH_SITE . '/language/' . $lang_code)
|| !is_dir(JPATH_SITE . '/language/' . $lang_code)
) {
$lang_code = $this->current_lang;
}
Expand Down