Skip to content

Commit 0a5b885

Browse files
Use ltrim to avoid removing first char when it is not a slash (#23)
Grazie mille!
1 parent 54178a2 commit 0a5b885

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/code/community/Fballiano/ImageCleaner/controllers/Adminhtml/FbimagecleanerController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function syncproductAction()
7979
$attributes = $db->fetchCol("SELECT attribute_id FROM {$resource->getTableName('eav_attribute')} WHERE entity_type_id={$entity_type_id} AND frontend_input='media_image'");
8080
$attributes = implode(",", $attributes);
8181
$db_images = $db->fetchCol("SELECT value FROM {$resource->getTableName('catalog_product_entity_varchar')} WHERE value IS NOT NULL AND LENGTH(value)>0 AND entity_type_id={$entity_type_id} AND attribute_id IN ($attributes) AND value <> 'no_selection'");
82-
if ($db_images) $db_images = substr_replace($db_images, '', 0, 1);
82+
if ($db_images) $db_images = array_map([$this, 'removeLeadingSlash'], $db_images);
8383

8484
$placeholders = $db->fetchCol("SELECT DISTINCT value FROM {$resource->getTableName('core_config_data')} WHERE path LIKE 'catalog/placeholder/%_placeholder'");
8585
if ($placeholders) {
@@ -89,7 +89,7 @@ public function syncproductAction()
8989
}
9090

9191
$media_gallery = $db->fetchCol("SELECT value FROM {$resource->getTableName('catalog_product_entity_media_gallery')} WHERE value IS NOT NULL AND LENGTH(value)>0");
92-
if ($media_gallery) $media_gallery = substr_replace($media_gallery, '', 0, 1);
92+
if ($media_gallery) $media_gallery = array_map([$this, 'removeLeadingSlash'], $media_gallery);
9393

9494
$fs_images = Mage::helper('fballiano_imagecleaner')->scandirRecursive($media_dir);
9595
$fs_images = str_replace("{$media_dir}/", '', $fs_images);
@@ -392,4 +392,9 @@ public function resetAction()
392392
$db->query("TRUNCATE TABLE {$cleaner_table}");
393393
$this->_redirect('*/*');
394394
}
395+
396+
private function removeLeadingSlash($imagePath)
397+
{
398+
return ltrim($imagePath, '/');
399+
}
395400
}

0 commit comments

Comments
 (0)