[-] Core: Fix #PSCFV-5238 cache_has_attachments field update
This commit is contained in:
+25
-7
@@ -57,7 +57,17 @@ class AttachmentCore extends ObjectModel
|
|||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
@unlink(_PS_DOWNLOAD_DIR_.$this->file);
|
@unlink(_PS_DOWNLOAD_DIR_.$this->file);
|
||||||
|
|
||||||
|
$products = Db::getInstance()->executeS('
|
||||||
|
SELECT id_product
|
||||||
|
FROM '._DB_PREFIX_.'product_attachment
|
||||||
|
WHERE id_attachment='.(int)$this->id);
|
||||||
|
|
||||||
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_attachment WHERE id_attachment = '.(int)$this->id);
|
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_attachment WHERE id_attachment = '.(int)$this->id);
|
||||||
|
|
||||||
|
foreach ($products as $product)
|
||||||
|
Product::updateCacheAttachment((int)$product['id_product']);
|
||||||
|
|
||||||
return parent::delete();
|
return parent::delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,9 +106,13 @@ class AttachmentCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public static function deleteProductAttachments($id_product)
|
public static function deleteProductAttachments($id_product)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->execute('
|
$res = Db::getInstance()->execute('
|
||||||
DELETE FROM '._DB_PREFIX_.'product_attachment
|
DELETE FROM '._DB_PREFIX_.'product_attachment
|
||||||
WHERE id_product = '.(int)$id_product);
|
WHERE id_product = '.(int)$id_product);
|
||||||
|
|
||||||
|
Product::updateCacheAttachment((int)$id_product);
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,10 +123,14 @@ class AttachmentCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function attachProduct($id_product)
|
public function attachProduct($id_product)
|
||||||
{
|
{
|
||||||
return Db::getInstance()->execute('
|
$res = Db::getInstance()->execute('
|
||||||
INSERT INTO '._DB_PREFIX_.'product_attachment
|
INSERT INTO '._DB_PREFIX_.'product_attachment
|
||||||
(id_attachment, id_product) VALUES
|
(id_attachment, id_product) VALUES
|
||||||
('.(int)$this->id.', '.(int)$id_product.')');
|
('.(int)$this->id.', '.(int)$id_product.')');
|
||||||
|
|
||||||
|
Product::updateCacheAttachment((int)$id_product);
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -135,15 +153,15 @@ class AttachmentCore extends ObjectModel
|
|||||||
if ((int)$id_attachment > 0)
|
if ((int)$id_attachment > 0)
|
||||||
$ids[] = array('id_product' => (int)$id_product, 'id_attachment' => (int)$id_attachment);
|
$ids[] = array('id_product' => (int)$id_product, 'id_attachment' => (int)$id_attachment);
|
||||||
|
|
||||||
Db::getInstance()->update('product', array(
|
|
||||||
'cache_has_attachments' => count($ids) ? 1 : 0
|
|
||||||
), 'id_product = '.(int)$id_product);
|
|
||||||
|
|
||||||
if (!empty($ids))
|
if (!empty($ids))
|
||||||
$result2 = Db::getInstance()->insert('product_attachment', $ids);
|
$result2 = Db::getInstance()->insert('product_attachment', $ids);
|
||||||
|
|
||||||
return ($result1 && (!isset($result2) || $result2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Product::updateCacheAttachment((int)$id_product);
|
||||||
|
if (is_array($array))
|
||||||
|
return ($result1 && (!isset($result2) || $result2));
|
||||||
|
|
||||||
return $result1;
|
return $result1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-2
@@ -1451,6 +1451,20 @@ class ProductCore extends ObjectModel
|
|||||||
return $this->deleteFeatures();
|
return $this->deleteFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function updateCacheAttachment($id_product)
|
||||||
|
{
|
||||||
|
$value = (bool)Db::getInstance()->getValue('
|
||||||
|
SELECT id_attachment
|
||||||
|
FROM '._DB_PREFIX_.'product_attachment
|
||||||
|
WHERE id_product='.(int)$id_product);
|
||||||
|
return Db::getInstance()->update(
|
||||||
|
'product',
|
||||||
|
array('cache_has_attachments' => (int)$value),
|
||||||
|
'id_product = '.(int)$id_product
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete product attachments
|
* Delete product attachments
|
||||||
*
|
*
|
||||||
@@ -1458,10 +1472,14 @@ class ProductCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function deleteAttachments()
|
public function deleteAttachments()
|
||||||
{
|
{
|
||||||
return Db::getInstance()->execute('
|
$res = Db::getInstance()->execute('
|
||||||
DELETE FROM `'._DB_PREFIX_.'product_attachment`
|
DELETE FROM `'._DB_PREFIX_.'product_attachment`
|
||||||
WHERE `id_product` = '.(int)$this->id
|
WHERE `id_product` = '.(int)$this->id
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Product::updateCacheAttachment((int)$this->id);
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3390,7 +3408,9 @@ class ProductCore extends ObjectModel
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Duplicate product attachement
|
// Duplicate product attachement
|
||||||
return Db::getInstance()->insert('product_attachment', $data);
|
$res = Db::getInstance()->insert('product_attachment', $data);
|
||||||
|
Product::updateCacheAttachment((int)$id_product_new);
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user