Skip to content

Commit

Permalink
Merge pull request PrestaShop#37233 from jolelievre/merge-90x-241024
Browse files Browse the repository at this point in the history
Merge 9.0.x 24/10/24
  • Loading branch information
jolelievre authored Oct 24, 2024
2 parents 9883ee7 + ca2f376 commit 327e0af
Show file tree
Hide file tree
Showing 149 changed files with 3,376 additions and 2,387 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ jobs:

- name: Run Tests
uses: ./.github/actions/ui-test
env:
## Improve Webkit stability
## Link : https://github.com/microsoft/playwright/issues/23899
GDK_BACKEND: x11
with:
TEST_CAMPAIGN: ${{ env.TEST_CAMPAIGN }}
BROWSER: ${{ matrix.browser }}
Expand Down
8 changes: 1 addition & 7 deletions classes/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

use PrestaShop\PrestaShop\Adapter\ServiceLocator;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Exception\InvalidArgumentException;
use PrestaShop\PrestaShop\Core\Image\ImageFormatConfiguration;
Expand Down Expand Up @@ -632,13 +631,8 @@ public function deleteImage($forceDelete = false)

// Delete auto-generated images
$image_types = ImageType::getImagesTypes();

// Get image formats we will be deleting. It would probably be easier to use ImageFormatConfiguration::SUPPORTED_FORMATS,
// but we want to avoid any behavior change in minor/patch version.
$configuredImageFormats = ServiceLocator::get(ImageFormatConfiguration::class)->getGenerationFormats();

foreach ($image_types as $imageType) {
foreach ($configuredImageFormats as $imageFormat) {
foreach (ImageFormatConfiguration::SUPPORTED_FORMATS as $imageFormat) {
$filesToDelete = $this->deleteAutoGeneratedImage($imageType, $imageFormat, $filesToDelete);
}
}
Expand Down
6 changes: 1 addition & 5 deletions classes/ObjectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1821,18 +1821,14 @@ public function deleteImage($force_delete = false)
return false;
}

// Get image formats we will be deleting. It would probably be easier to use ImageFormatConfiguration::SUPPORTED_FORMATS,
// but we want to avoid any behavior change in minor/patch version.
$configuredImageFormats = ServiceLocator::get(ImageFormatConfiguration::class)->getGenerationFormats();
$types = ImageType::getImagesTypes();

