/** * Deletes a Shipper from the database * * Deletes related Text, shipment cost, and zone relation records as well. * @param integer $shipper_id The Shipper ID * @return boolean True on success, false on failure, * null on noop. * @static * @access private */ private static function _delete_shipper($shipper_id) { global $objDatabase; if (empty(self::$arrShippers)) { self::init(); } if (empty(self::$arrShippers[$shipper_id])) { return null; } if (!\Text::deleteById($shipper_id, 'Shop', self::TEXT_NAME)) { return false; } $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipment_cost\n WHERE shipper_id=" . $shipper_id); if (!$objResult) { return false; } $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_shipper\n WHERE shipper_id=" . $shipper_id); if (!$objResult) { return false; } $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipper\n WHERE id=" . $shipper_id); if (!$objResult) { return false; } $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipment_cost"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_shipper"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_shipper"); return true; }
/** * Deletes the Attribute from the database. * * Includes both the name and all of the value entries related to it. * As a consequence, all relations to Products referring to the deleted * entries are deleted, too. See {@link Product::arrAttribute(sp?)}. * Keep in mind that any Products currently held in memory may cause * inconsistencies! * @return boolean True on success, false otherwise. * @global ADONewConnection $objDatabase Database connection object */ function delete() { global $objDatabase; // Delete references to products first $query = "\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_product_attribute`\n WHERE `option_id` IN (\n SELECT `id`\n FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_option`\n WHERE `attribute_id`={$this->id})"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return false; } // Delete values' Text records foreach (array_keys($this->arrValues) as $id) { if (!\Text::deleteById($id, 'Shop', self::TEXT_OPTION_NAME)) { //DBG::log("Attribute::delete(): Error deleting Text for Option ID $id"); return false; } } // Delete option $query = "\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_option`\n WHERE `attribute_id`={$this->id}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return false; } // Delete names' Text records if (!\Text::deleteById($this->id, 'Shop', self::TEXT_ATTRIBUTE_NAME)) { //DBG::log("Attribute::delete(): Error deleting Text for Attribute ID $id"); return false; } // Delete Attribute $query = "\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_attribute`\n WHERE `id`={$this->id}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return false; } unset($this); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop_attribute"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop_option"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop_rel_product_attribute"); return true; }
/** * Delete this Product from the database. * * Associated Attributes and pictures are deleted with it. * @return boolean True on success, false otherwise * @global ADONewConnection $objDatabase Database connection object * @author Reto Kohli <*****@*****.**> */ function delete($flagDeleteImages = false) { global $objDatabase; // TODO: MUST NOT delete while the Product is part of any Order! if (!$this->id) { return false; } if ($flagDeleteImages) { // Heck, most of this should go into the ProductPicture class... // Split picture data into single pictures $arrPictures = explode(':', $this->pictures); foreach ($arrPictures as $strPicture) { if (empty($strPicture)) { continue; } // Split picture into name, width, height -- all are base64 // encoded! $arrPicture = explode('?', $strPicture); $strFileName = base64_decode($arrPicture[0]); // If it is the default image, skip it if (preg_match('/' . ShopLibrary::noPictureName . '$/', $strFileName)) { continue; } // Verify that no other Product uses the same picture. // $arrPicture[0] contains the encoded file name $query = "\n SELECT picture FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products\n WHERE picture LIKE '%" . addslashes($arrPicture[0]) . "%'"; $objResult = $objDatabase->Execute($query); if ($objResult->RecordCount() == 1) { // The only one -- it can be deleted. // Delete the picture and thumbnail. $thumbName = \Image::getThumbnailPath($strFileName); // Continue even if deleting the images fails \File::delete_file($strFileName); \File::delete_file($thumbName); } } } // Remove any Text records present if (!\Text::deleteById($this->id, 'Shop', self::TEXT_NAME)) { return false; } if (!\Text::deleteById($this->id, 'Shop', self::TEXT_SHORT)) { return false; } if (!\Text::deleteById($this->id, 'Shop', self::TEXT_LONG)) { return false; } if (!\Text::deleteById($this->id, 'Shop', self::TEXT_KEYS)) { return false; } if (!\Text::deleteById($this->id, 'Shop', self::TEXT_CODE)) { return false; } if (!\Text::deleteById($this->id, 'Shop', self::TEXT_URI)) { return false; } // Delete the Product attribute relations and the Product itself // TEST if (!Attributes::removeFromProduct($this->id)) { return false; } \Env::get('cx')->getEvents()->triggerEvent('model/preRemove', array(new \Doctrine\ORM\Event\LifecycleEventArgs($this, \Env::get('em')))); $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products\n WHERE id={$this->id}"); if (!$objResult) { return false; } \Env::get('cx')->getEvents()->triggerEvent('model/postRemove', array(new \Doctrine\ORM\Event\LifecycleEventArgs($this, \Env::get('em')))); $objDatabase->Execute("\n OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_products"); return true; }
/** * Delete the article group from the database * * Backend use only. * @param integer $group_id The group ID * @return boolean True on success, false otherwise * @static * @author Reto Kohli <*****@*****.**> */ static function deleteArticleGroup($group_id) { global $objDatabase, $_ARRAYLANG; if (empty($group_id)) { return false; } if (is_null(self::$arrArticleGroup)) { self::init(); } if (empty(self::$arrArticleGroup[$group_id])) { return true; } // Remove related rates $query = "\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_discount_group`\n WHERE `article_group_id`={$group_id}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return self::errorHandler(); } // Remove the group if (!\Text::deleteById($group_id, 'Shop', self::TEXT_NAME_GROUP_ARTICLE)) { return \Message::error($_ARRAYLANG['TXT_SHOP_DISCOUNT_ARTICLE_GROUP_ERROR_DELETING']); } $query = "\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_article_group`\n WHERE `id`={$group_id}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return \Message::error($_ARRAYLANG['TXT_SHOP_DISCOUNT_ARTICLE_GROUP_ERROR_DELETING']); } return \Message::ok($_ARRAYLANG['TXT_SHOP_DISCOUNT_ARTICLE_GROUP_DELETED_SUCCESSFULLY']); }
/** * Deletes a currency * * This method will fail if you try to delete the default Currency. * @return boolean Null if nothing was deleted, * boolean true upon deleting the currency * successfully, or false otherwise */ static function delete() { global $objDatabase; if (empty($_GET['currencyId'])) { return null; } self::init(); $currency_id = $_GET['currencyId']; if ($currency_id == self::$defaultCurrencyId) { return false; } if (!\Text::deleteById($currency_id, 'Shop', self::TEXT_NAME)) { return false; } $objResult = $objDatabase->Execute("\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_currencies`\n WHERE `id`={$currency_id}"); if (!$objResult) { return false; } unset(self::$arrCurrency[$currency_id]); $objDatabase->Execute("OPTIMIZE TABLE `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_currencies`"); return true; }
/** * Remove the VAT with the given ID from the database * * Note that VAT class names are only visible in the backend. Thus, * the backend language is used to display and store those Texts. * Remember to re-init() the Vat class after changing the database table. * @static * @access public * @param integer The VAT ID * @global ADONewConnection * @return boolean True if the values were accepted and * successfully inserted into the database, * false otherwise. */ static function deleteVat($vatId) { global $objDatabase; if (!is_array(self::$arrVat)) { self::init(); } $vatId = intval($vatId); if (!$vatId > 0) { return false; } if (!\Text::deleteById($vatId, 'Shop', self::TEXT_CLASS)) { return false; } $query = "\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_vat\n WHERE id={$vatId}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return false; } self::init(); return true; }
/** * Delete matching image types from the database. * * Also deletes associated Text records. * @param string $key The type key * @return boolean True on success, false otherwise * @global mixed $objDatabase Database object * @author Reto Kohli <*****@*****.**> */ static function deleteByKey($key) { global $objDatabase; if (empty($key)) { return false; } $objResult = $objDatabase->Execute("\n SELECT `text_id`\n FROM `" . DBPREFIX . "core_imagetype`\n WHERE `module_id`=" . MODULE_ID . "\n AND `key`='" . addslashes($key) . "'"); if (!$objResult) { return self::errorHandler(); } if ($objResult->RecordCount()) { if (!\Text::deleteById($objResult->fields['text_id'])) { return false; } } $objResult = $objDatabase->Execute("\n DELETE FROM `" . DBPREFIX . "core_imagetype`\n WHERE `module_id`=" . MODULE_ID . "\n AND `key`='" . addslashes($key) . "'"); if (!$objResult) { return self::errorHandler(); } return true; }
/** * Deletes the Country with the given ID from the database * @param integer $country_id The Country ID * @return boolean True on success, false otherwise */ static function deleteById($country_id) { global $objDatabase, $_CORELANG; if (is_null(self::$arrCountries)) { self::init(); } if (empty(self::$arrCountries[$country_id])) { // Message::add($_CORELANG['TXT_CORE_COUNTRY_ERROR_DELETING_NOT_FOUND']; return false; } if (!\Text::deleteById($country_id, 'core', self::TEXT_NAME, 0)) { return false; } $query = "\n DELETE FROM `" . DBPREFIX . "core_country`\n WHERE `id`=" . intval($country_id); $objResult = $objDatabase->Execute($query); if (!$objResult) { // Message::add($_CORELANG['TXT_CORE_COUNTRY_ERROR_DELETING']; return false; } return true; }
/** * Deletes this ShopCategory from the database. * * Also removes associated subcategories and Products. * Images will only be erased from the disc if the optional * $flagDeleteImages parameter evaluates to true. * @return boolean True on success, false otherwise * @global ADONewConnection $objDatabase Database connection object * @author Reto Kohli <*****@*****.**> */ function delete($flagDeleteImages = false) { global $objDatabase; // Delete Products and images if (Products::deleteByShopCategory($this->id, $flagDeleteImages) === false) { return false; } // Delete subcategories foreach ($this->getChildCategories() as $subCategory) { if (!$subCategory->delete($flagDeleteImages)) { return false; } } // TEST: Delete pictures, if requested if ($flagDeleteImages) { \File::delete_file($this->picture()); } // Delete Text \Text::deleteById($this->id(), 'Shop', self::TEXT_NAME); \Text::deleteById($this->id(), 'Shop', self::TEXT_DESCRIPTION); // Delete Category $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories\n WHERE id={$this->id}"); if (!$objResult) { return false; } $objDatabase->Execute("\n OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_categories"); return true; }
/** * Delete Zone * @static */ static function deleteZone() { global $objDatabase; if (empty($_GET['delete_zone_id'])) { return null; } $zone_id = $_GET['delete_zone_id']; if (is_null(self::$arrZone)) { self::init(); } if (empty(self::$arrZone[$zone_id])) { return null; } // Delete Country relations $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_countries\n WHERE zone_id={$zone_id}"); if (!$objResult) { return false; } // Update relations: Move affected Payments and Shipments to Zone "All" $objResult = $objDatabase->Execute("\n UPDATE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_payment\n SET zone_id=1\n WHERE zone_id={$zone_id}"); if (!$objResult) { return false; } $objResult = $objDatabase->Execute("\n UPDATE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_shipper\n SET zone_id=1\n WHERE zone_id={$zone_id}"); if (!$objResult) { return false; } // Delete Zone with Text if (!\Text::deleteById($zone_id, 'Shop', self::TEXT_NAME)) { return false; } $objResult = $objDatabase->Execute("\n DELETE FROM " . DBPREFIX . "module_shop" . MODULE_INDEX . "_zones\n WHERE id={$zone_id}"); if (!$objResult) { return false; } $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_zones"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_countries"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_payment"); $objDatabase->Execute("OPTIMIZE TABLE " . DBPREFIX . "module_shop" . MODULE_INDEX . "_rel_shipper"); return true; }
/** * Deletes one or more Manufacturers * @param mixed $ids The Manufacturer ID or an array of those * @return boolean True on success, false otherwise * @static */ static function delete($ids) { global $objDatabase, $_ARRAYLANG; if (empty($ids)) { return true; } if (!is_array($ids)) { $ids = array($ids); } if (is_null(self::$arrManufacturer)) { self::init(); } foreach ($ids as $id) { if (empty(self::$arrManufacturer[$id])) { // Something weird is going on. Probably just a page reload, // silently return false; } if (!\Text::deleteById($id, 'Shop', self::TEXT_NAME)) { return \Message::error($_ARRAYLANG['TXT_SHOP_MANUFACTURER_DELETE_FAILED']); } if (!\Text::deleteById($id, 'Shop', self::TEXT_URI)) { return \Message::error($_ARRAYLANG['TXT_SHOP_MANUFACTURER_DELETE_FAILED']); } $query = "\n DELETE FROM `" . DBPREFIX . "module_shop" . MODULE_INDEX . "_manufacturer`\n WHERE `id`={$id}"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return \Message::error($_ARRAYLANG['TXT_SHOP_MANUFACTURER_DELETE_FAILED']); } } self::flush(); return \Message::ok($_ARRAYLANG['TXT_SHOP_MANUFACTURER' . (count($ids) > 1 ? 'S' : '') . '_DELETED_SUCCESSFULLY']); }
/** * Update or add a new template * * Stores the template for the given section * Uses the language ID from the lang_id index, if present, * or the FRONTEND_LANG_ID constant otherwise. * key The key of any mail template to be used * lang_id The language ID * sender The sender name * from The sender e-mail address * to The recipient e-mail address(es), comma separated * reply The reply-to e-mail address * cc The carbon copy e-mail address(es), comma separated * bcc The blind carbon copy e-mail address(es), comma separated * subject The message subject * message The plain text message body * message_html The HTML message body * html If this evaluates to true, turns on HTML mode * attachments An array of file paths to attach. The array keys may * be used for the paths, and the values for the name. * If the keys are numeric, the values are regarded as paths. * The key index is mandatory. If available, the corresponding mail * template is loaded, and updated. * Missing fields are filled with default values, which are generally empty. * The protected flag can neither be set nor cleared by calling this method, * but is always kept as-is. * Note: The attachment paths must comply with the requirements for * file paths as defined in the {@see File} class version 2.2.0. * @param string $section The section * @param array $arrField The field array * @return boolean True on success, false otherwise */ static function store($section, $arrField) { global $objDatabase; if (empty($arrField['key'])) { return false; } // TODO: Field verification // This is non-trivial, as any placeholders must also be recognized and accepted! // if (!empty($arrField['from']) && !\FWValidator::isEmail($arrField['from'])) ... $lang_id = isset($arrField['lang_id']) ? $arrField['lang_id'] : FRONTEND_LANG_ID; $key = $arrField['key']; // Strip crap characters from the key; neither umlauts nor symbols allowed $key = preg_replace('/[^_a-z\\d]/i', '', $key); $text_id = 0; // The original template is needed for the Text IDs and protected // flag only $arrTemplate = self::get($section, $key, $lang_id); if ($arrTemplate) { // && $arrTemplate['available']) { $arrField['protected'] = $arrTemplate['protected']; $text_id = $arrTemplate['text_id']; // If the key is present in the database, update the record. $query = "\n UPDATE " . DBPREFIX . "core_mail_template\n SET `html`=" . (empty($arrField['html']) ? 0 : 1) . ",\n `protected`=" . (empty($arrField['protected']) ? 0 : 1) . "\n WHERE `key`='" . addslashes($key) . "'\n AND `section`" . (isset($section) ? "='" . addslashes($section) . "'" : ' IS NULL'); $objResult = $objDatabase->Execute($query); if (!$objResult) { \DBG::log("MailTemplate::store(): ERROR updating Template with key {$key}"); return self::errorHandler(); } } else { $query = "\n SELECT MAX(`text_id`) AS `id`\n FROM " . DBPREFIX . "core_mail_template"; $objResult = $objDatabase->Execute($query); if (!$objResult) { return self::errorHandler(); } $text_id = $objResult->fields['id'] + 1; $query = "\n INSERT INTO " . DBPREFIX . "core_mail_template (\n `key`, `section`, `html`, `protected`, `text_id`\n ) VALUES (\n '" . addslashes($key) . "', " . (isset($section) ? "'" . addslashes($section) . "'" : 'NULL') . ",\n " . (empty($arrField['html']) ? 0 : 1) . ",\n " . (empty($arrField['protected']) ? 0 : 1) . ",\n {$text_id}\n )"; $objResult = $objDatabase->Execute($query); if (!$objResult) { \DBG::log("MailTemplate::store(): ERROR inserting Template with key {$key}"); return self::errorHandler(); } } foreach (self::$text as $index => $key) { if (isset($arrField[$index])) { if (!\Text::replace($text_id, $lang_id, $section, $key, $arrField[$index])) { \DBG::log("MailTemplate::store(): ERROR replacing text for key {$key}, ID {$text_id}, lang ID {$lang_id}"); return false; } } else { if (!\Text::deleteById($text_id, $section, $key, $lang_id)) { \DBG::log("MailTemplate::store(): ERROR deleting text for key {$key}, ID {$text_id}, lang ID {$lang_id}"); return false; } } } // Force reinit self::reset(); return true; }