本文整理汇总了PHP中Text::replace方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::replace方法的具体用法?PHP Text::replace怎么用?PHP Text::replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text
的用法示例。
在下文中一共展示了Text::replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get($string)
{
$key = Text::lowercase($string);
$key = Text::replace(' ', '-', $key);
if (isset($this->db[$key])) {
return $this->db[$key];
}
return '';
}
示例2: errorHandler
/**
* Handles database errors
*
* Also migrates old ProductAttribute to new Attribute structures,
* including Text records.
* @return boolean false Always!
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
// Attribute
$default_lang_id = \FWLanguage::getDefaultLangId();
$table_name_old = DBPREFIX . 'module_shop_products_attributes_name';
$table_name_new = DBPREFIX . 'module_shop_attribute';
if (\Cx\Lib\UpdateUtil::table_exist($table_name_new)) {
\Cx\Lib\UpdateUtil::drop_table($table_name_old);
} else {
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'type' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'display_type'));
$table_index = array();
if (\Cx\Lib\UpdateUtil::table_exist($table_name_old)) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name_old, 'name')) {
// Migrate all Product strings to the Text table first
\Text::deleteByKey('Shop', self::TEXT_ATTRIBUTE_NAME);
$query = "\n SELECT `id`, `name`\n FROM `{$table_name_old}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to query Attribute names", $query);
}
while (!$objResult->EOF) {
$id = $objResult->fields['id'];
$name = $objResult->fields['name'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_ATTRIBUTE_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Attribute name '{$name}'");
}
$objResult->MoveNext();
}
}
}
//DBG::activate(DBG_ADODB);
\Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index);
if (!\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to rename Attribute table");
}
}
$table_name_old = DBPREFIX . 'module_shop_products_attributes_value';
$table_name_new = DBPREFIX . 'module_shop_option';
if (\Cx\Lib\UpdateUtil::table_exist($table_name_new)) {
\Cx\Lib\UpdateUtil::drop_table($table_name_old);
} else {
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'attribute_id' => array('type' => 'INT(10)', 'unsigned' => true, 'renamefrom' => 'name_id'), 'price' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'));
$table_index = array();
if (\Cx\Lib\UpdateUtil::table_exist($table_name_old)) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name_old, 'value')) {
// Migrate all Product strings to the Text table first
\Text::deleteByKey('Shop', self::TEXT_OPTION_NAME);
$query = "\n SELECT `id`, `value`\n FROM `{$table_name_old}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to query option names", $query);
}
while (!$objResult->EOF) {
$id = $objResult->fields['id'];
$name = $objResult->fields['value'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_OPTION_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to migrate option Text '{$name}'");
}
$objResult->MoveNext();
}
}
}
\Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index);
if (!\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to rename Option table");
}
}
$table_name_old = DBPREFIX . 'module_shop_products_attributes';
$table_name_new = DBPREFIX . 'module_shop_rel_product_attribute';
if (\Cx\Lib\UpdateUtil::table_exist($table_name_new)) {
\Cx\Lib\UpdateUtil::drop_table($table_name_old);
} else {
$table_structure = array('product_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true), 'option_id' => array('type' => 'INT(10)', 'unsigned' => true, 'primary' => true, 'renamefrom' => 'attributes_value_id'), 'ord' => array('type' => 'INT(10)', 'default' => '0', 'renamefrom' => 'sort_id'));
$table_index = array();
\Cx\Lib\UpdateUtil::table($table_name_old, $table_structure, $table_index);
if (!\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to rename Product-Attribute relation table {$table_name_old} to {$table_name_new}");
}
}
// Always
return false;
}
示例3: errorHandler
/**
* Handles database errors
*
* Also migrates old Currency names to the Text class,
* and inserts default Currencyes if necessary
* @return boolean false Always!
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
global $objDatabase;
// Currency
\Text::errorHandler();
$table_name = DBPREFIX . 'module_shop_currencies';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'code' => array('type' => 'CHAR(3)', 'notnull' => true, 'default' => ''), 'symbol' => array('type' => 'VARCHAR(20)', 'notnull' => true, 'default' => ''), 'rate' => array('type' => 'DECIMAL(10,4)', 'unsigned' => true, 'notnull' => true, 'default' => '1.0000'), 'increment' => array('type' => 'DECIMAL(6,5)', 'unsigned' => true, 'notnull' => true, 'default' => '0.01'), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'sort_order'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'renamefrom' => 'status'), 'default' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'is_default'));
$table_index = array();
$default_lang_id = \FWLanguage::getDefaultLangId();
if (\Cx\Lib\UpdateUtil::table_exist($table_name)) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
// Migrate all Currency names to the Text table first
\Text::deleteByKey('Shop', self::TEXT_NAME);
$query = "\n SELECT `id`, `code`, `name`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query Currency names", $query);
}
while (!$objResult->EOF) {
$id = $objResult->fields['id'];
$name = $objResult->fields['name'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Currency name '{$name}'");
}
$objResult->MoveNext();
}
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
return false;
}
// If the table did not exist, insert defaults
$arrCurrencies = array('Schweizer Franken' => array('CHF', 'sFr.', 1.0, '0.05', 1, 1, 1), 'Euro' => array('EUR', html_entity_decode("€"), 1.18, '0.01', 2, 1, 0), 'United States Dollars' => array('USD', '$', 0.88, '0.01', 3, 1, 0));
// There is no previous version of this table!
\Cx\Lib\UpdateUtil::table($table_name, $table_structure);
// And there aren't even records to migrate, so
foreach ($arrCurrencies as $name => $arrCurrency) {
$query = "\n INSERT INTO `contrexx_module_shop_currencies` (\n `code`, `symbol`, `rate`, `increment`,\n `ord`, `active`, `default`\n ) VALUES (\n '" . join("','", $arrCurrency) . "'\n )";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to insert default Currencies");
}
$id = $objDatabase->Insert_ID();
if (!\Text::replace($id, FRONTEND_LANG_ID, 'Shop', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to add Text for default Currency name '{$name}'");
}
}
// Always
return false;
}
示例4: errorHandler
/**
* Tries to fix any database problems
* @return boolean False. Always.
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
//die("Discount::errorHandler(): Disabled!<br />");
// Discount
\Text::errorHandler();
$table_name = DBPREFIX . 'module_shop_article_group';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true));
$table_index = array();
//\DBG::activate(DBG_DB);
if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) {
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
$default_lang_id = \FWLanguage::getDefaultLangId();
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
\Text::deleteByKey('Shop', self::TEXT_NAME_GROUP_ARTICLE);
$query = "\n SELECT `id`, `name`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query article group names", $query);
}
while (!$objResult->EOF) {
$group_id = $objResult->fields['id'];
$name = $objResult->fields['name'];
if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_NAME_GROUP_ARTICLE, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate article group names");
}
$objResult->MoveNext();
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
$table_name = DBPREFIX . 'module_shop_customer_group';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true));
$table_index = array();
if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) {
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
\Text::deleteByKey('Shop', self::TEXT_NAME_GROUP_CUSTOMER);
$query = "\n SELECT `id`, `name`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query customer group names", $query);
}
while (!$objResult->EOF) {
$group_id = $objResult->fields['id'];
$name = $objResult->fields['name'];
if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_NAME_GROUP_CUSTOMER, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate customer group names");
}
$objResult->MoveNext();
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
$table_name = DBPREFIX . 'module_shop_rel_discount_group';
$table_structure = array('customer_group_id' => array('type' => 'int(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'primary' => true), 'article_group_id' => array('type' => 'int(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'primary' => true), 'rate' => array('type' => 'decimal(9,2)', 'notnull' => true, 'default' => '0.00'));
$table_index = array();
if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) {
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
$table_name = DBPREFIX . 'module_shop_discountgroup_count_name';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true));
$table_index = array();
if (!\Cx\Lib\UpdateUtil::table_exist($table_name)) {
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
\Text::deleteByKey('Shop', self::TEXT_NAME_GROUP_COUNT);
\Text::deleteByKey('Shop', self::TEXT_UNIT_GROUP_COUNT);
$query = "\n SELECT `id`, `name`, `unit`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query count group names", $query);
}
while (!$objResult->EOF) {
$group_id = $objResult->fields['id'];
$name = $objResult->fields['name'];
$unit = $objResult->fields['unit'];
if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_NAME_GROUP_COUNT, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate count group names");
}
if (!\Text::replace($group_id, $default_lang_id, 'Shop', self::TEXT_UNIT_GROUP_COUNT, $unit)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate count group units");
}
$objResult->MoveNext();
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
}
$table_name = DBPREFIX . 'module_shop_discountgroup_count_rate';
$table_structure = array('group_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => 0, 'primary' => true), 'count' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => 1, 'primary' => true), 'rate' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => true, 'default' => '0.00'));
$table_index = array();
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// Always
return false;
}
示例5: errorHandler
/**
* Handle any error occurring in this class.
*
* Tries to fix known problems with the database table.
* @global mixed $objDatabase Database object
* @return boolean False. Always.
* @author Reto Kohli <reto.kohli@comvation.com>
*/
function errorHandler()
{
global $objDatabase;
//die("ImageType::errorHandler(): Disabled!<br />");
$arrTables = $objDatabase->MetaTables('TABLES');
if (in_array(DBPREFIX . "core_imagetype", $arrTables)) {
$objResult = $objDatabase->Execute("\n DROP TABLE `" . DBPREFIX . "core_imagetype`");
if (!$objResult) {
return false;
}
echo "ImageType::errorHandler(): Created table core_imagetype<br />";
}
$objResult = $objDatabase->Execute("\n CREATE TABLE IF NOT EXISTS `" . DBPREFIX . "core_imagetype` (\n `module_id` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'The ID of the module this image type occurs in',\n `key` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'The key unique for each module ID that identifies the image type',\n `text_id` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Relates to core_text.id',\n `width` INT UNSIGNED NULL DEFAULT NULL,\n `height` INT UNSIGNED NULL DEFAULT NULL,\n `quality` INT UNSIGNED NULL DEFAULT NULL,\n `width_thumb` INT UNSIGNED NULL DEFAULT NULL,\n `height_thumb` INT UNSIGNED NULL DEFAULT NULL,\n `quality_thumb` INT UNSIGNED NULL DEFAULT NULL,\n PRIMARY KEY (`module_id`, `key`),\n UNIQUE (`text_id`)\n ) ENGINE=MYISAM");
if (!$objResult) {
return false;
}
echo "ImageType::errorHandler(): Created table core_imagetype<br />";
$arrImagetypes = array(array('module_id' => 10013, 'key' => 'hotelcard_hotel_title', 'text' => array(1 => 'Titelbild', 2 => 'Title', 3 => 'Title', 4 => 'Title'), 'width' => 320, 'height' => 240, 'quality' => 90, 'width_thumb' => 160, 'height_thumb' => 120, 'quality_thumb' => 90), array('module_id' => 10013, 'key' => 'hotelcard_hotel_room', 'text' => array(1 => 'Zimmer', 2 => 'Room', 3 => 'Room', 4 => 'Room'), 'width' => 320, 'height' => 240, 'quality' => 90, 'width_thumb' => 160, 'height_thumb' => 120, 'quality_thumb' => 90), array('module_id' => 10013, 'key' => 'hotelcard_hotel_vicinity', 'text' => array(1 => 'Umbgebung', 2 => 'Vicinity', 3 => 'Vicinity', 4 => 'Vicinity'), 'width' => 320, 'height' => 240, 'quality' => 90, 'width_thumb' => 160, 'height_thumb' => 120, 'quality_thumb' => 90), array('module_id' => 10013, 'key' => 'hotelcard_hotel_lobby', 'text' => array(1 => 'Lobby', 2 => 'Lobby', 3 => 'Lobby', 4 => 'Lobby'), 'width' => 320, 'height' => 240, 'quality' => 90, 'width_thumb' => 160, 'height_thumb' => 120, 'quality_thumb' => 90));
\Text::deleteByKey(self::TEXT_IMAGETYPE);
foreach ($arrImagetypes as $arrImagetype) {
$text_id = 0;
foreach ($arrImagetype['text'] as $lang_id => $text) {
$text_id = \Text::replace($text_id, $lang_id, $text, $arrImagetype['module_id'], self::TEXT_IMAGETYPE);
if (!$text_id) {
die("ImageType::errorHandler(): Error storing Text");
}
}
$objResult = $objDatabase->Execute("\n INSERT INTO `" . DBPREFIX . "core_imagetype` (\n `module_id`, `key`, `text_id`,\n `width`, `height`, `quality`,\n `width_thumb`, `height_thumb`, `quality_thumb`\n ) VALUES (\n " . $arrImagetype['module_id'] . ",\n '" . addslashes($arrImagetype['key']) . "',\n {$text_id},\n " . $arrImagetype['width'] . ",\n " . $arrImagetype['height'] . ",\n " . $arrImagetype['quality'] . ",\n " . $arrImagetype['width_thumb'] . ",\n " . $arrImagetype['height_thumb'] . ",\n " . $arrImagetype['quality_thumb'] . "\n )");
if (!$objResult) {
die("ImageType::errorHandler(): Error adding Imagetype");
}
echo "ImageType::errorHandler(): Inserted image type " . var_export($arrImagetype, true) . "<br />";
}
// More to come...
return false;
}
示例6: store
/**
* 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;
}
示例7: errorHandler
/**
* Tries to recreate the database table(s) for the class
*
* Should be called whenever there's a problem with the database table.
* @return boolean False. Always.
*/
static function errorHandler()
{
$table_name = DBPREFIX . 'core_country';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'alpha2' => array('type' => 'CHAR(2)', 'notnull' => true, 'default' => ''), 'alpha3' => array('type' => 'CHAR(3)', 'notnull' => true, 'default' => ''), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'sort_order'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'notnull' => true, 'default' => '1', 'renamefrom' => 'is_active'));
\Cx\Lib\UpdateUtil::table($table_name, $table_structure);
if (\Cx\Lib\UpdateUtil::table_empty($table_name)) {
\Text::deleteByKey('core', self::TEXT_NAME);
// Copy the Countries from the Shop module if possible
if (\Cx\Lib\UpdateUtil::table_exist(DBPREFIX . "module_shop_countries")) {
$query = "\n SELECT `countries_id`, `countries_name`,\n `countries_iso_code_2`, `countries_iso_code_3`,\n `activation_status`\n FROM " . DBPREFIX . "module_shop_countries";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to query Country names", $query);
}
$default_lang_id = \FWLanguage::getDefaultLangId();
while (!$objResult->EOF) {
$id = $objResult->fields['countries_id'];
$name = $objResult->fields['countries_name'];
$alpha2 = $objResult->fields['countries_iso_code_2'];
$alpha3 = $objResult->fields['countries_iso_code_3'];
$active = $objResult->fields['activation_status'];
$ord = 0;
if ($id == 14) {
// fixing missing name
$name = 'Österreich';
}
if (!self::store($alpha2, $alpha3, $default_lang_id, $name, $ord, $active, $id)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to migrate Country '{$name}'");
}
$objResult->MoveNext();
}
\Cx\Lib\UpdateUtil::drop_table(DBPREFIX . 'module_shop_countries');
}
}
// USE FOR NEW INSTALLATIONS ONLY!
// These records will lead to inconsistencies with Country references in
// other tables otherwise.
if (\Cx\Lib\UpdateUtil::table_empty($table_name)) {
// Add new Country records if available
if (file_exists(ASCMS_CORE_PATH . '/countries_iso_3166-2.php') && (include_once ASCMS_CORE_PATH . '/countries_iso_3166-2.php')) {
//DBG::log("Country::errorHandler(): Included ISO file");
$arrCountries = null;
$ord = 0;
foreach ($arrCountries as $country_id => $arrCountry) {
$name = $arrCountry[0];
$alpha2 = $arrCountry[1];
$alpha3 = $arrCountry[2];
// Not currently in use:
// $numeric = $arrCountry[3];
// $iso_full = $arrCountry[4];
// English (language ID 2) only!
if (!self::store($alpha2, $alpha3, 2, $name, ++$ord, true, $country_id)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to add Country '{$name}' from ISO file");
}
//DBG::log("Country::errorHandler(): Added Country ID $country_id: '$name'");
}
}
}
//DBG::activate(DBG_ADODB);
// Add more languages from the countries_languages.php file,
// if present
$arrCountries = array();
// $arrCountries is redefined in the file
if (file_exists(ASCMS_CORE_PATH . '/countries_languages.php') && (include_once ASCMS_CORE_PATH . '/countries_languages.php')) {
foreach ($arrCountries as $alpha2 => $arrLanguage) {
//DBG::log("errorHandler: Looking for Alpha-2 $alpha2");
$country_id = self::getIdByAlpha2($alpha2);
if (!$country_id) {
// TODO: Fail or not?
continue;
}
foreach ($arrLanguage as $lang_id => $name) {
if (!\Text::replace($country_id, $lang_id, 'core', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to to update Country '{$name}' from languages file");
}
//DBG::log("Country::errorHandler(): Added Country ID $country_id: language ID $lang_id");
}
}
}
\Cx\Core\Setting\Controller\Setting::init('core', 'country');
\Cx\Core\Setting\Controller\Setting::add('numof_countries_per_page_backend', 30, 101);
// More to come...
// Always!
return false;
}
示例8: errorHandler
/**
* Handles database errors
*
* Also migrates text fields to the new structure
* @return boolean False. Always.
* @static
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
// Product
// Fix the Text, Discount, and Manufacturer tables first
\Text::errorHandler();
// Discount::errorHandler(); // Called by Customer::errorHandler();
Manufacturer::errorHandler();
$table_name = DBPREFIX . 'module_shop_products';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true), 'normalprice' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'), 'resellerprice' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'), 'discountprice' => array('type' => 'DECIMAL(9,2)', 'default' => '0.00'), 'discount_active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'is_special_offer'), 'stock' => array('type' => 'INT(10)', 'default' => '10'), 'stock_visible' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'stock_visibility'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'status'), 'b2b' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1'), 'b2c' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1'), 'date_start' => array('type' => 'TIMESTAMP', 'default' => '0000-00-00 00:00:00', 'renamefrom' => 'startdate'), 'date_end' => array('type' => 'TIMESTAMP', 'default' => '0000-00-00 00:00:00', 'renamefrom' => 'enddate'), 'weight' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'category_id' => array('type' => 'VARCHAR(255)', 'default' => '', 'renamefrom' => 'catid'), 'vat_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'manufacturer_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null, 'renamefrom' => 'manufacturer'), 'group_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'article_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => false, 'default' => null), 'usergroup_ids' => array('type' => 'VARCHAR(4096)', 'notnull' => false, 'default' => null), 'ord' => array('type' => 'INT(10)', 'default' => '0', 'renamefrom' => 'sort_order'), 'distribution' => array('type' => 'VARCHAR(16)', 'default' => '', 'renamefrom' => 'handler'), 'picture' => array('type' => 'VARCHAR(4096)', 'notnull' => false, 'default' => null), 'flags' => array('type' => 'VARCHAR(4096)', 'notnull' => false, 'default' => null), 'minimum_order_quantity' => array('type' => 'INT(10)', 'unsigned' => false, 'default' => '0'));
$table_index = array('group_id' => array('fields' => array('group_id')), 'article_id' => array('fields' => array('article_id')), 'flags' => array('fields' => array('flags'), 'type' => 'FULLTEXT'));
$default_lang_id = \FWLanguage::getDefaultLangId();
if (\Cx\Lib\UpdateUtil::table_exist($table_name)) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'title')) {
// Migrate all Product strings to the Text table first
\Text::deleteByKey('Shop', self::TEXT_NAME);
\Text::deleteByKey('Shop', self::TEXT_SHORT);
\Text::deleteByKey('Shop', self::TEXT_LONG);
\Text::deleteByKey('Shop', self::TEXT_CODE);
\Text::deleteByKey('Shop', self::TEXT_URI);
\Text::deleteByKey('Shop', self::TEXT_KEYS);
$query = "\n SELECT `id`, `title`, `shortdesc`, `description`,\n `product_id`, `external_link`, `keywords`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query Product strings", $query);
}
while (!$objResult->EOF) {
$id = $objResult->fields['id'];
$name = $objResult->fields['title'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product name '{$name}'");
}
$short = $objResult->fields['shortdesc'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_SHORT, $short)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product short '{$short}'");
}
$long = $objResult->fields['description'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_LONG, $long)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product long '{$long}'");
}
$code = $objResult->fields['product_id'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_CODE, $code)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product code '{$code}'");
}
$uri = $objResult->fields['external_link'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_URI, $uri)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product uri '{$uri}'");
}
$keys = $objResult->fields['keywords'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_KEYS, $keys)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Product keys '{$keys}'");
}
$objResult->MoveNext();
}
}
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// Also fix Customer and some related tables
Customer::errorHandler();
// Always
return false;
}
示例9: errorHandler
/**
* Handle any error occurring in this class.
*
* Tries to fix known problems with the database table.
* If the table exists, it is dropped.
* After that, the table is created anew.
* Finally, the mime types known are inserted.
* @global mixed $objDatabase Database object
* @return boolean False. Always.
* @author Reto Kohli <reto.kohli@comvation.com>
*/
function errorHandler()
{
global $objDatabase;
die("Filetype::errorHandler(): Disabled!<br />");
$objResult = $objDatabase->Execute("\n ALTER TABLE `" . DBPREFIX . "core_filetype`\n CHANGE `name_text_id` `text_name_id` INT(10) UNSIGNED NOT NULL DEFAULT 0");
if (!$objResult) {
return false;
}
$objResult = $objDatabase->Execute("\n ALTER TABLE `" . DBPREFIX . "core_filetype`\n ADD `ord` INT(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `id`");
if (!$objResult) {
return false;
}
die("Filetype::errorHandler(): Fixed Filetype table");
$arrTables = $objDatabase->MetaTables('TABLES');
if (in_array(DBPREFIX . "core_filetype", $arrTables)) {
// The table does exist, but causes errors! So...
$objResult = $objDatabase->Execute("\n DROP TABLE `" . DBPREFIX . "core_filetype`");
if (!$objResult) {
return false;
}
}
$objResult = $objDatabase->Execute("\n CREATE TABLE `" . DBPREFIX . "core_filetype` (\n `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,\n `ord` INT(10) UNSIGNED NOT NULL DEFAULT 0,\n `text_name_id` INT(10) UNSIGNED NOT NULL DEFAULT 0,\n `extension` VARCHAR(16) NULL COMMENT 'Extension without the leading dot',\n `mimetype` VARCHAR(32) NULL COMMENT 'Mime type',\n PRIMARY KEY (`id`),\n UNIQUE INDEX `type` USING BTREE (`extension`(16) ASC, `mimetype`(32) ASC)\n ) ENGINE=InnoDB");
if (!$objResult) {
return false;
}
/**
* Known extensions and corresponding MIME types.
*
* Note that these associations are arbitrary!
* @var array
*/
$arrExtensions2Mimetypes = array('3dm' => 'x-world/x-3dmf', '3dmf' => 'x-world/x-3dmf', 'ai' => 'application/postscript', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'au' => 'audio/basic', 'avi' => 'video/x-msvideo', 'bin' => 'application/octet-stream', 'cab' => 'application/x-shockwave-flash', 'chm' => 'application/mshelp', 'class' => 'application/octet-stream', 'com' => 'application/octet-stream', 'csh' => 'application/x-csh', 'css' => 'text/css', 'csv' => 'text/comma-separated-values', 'dll' => 'application/octet-stream', 'doc' => 'application/msword', 'dot' => 'application/msword', 'eps' => 'application/postscript', 'exe' => 'application/octet-stream', 'fh4' => 'image/x-freehand', 'fh5' => 'image/x-freehand', 'fhc' => 'image/x-freehand', 'fif' => 'image/fif', 'gif' => 'image/gif', 'gtar' => 'application/x-gtar', 'gz ' => 'application/gzip', 'hlp' => 'application/mshelp', 'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', 'html' => 'text/html', 'ico' => 'image/x-icon', 'ief' => 'image/ief', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', 'js' => 'text/javascript', 'latex' => 'application/x-latex', 'mcf' => 'image/vasa', 'mid' => 'audio/x-midi', 'midi' => 'audio/x-midi', 'mov' => 'video/quicktime', 'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/x-mpeg', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'pbm' => 'image/x-portable-bitmap', 'pdf' => 'application/pdf', 'pgm' => 'image/x-portable-graymap', 'php' => 'application/x-httpd-php', 'phtml' => 'application/x-httpd-php', 'png' => 'image/png', 'pnm' => 'image/x-portable-anymap', 'pot' => 'application/mspowerpoint', 'ppm' => 'image/x-portable-pixmap', 'pps' => 'application/mspowerpoint', 'ppt' => 'application/mspowerpoint', 'ppz' => 'application/mspowerpoint', 'ps' => 'application/postscript', 'qd3' => 'x-world/x-3dmf', 'qd3d' => 'x-world/x-3dmf', 'qt' => 'video/quicktime', 'ra' => 'audio/x-pn-realaudio', 'ram' => 'audio/x-pn-realaudio', 'rgb' => 'image/x-rgb', 'rpm' => 'audio/x-pn-realaudio-plugin', 'rtf' => 'text/rtf', 'rtx' => 'text/richtext', 'sgm' => 'text/x-sgml', 'sgml' => 'text/x-sgml', 'sh' => 'application/x-sh', 'shtml' => 'text/html', 'sit' => 'application/x-stuffit', 'snd' => 'audio/basic', 'stream' => 'audio/x-qt-stream', 'swf' => 'application/x-shockwave-flash', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain', 'viv' => 'video/vnd.vivo', 'vivo' => 'video/vnd.vivo', 'wav' => 'audio/x-wav', 'wbmp' => 'image/vnd.wap.wbmp', 'wml' => 'text/vnd.wap.wml', 'wrl' => 'model/vrml', 'xbm' => 'image/x-xbitmap', 'xhtml' => 'application/xhtml+xml', 'xla' => 'application/msexcel', 'xls' => 'application/msexcel', 'xml' => 'text/xml', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-windowdump', 'z' => 'application/x-compress', 'zip' => 'application/zip');
Text::deleteByKey(self::TEXT_NAME);
foreach ($arrExtensions2Mimetypes as $extension => $mimetype) {
$text_id = 0;
// TODO: Add proper names for the file types
$text_id = Text::replace($text_id, FRONTEND_LANG_ID, $mimetype, MODULE_ID, self::TEXT_NAME);
if (!$text_id) {
echo "Filetype::errorHandler(): Failed to store Text for type {$mimetype}<br />";
continue;
}
$objResult = $objDatabase->Execute("\n INSERT INTO `" . DBPREFIX . "core_filetype` (\n `text_name_id`, `extension`, `mimetype`\n ) VALUES (\n {$text_id}, '" . addslashes($extension) . "', '" . addslashes($mimetype) . "'\n )");
if (!$objResult) {
echo "Filetype::errorHandler(): Failed to store file type {$mimetype}<br />";
continue;
}
}
// More to come...
return false;
}
示例10: errorHandler
/**
* Handles any kind of database error
* @throws Cx\Lib\Update_DatabaseException
* @return boolean False. Always.
*/
static function errorHandler()
{
// ShopCategory
// Fix the Text and Settings table first
\Text::errorHandler();
ShopSettings::errorHandler();
$default_lang_id = \FWLanguage::getDefaultLangId();
$table_name = DBPREFIX . 'module_shop_categories';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'catid'), 'parent_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'parentid'), 'ord' => array('type' => 'INT(5)', 'unsigned' => true, 'default' => '0', 'renamefrom' => 'catsorting'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'catstatus'), 'picture' => array('type' => 'VARCHAR(255)', 'default' => ''), 'flags' => array('type' => 'VARCHAR(255)', 'default' => ''));
$table_index = array('flags' => array('fields' => 'flags', 'type' => 'FULLTEXT'));
if (\Cx\Lib\UpdateUtil::table_exist($table_name)) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'catname')) {
// Migrate all ShopCategory names to the Text table first
\Text::deleteByKey('Shop', self::TEXT_NAME);
\Text::deleteByKey('Shop', self::TEXT_DESCRIPTION);
$query = "\n SELECT `catid`, `catname`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query ShopCategory names");
}
while (!$objResult->EOF) {
$id = $objResult->fields['catid'];
$name = $objResult->fields['catname'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate ShopCategory name '{$name}'");
}
$objResult->MoveNext();
}
}
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// Always
return false;
}
示例11: errorHandler
/**
* Handles database errors
*
* Also migrates text fields to the new structure
* @return boolean False. Always.
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
// Zones
// Fix the Zone-Payment relation table
$table_name = DBPREFIX . 'module_shop_rel_payment';
$table_structure = array('zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'zones_id'), 'payment_id' => array('type' => 'INT(10)', 'unsigned' => true, 'default' => '0', 'primary' => true));
$table_index = array();
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// Fix the Text table
\Text::errorHandler();
$table_name = DBPREFIX . 'module_shop_zones';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'auto_increment' => true, 'primary' => true, 'renamefrom' => 'zones_id'), 'active' => array('type' => 'TINYINT(1)', 'unsigned' => true, 'default' => '1', 'renamefrom' => 'activation_status'));
$table_index = array();
$default_lang_id = \FWLanguage::getDefaultLangId();
if (\Cx\Lib\UpdateUtil::table_exist($table_name)) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'zones_name')) {
// Migrate all Zone names to the Text table first
\Text::deleteByKey('Shop', self::TEXT_NAME);
$query = "\n SELECT `zones_id`, `zones_name`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
if (!$objResult) {
throw new \Cx\Lib\Update_DatabaseException("Failed to query Zone names", $query);
}
while (!$objResult->EOF) {
$id = $objResult->fields['zones_id'];
$name = $objResult->fields['zones_name'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Zone name '{$name}'");
}
$objResult->MoveNext();
}
}
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
$table_name_old = DBPREFIX . 'module_shop_rel_shipment';
$table_name_new = DBPREFIX . 'module_shop_rel_shipper';
if (!\Cx\Lib\UpdateUtil::table_exist($table_name_new) && \Cx\Lib\UpdateUtil::table_exist($table_name_old)) {
\Cx\Lib\UpdateUtil::table_rename($table_name_old, $table_name_new);
}
$table_structure = array('shipper_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'shipment_id'), 'zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'renamefrom' => 'zones_id'));
$table_index = array();
\Cx\Lib\UpdateUtil::table($table_name_new, $table_structure, $table_index);
$table_name = DBPREFIX . 'module_shop_rel_countries';
$table_structure = array('country_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'countries_id'), 'zone_id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'default' => '0', 'primary' => true, 'renamefrom' => 'zones_id'));
$table_index = array();
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// Always
return false;
}
示例12: add_if_not
</p>
</section>
</noscript>
<section id="configuration">
<?php
function add_if_not($obj, $name, $value)
{
if (!$obj->is_set($name)) {
$obj->addChild($name, $value);
}
}
// =====================================================
// posts.xml
// =====================================================
$filenamepost = Text::replace('posts.xml', 'post.xml', FILE_XML_POSTS);
if (file_exists($filenamepost)) {
$obj = new NBXML($filenamepost, 0, TRUE, '', FALSE);
add_if_not($obj, 'friendly', '');
if ($obj->asXml(FILE_XML_POSTS)) {
echo Html::p(array('class' => 'pass', 'content' => 'DB updated: ' . FILE_XML_POSTS));
@unlink($filenamepost);
} else {
echo Html::p(array('class' => 'pass', 'content' => 'FAIL - DB updated: ' . FILE_XML_POSTS));
}
}
// =====================================================
// Posts
// =====================================================
$posts_files = Filesystem::ls(PATH_POSTS, '*', 'xml', false, false, false);
$_DB_POST = new DB_POSTS(FILE_XML_POSTS);
示例13: errorHandler
/**
* Handles database errors
*
* Also migrates the old Manufacturers to the new structure
* @return boolean False. Always.
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
// Manufacturer
// Fix the Text table first
\Text::errorHandler();
$table_name = DBPREFIX . 'module_shop_manufacturer';
// Note: As this table uses a single column, the primary key will
// have to be added separately below. Otherwise, UpdateUtil::table()
// will drop the id column first, then try to drop all the others,
// which obviously won't work.
// In that context, the "AUTO_INCREMENT" has to be dropped as well,
// for that only applies to a primary key column.
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true));
$table_index = array();
$default_lang_id = \FWLanguage::getDefaultLangId();
if (\Cx\Lib\UpdateUtil::table_exist($table_name) && \Cx\Lib\UpdateUtil::column_exist($table_name, 'name')) {
// Get rid of bodies
\Text::deleteByKey('Shop', self::TEXT_NAME);
\Text::deleteByKey('Shop', self::TEXT_URI);
// Migrate all Manufacturer text fields to the Text table
$query = "\n SELECT `id`, `name`, `url`\n FROM `" . DBPREFIX . "module_shop_manufacturer`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
while (!$objResult->EOF) {
$id = $objResult->fields['id'];
$name = $objResult->fields['name'];
$uri = $objResult->fields['url'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_NAME, $name)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Manufacturer name '{$name}'");
}
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_URI, $uri)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate Manufacturer URI '{$uri}'");
}
$objResult->MoveNext();
}
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
\Cx\Lib\UpdateUtil::sql("\n ALTER TABLE `{$table_name}`\n ADD PRIMARY KEY (`id`)");
\Cx\Lib\UpdateUtil::sql("\n ALTER TABLE `{$table_name}`\n CHANGE `id` `id` int(10) unsigned NOT NULL AUTO_INCREMENT");
// Always
return false;
}
示例14: strtolower
}
$filename = $_GET['filename'];
if ($filename) {
// Ext
$ext = strtolower(pathinfo($filename, $pathinfo_extension));
if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
exit(json_encode(array('status' => 0, 'msg' => 'Extension error')));
}
// Stream
$content = file_get_contents("php://input");
if ($content == false) {
exit(json_encode(array('status' => 0, 'msg' => 'Streaming error')));
}
$filename = strtolower(pathinfo($filename, $pathinfo_filename));
$filename = Text::replace(' ', '', $filename);
$filename = Text::replace('_', '', $filename);
//$filename = Text::cut_text($filename, 20);
$number = 0;
while (file_exists($path_upload . $filename . '_' . $number . '_o.' . $ext)) {
$number++;
}
if (file_put_contents($path_upload . $filename . '_' . $number . '_o.' . $ext, $content)) {
// If the gif then don't resize
if ($ext != 'gif') {
// Resize and/or Crop
if ($settings['img_resize']) {
$Resize->setImage($path_upload . $filename . '_' . $number . '_o.' . $ext, $settings['img_resize_width'], $settings['img_resize_height'], $settings['img_resize_option']);
$Resize->saveImage($path_upload . $filename . '_' . $number . '_o.' . $ext, $settings['img_resize_quality']);
}
// Generate thumbnail
if ($settings['img_thumbnail_small']) {
示例15: errorHandler
/**
* Tries to fix database problems
*
* Also migrates text fields to the new structure.
* Note that no VAT classes are added here (yet), so neither the old
* nor the new table exists to begin with, the new structure will be
* created with no records.
* @return boolean False. Always.
* @throws Cx\Lib\Update_DatabaseException
*/
static function errorHandler()
{
// Vat
$table_name = DBPREFIX . 'module_shop_vat';
$table_structure = array('id' => array('type' => 'INT(10)', 'unsigned' => true, 'notnull' => true, 'auto_increment' => true, 'primary' => true), 'rate' => array('type' => 'DECIMAL(5,2)', 'unsigned' => true, 'notnull' => true, 'default' => '0.00', 'renamefrom' => 'percent'));
$table_index = array();
$default_lang_id = \FWLanguage::getDefaultLangId();
if (\Cx\Lib\UpdateUtil::table_exist($table_name, 'class')) {
if (\Cx\Lib\UpdateUtil::column_exist($table_name, 'class')) {
// Migrate all Vat classes to the Text table first
\Text::deleteByKey('Shop', self::TEXT_CLASS);
$query = "\n SELECT `id`, `class`\n FROM `{$table_name}`";
$objResult = \Cx\Lib\UpdateUtil::sql($query);
while (!$objResult->EOF) {
$id = $objResult->fields['id'];
$class = $objResult->fields['class'];
if (!\Text::replace($id, $default_lang_id, 'Shop', self::TEXT_CLASS, $class)) {
throw new \Cx\Lib\Update_DatabaseException("Failed to migrate VAT class '{$class}'");
}
$objResult->MoveNext();
}
}
}
\Cx\Lib\UpdateUtil::table($table_name, $table_structure, $table_index);
// Always
return false;
}