foreach ($types as $image_type) {
if (file_exists($this->image_dir . $this->id . '-' . stripslashes($image_type['name']) . '.' . $this->image_format)
&& !unlink($this->image_dir . $this->id . '-' . stripslashes($image_type['name']) . '.' . $this->image_format)) {
return false;
}

foreach ($configuredImageFormats as $imageFormat) {
foreach (ImageFormatConfiguration::SUPPORTED_FORMATS as $imageFormat) {
$file = $this->image_dir . $this->id . '-' . stripslashes($image_type['name']) . '.' . $imageFormat;
if (file_exists($file)) {
unlink($file);
Expand Down
10 changes: 6 additions & 4 deletions classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2282,7 +2282,7 @@ public static function generateHtaccess($path = null, $rewrite_settings = null,

if ($rewrite_settings) {
// Compatibility with the old image filesystem
fwrite($write_fd, "# Images\n");
fwrite($write_fd, "# Rewrites for product images (support up to < 10 million images)\n");

// Rewrite product images < 10 millions
$path_components = [];
Expand All @@ -2293,12 +2293,14 @@ public static function generateHtaccess($path = null, $rewrite_settings = null,
fwrite($write_fd, $domain_rewrite_cond);
fwrite($write_fd, 'RewriteRule ^(' . str_repeat('([\d])', $i) . '(?:\-[\w-]*)?)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/p/' . $path . '/$1$' . ($i + 2) . " [L]\n");
}

fwrite($write_fd, "# Rewrites for category images\n");
fwrite($write_fd, $media_domains);
fwrite($write_fd, $domain_rewrite_cond);
fwrite($write_fd, 'RewriteRule ^c/([\d]+)(\-[\.*\w-]*)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3 [L]' . PHP_EOL);
fwrite($write_fd, 'RewriteRule ^c/([\d]+)(|_thumb)(\-[\.*\w-]*)/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3$4 [L]' . PHP_EOL);
fwrite($write_fd, $media_domains);
fwrite($write_fd, $domain_rewrite_cond);
fwrite($write_fd, 'RewriteRule ^c/([a-zA-Z_-]+)(-[\d]+)?/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3 [L]' . PHP_EOL);
fwrite($write_fd, 'RewriteRule ^c/([a-zA-Z_-]+)(|_thumb)(-[\d]+)?/.+(\.(?:jpe?g|webp|png|avif))$ %{ENV:REWRITEBASE}img/c/$1$2$3$4 [L]' . PHP_EOL);
}

fwrite($write_fd, "# AlphaImageLoader for IE and fancybox\n");
Expand All @@ -2309,7 +2311,7 @@ public static function generateHtaccess($path = null, $rewrite_settings = null,
}
// Redirections to dispatcher
if ($rewrite_settings) {
fwrite($write_fd, "\n# Dispatcher\n");
fwrite($write_fd, "\n# Send all other traffic to dispatcher\n");
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -s [OR]\n");
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -l [OR]\n");
fwrite($write_fd, "RewriteCond %{REQUEST_FILENAME} -d\n");
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"prestashop/hummingbird": "dev-develop",
"prestashop/pagesnotfound": "^2",
"prestashop/productcomments": "^7.0",
"prestashop/ps_apiresources": "dev-update-module",
"prestashop/ps_apiresources": "dev-reset-module",
"prestashop/ps_banner": "^2",
"prestashop/ps_bestsellers": "^1.0",
"prestashop/ps_brandlist": "^1.0",
Expand Down Expand Up @@ -257,7 +257,7 @@
"repositories": {
"ps_apiresources": {
"type": "vcs",
"url": "https://github.com/jolelievre/ps_apiresources.git"
"url": "https://github.com/jinpresta/ps_apiresources.git"
}
},
"minimum-stability": "dev",
Expand Down
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion install-dev/controllers/http/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function display(): void
$this->database_login = $parameters['parameters']['database_user'];
$this->database_password = $parameters['parameters']['database_password'];
$this->database_engine = $parameters['parameters']['database_engine'];
$this->database_prefix = substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', mt_rand(1,10))), 0, 5).'_';
$this->database_prefix = substr(str_shuffle(str_repeat('0123456789abcdefghijklmnopqrstuvwxyz', mt_rand(1,10))), 0, 5).'_';

$this->database_clear = true;
$this->use_smtp = false;
Expand Down
3 changes: 3 additions & 0 deletions install-dev/data/xml/configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -897,5 +897,8 @@ Country</value>
<configuration id="PS_ADMIN_API_FORCE_DEBUG_SECURED" name="PS_ADMIN_API_FORCE_DEBUG_SECURED">
<value>1</value>
</configuration>
<configuration id="PS_SEPARATOR_FILE_MANAGER_SQL" name="PS_SEPARATOR_FILE_MANAGER_SQL">
<value>;</value>
</configuration>
</entities>
</entity_configuration>
2 changes: 2 additions & 0 deletions phpstan-disallowed-calls.neon
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ parameters:
- src/PrestaShopBundle/Controller/Admin/Configure/ShopParameters/OrderStateController.php
- src/PrestaShopBundle/Controller/Admin/Improve/Design/CmsPageController.php
- src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php
- src/PrestaShopBundle/Controller/Admin/Improve/International/LanguageController.php
- src/PrestaShopBundle/Controller/Admin/Improve/International/CurrencyController.php
disallowedConstants:
-
constant:
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Backup/BackupRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class BackupRemover implements BackupRemoverInterface
/**
* {@inheritdoc}
*/
public function remove(BackupInterface $backup)
public function remove(BackupInterface $backup): bool
{
$legacyBackup = new PrestaShopBackup($backup->getFileName());

Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/Backup/DatabaseBackupCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace PrestaShop\PrestaShop\Adapter\Backup;

use PrestaShop\PrestaShop\Adapter\Entity\PrestaShopBackup;
use PrestaShop\PrestaShop\Core\Backup\BackupInterface;
use PrestaShop\PrestaShop\Core\Backup\Exception\BackupException;
use PrestaShop\PrestaShop\Core\Backup\Exception\DirectoryIsNotWritableException;
use PrestaShop\PrestaShop\Core\Backup\Manager\BackupCreatorInterface;
Expand All @@ -41,7 +42,7 @@ final class DatabaseBackupCreator implements BackupCreatorInterface
/**
* {@inheritdoc}
*/
public function createBackup()
public function createBackup(): BackupInterface
{
ini_set('max_execution_time', '0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CannotDeleteImageException;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Category\ValueObject\CategoryId;
use PrestaShop\PrestaShop\Core\Image\ImageFormatConfiguration;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;

Expand Down Expand Up @@ -79,7 +80,6 @@ public function handle(DeleteCategoryCoverImageCommand $command)
$this->assertCategoryExists($categoryId, $category);

$this->deleteCoverImage($category);
$this->deleteThumbnailImage($category);
$this->deleteTemporaryThumbnailImage($category);
$this->deleteImagesForAllTypes($category);
}
Expand Down Expand Up @@ -109,24 +109,6 @@ private function deleteCoverImage(Category $category)
}
}

/**
* @param Category $category
*
* @throws CannotDeleteImageException
*/
private function deleteThumbnailImage(Category $category)
{
$thumbnailPath = $this->configuration->get('_PS_CAT_IMG_DIR_') . $category->id . '_thumb.jpg';

try {
if ($this->filesystem->exists($thumbnailPath)) {
$this->filesystem->remove($thumbnailPath);
}
} catch (IOException $e) {
throw new CannotDeleteImageException(sprintf('Cannot delete thumbnail image for category with id "%s"', $category->id), CannotDeleteImageException::THUMBNAIL_IMAGE, $e);
}
}

/**
* @param Category $category
*
Expand All @@ -153,17 +135,15 @@ private function deleteTemporaryThumbnailImage(Category $category)
private function deleteImagesForAllTypes(Category $category)
{
$imageTypes = ImageType::getImagesTypes('categories');
$imageTypeFormattedName = ImageType::getFormattedName('small');
$categoryImageDir = $this->configuration->get('_PS_CAT_IMG_DIR_');

try {
foreach ($imageTypes as $imageType) {
$imagePath = $categoryImageDir . $category->id . '-' . $imageType['name'] . '.jpg';

if ($imageTypeFormattedName === $imageType['name']
&& $this->filesystem->exists($imagePath)
) {
$this->filesystem->remove($imagePath);
foreach (ImageFormatConfiguration::SUPPORTED_FORMATS as $imageFormat) {
$imagePath = $categoryImageDir . $category->id . '-' . $imageType['name'] . '.' . $imageFormat;
if ($this->filesystem->exists($imagePath)) {
$this->filesystem->remove($imagePath);
}
}
}
} catch (IOException $e) {
Expand Down
Loading

0 comments on commit 327e0af

Please sign in to comment.