1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<?php
/* --------------------------------------------------------------
ProductRepositoryDeleteHelper.inc.php 2017-05-23
Gambio GmbH
http://www.gambio.de
Copyright (c) 2017 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
/**
* Class ProductRepositoryDeleteHelper
*/
class ProductRepositoryDeleteHelper
{
/**
* Removes product contents, if they are not duplicated.
*
* @param \IdType $productId Product id of content to be removed.
* @param \CI_DB_query_builder $db Query builder instance to access data.
* @param \ProductsContentFileStorage $productsContentFileStorage Storage class for product contents.
*
* @return $this|ProductRepositoryDeleteHelper Same instance for chained method calls.
*/
public function productsContent(IdType $productId,
CI_DB_query_builder $db,
ProductsContentFileStorage $productsContentFileStorage)
{
// Todo: Implement functionality for new product content database scheme
//// 1. get content files by product id
//$contentFiles = $db->get_where('products_content', ['products_id' => $productId->asInt()])->result_array();
//foreach($contentFiles as $contentFile)
//{
// // 2. check if content file is duplicated
// $total = (int)$db->select('COUNT(*) as total')
// ->from('products_content')
// ->where([
// 'products_id !=' => $productId->asInt(),
// 'content_file' => $contentFile['content_file']
// ])
// ->get()
// ->row_array()['total'];
//
// // 3. remove file, if not duplicated
// if($total === 0)
// {
// $productsContentFileStorage->deleteFile(new FilenameStringType($contentFile['content_file']));
// }
//}
//
return $this;
}
/**
* Removes property combination images.
*
* @param \IdType $combinationId Combination id of images to be removed.
*
* @return $this|ProductRepositoryDeleteHelper Same instance for chained method calls.
*/
public function propertyCombinationImages(IdType $combinationId)
{
$files = glob(DIR_FS_CATALOG_IMAGES . 'product_images/properties_combis_images/' . $combinationId->asInt()
. '_*') ? : [];
foreach($files as $file)
{
file_exists($file) ? unlink($file) : null;
}
return $this;
}
/**
* Reset caches for categories and 'also_purchased', if cache is used.
*
* @return $this|ProductRepositoryDeleteHelper Same instance for chained method calls.
*/
public function resetCategoriesAndAlsoPurchasedCache()
{
if(USE_CACHE == 'true')
{
xtc_reset_cache_block('categories');
xtc_reset_cache_block('also_purchased');
}
return $this;
}
}