shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

1004.php (15314B)


      1 <?php
      2 class ModelUpgrade1004 extends Model {
      3 	public function upgrade() {
      4 		// custom_field
      5 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "custom_field' AND COLUMN_NAME = 'required'");
      6 
      7 		if ($query->num_rows) {
      8 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "custom_field` DROP `required`");
      9 		}
     10 
     11 		// custom_field
     12 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "custom_field' AND COLUMN_NAME = 'position'");
     13 
     14 		if ($query->num_rows) {
     15 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "custom_field` DROP `position`");
     16 		}
     17 
     18 		// custom_field
     19 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "custom_field' AND COLUMN_NAME = 'status'");
     20 
     21 		if (!$query->num_rows) {
     22 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "custom_field` ADD `status` tinyint(1) NOT NULL AFTER `location`");
     23 		}
     24 
     25 		// custom_field
     26 		$this->db->query("ALTER TABLE `" . DB_PREFIX . "custom_field` CHANGE `location` `location` varchar(7) NOT NULL");
     27 
     28 		// order_custom_field
     29 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "order_field'");
     30 
     31 		if ($query->num_rows) {
     32 			$order_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_field`");
     33 
     34 			foreach ($order_field_query->rows as $result) {
     35 				$order_custom_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_custom_field` WHERE `order_id` = '" . (int)$result['order_id'] . "' AND custom_field_id = '" . (int)$result['custom_field_id'] . "' AND custom_field_value_id = '" . (int)$result['custom_field_value_id'] . "' AND `name` = '" . $this->db->escape($result['name']) . "' AND `value` = '" . $this->db->escape($result['value']) . "'");
     36 
     37 				if (!$order_custom_field_query->num_rows) {
     38 					$this->db->query("INSERT INTO `" . DB_PREFIX . "order_custom_field` SET `order_id` = '" . (int)$result['order_id'] . "', custom_field_id = '" . (int)$result['custom_field_id'] . "', custom_field_value_id = '" . (int)$result['custom_field_value_id'] . "', `name` = '" . $this->db->escape($result['name']) . "', `value` = '" . $this->db->escape($result['value']) . "'");
     39 				}
     40 			}
     41 
     42 			$this->db->query("DROP TABLE `" . DB_PREFIX . "order_field`");
     43 		}
     44 
     45 		// download
     46 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "download' AND COLUMN_NAME = 'remaining'");
     47 
     48 		if ($query->num_rows) {
     49 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "download` DROP `remaining`");
     50 		}
     51 
     52 		// information_description
     53 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "information_description' AND COLUMN_NAME = 'meta_title'");
     54 
     55 		if (!$query->num_rows) {
     56 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_title` varchar(255) NOT NULL AFTER `description`");
     57 		}
     58 
     59 		// information_description
     60 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "information_description' AND COLUMN_NAME = 'meta_description'");
     61 
     62 		if (!$query->num_rows) {
     63 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_description` varchar(255) NOT NULL AFTER `meta_title`");
     64 		}
     65 
     66 		// information_description
     67 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "information_description' AND COLUMN_NAME = 'meta_keyword'");
     68 
     69 		if (!$query->num_rows) {
     70 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "information_description` ADD `meta_keyword` varchar(255) NOT NULL AFTER `meta_description`");
     71 		}
     72 
     73 		// order
     74 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "order' AND COLUMN_NAME = 'marketing_id'");
     75 
     76 		if (!$query->num_rows) {
     77 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "order` ADD `marketing_id` int(11) NOT NULL AFTER `commission`");
     78 		}
     79 
     80 		// order
     81 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "order' AND COLUMN_NAME = 'tracking'");
     82 
     83 		if (!$query->num_rows) {
     84 			$this->db->query("ALTER TABLE `" . DB_PREFIX . "order` ADD `tracking` varchar(64) NOT NULL AFTER `marketing_id`");
     85 		}
     86 
     87 		// Update some new default settings
     88 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '0'");
     89 
     90 		foreach ($query->rows as $setting) {
     91 			if (!$setting['serialized']) {
     92 				$settings[$setting['key']] = $setting['value'];
     93 			} else {
     94 				$settings[$setting['key']] = json_decode($setting['value'], true);
     95 			}
     96 		}
     97 
     98 		// Convert _smtp_ to _mail_smtp_
     99 		if (empty($settings['config_mail_smtp_hostname']) && !empty($settings['config_smtp_host'])) {
    100 			$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `value` = '" . $settings['config_smtp_host'] . "', `key` = 'config_mail_smtp_hostname', `code` = 'config', `store_id` = 0");
    101 		}
    102 		if (empty($settings['config_mail_smtp_username']) && !empty($settings['config_smtp_username'])) {
    103 			$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `value` = '" . $settings['config_smtp_username'] . "', `key` = 'config_mail_smtp_username', `code` = 'config', `store_id` = 0");
    104 		}
    105 		if (empty($settings['config_mail_smtp_password']) && !empty($settings['config_smtp_password'])) {
    106 			$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `value` = '" . $settings['config_smtp_password'] . "', `key` = 'config_mail_smtp_password', `code` = 'config', `store_id` = 0");
    107 		}
    108 		if (empty($settings['config_mail_smtp_port']) && !empty($settings['config_smtp_port'])) {
    109 			$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `value` = '" . $settings['config_smtp_port'] . "', `key` = 'config_mail_smtp_port', `code` = 'config', `store_id` = 0");
    110 		}
    111 		if (empty($settings['config_mail_smtp_timeout']) && !empty($settings['config_smtp_timeout'])) {
    112 			$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `value` = '" . $settings['config_smtp_timeout'] . "', `key` = 'config_mail_smtp_timeout', `code` = 'config', `store_id` = 0");
    113 		}
    114 
    115 		// setting
    116 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_meta_title'");
    117 
    118 		if (!$query->num_rows) {
    119 			$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `key` = 'config_meta_title', `value` = '" . $this->db->escape($settings['config_name']) . "', `code` = 'config', `serialized` = '0', `store_id` = 0");
    120 		}
    121 
    122 		// Convert 1.5.x core module format to 2.x (core modules only)
    123 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE serialized = '1'");
    124 
    125 		foreach ($query->rows as $result) {
    126 			if ($result['serialized']) {
    127 				$value = json_decode($result['value'], true);
    128 
    129 				$module_data = array();
    130 				if (in_array($result['code'], array('latest', 'bestseller', 'special', 'featured'))) {
    131 					if ($value) {
    132 						foreach ($value as $k => $v) {
    133 
    134 							// Since 2.x doesn't look good with modules as side boxes, set to content bottom
    135 							if ($v['position'] == 'column_left' || $v['position'] == 'column_right') {
    136 								$v['position'] = 'content_bottom';
    137 							}
    138 
    139 							$module_data['name'] = ($result['key'] . '_' . $k);
    140 							$module_data['status'] = $v['status'];
    141 							if (isset($v['image_width'])) {	$module_data['width'] = $v['image_width']; }
    142 							if (isset($v['image_height'])) { $module_data['height'] = $v['image_height']; }
    143 							if (isset($v['limit'])) { $module_data['limit'] = $v['limit']; } else { $module_data['limit'] = 4; }
    144 
    145 							if ($result['code'] == 'featured') {
    146 								foreach ($query->rows as $result2) {
    147 									if ($result2['key'] == 'featured_product') {
    148 										$module_data['product'] = explode(",", $result2['value']);
    149 										$module_data['limit'] = 4;
    150 										break;
    151 									} else {
    152 										$featured_product_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `key` = 'featured_product'");
    153 										if ($featured_product_query->num_rows) {
    154 											$module_data['product'] = explode(",", $featured_product_query->row['value']);
    155 											$module_data['limit'] = 4;
    156 										}
    157 									}
    158 								}
    159 							}
    160 
    161 							$this->db->query("INSERT INTO `" . DB_PREFIX . "module` (`name`, `code`, `setting`) values ('" . $this->db->escape($result['key']) . '_' . $k . "', '" . $this->db->escape($result['code']) . "', '" . $this->db->escape(json_encode($module_data)) . "')");
    162 							$module_id = $this->db->getLastId();
    163 							$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_module` (`layout_id`, `code`, `position`, `sort_order`) values ('" . (int)$v['layout_id'] . "', '" . ($result['code'] . '.' . $module_id)  . "', '" . $this->db->escape($v['position']) . "', '" . (int)$v['sort_order'] . "')");
    164 							$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . $result['store_id'] . "' AND `code` = '" . $result['code'] . "'");
    165 						}
    166 					} else {
    167 						$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `code` = '" . $this->db->escape($result['code']) . "'");
    168 					}
    169 				} elseif (in_array($result['code'], array('category', 'account', 'affiliate', 'filter'))) {
    170 					foreach ($value as $k => $v) {
    171 						$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . $result['store_id'] . "' AND `code` = '" . $result['code'] . "'");
    172 						$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET store_id = '" . $result['store_id'] . "', `code` = '" . $result['code'] . "', `key` = '" . ($result['code'] . '_status') . "', value = 1");
    173 						if ($v['status']) {
    174 							$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_module` (`layout_id`, `code`, `position`, `sort_order`) values ('" . (int)$v['layout_id'] . "', '" . ($result['code'])  . "', '" . $this->db->escape($v['position']) . "', '" . (int)$v['sort_order'] . "')");
    175 						}
    176 					}
    177 				} elseif (in_array($result['code'], array('banner', 'carousel', 'slideshow'))) {
    178 					if ($value) {
    179 						foreach ($value as $k => $v) {
    180 							$module_data['name'] = ($result['key'] . '_' . $k);
    181 							$module_data['status'] = $v['status'];
    182 							$module_data['banner_id'] = $v['banner_id'];
    183 							if (isset($v['image_width'])) {	$module_data['width'] = $v['image_width']; }
    184 							if (isset($v['image_height'])) { $module_data['height'] = $v['image_height']; }
    185 							if (isset($v['width'])) {	$module_data['width'] = $v['width']; }
    186 							if (isset($v['height'])) {	$module_data['height'] = $v['height']; }
    187 
    188 							$this->db->query("INSERT INTO `" . DB_PREFIX . "module` (`name`, `code`, `setting`) values ('" . $this->db->escape($result['key']) . '_' . $k . "', '" . $this->db->escape($result['code']) . "', '" . $this->db->escape(json_encode($module_data)) . "')");
    189 							$module_id = $this->db->getLastId();
    190 							$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_module` (`layout_id`, `code`, `position`, `sort_order`) values ('" . (int)$v['layout_id'] . "', '" . ($result['code'] . '.' . $module_id)  . "', '" . $this->db->escape($v['position']) . "', '" . (int)$v['sort_order'] . "')");
    191 							$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . $result['store_id'] . "' AND `code` = '" . $result['code'] . "'");
    192 						}
    193 					} else {
    194 						$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `code` = '" . $this->db->escape($result['code']) . "'");
    195 					}
    196 				} elseif (in_array($result['code'], array('welcome'))) {
    197 					if ($value) {
    198 						// Install HTML module if not already installed
    199 						$html_query = $this->db->query("SELECT count(*) FROM " . DB_PREFIX . "extension WHERE code = 'html'");
    200 						if ($html_query->row['count(*)'] == '0') {
    201 							$this->db->query("INSERT INTO `" . DB_PREFIX . "extension` SET `type` = 'module', `code` = 'html'");
    202 						}
    203 						$result['code'] = 'html';
    204 						foreach ($value as $k => $v) {
    205 							$module_data['name'] = ($result['key'] . '_' . $k);
    206 							$module_data['status'] = $v['status'];
    207 							foreach($v['description'] as $language_id => $description) {
    208 								$module_data['module_description'][$language_id]['title'] = '';
    209 								$module_data['module_description'][$language_id]['description'] = str_replace('image/data', 'image/catalog', $description);
    210 							}
    211 
    212 							$this->db->query("INSERT INTO `" . DB_PREFIX . "module` (`name`, `code`, `setting`) values ('" . $this->db->escape($result['key']) . '_' . $k . "', '" . $this->db->escape($result['code']) . "', '" . $this->db->escape(json_encode($module_data)) . "')");
    213 							$module_id = $this->db->getLastId();
    214 							$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_module` (`layout_id`, `code`, `position`, `sort_order`) values ('" . (int)$v['layout_id'] . "', '" . ($result['code'] . '.' . $module_id)  . "', '" . $this->db->escape($v['position']) . "', '" . (int)$v['sort_order'] . "')");
    215 							$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . $result['store_id'] . "' AND `code` = 'welcome'");
    216 						}
    217 					} else {
    218 						//$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `code` = '" . $this->db->escape($result['code']) . "'");
    219 						$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `code` = 'welcome'");
    220 					}
    221 				} else {
    222 					// could add code for other types here
    223 					// If module has position, but not a core module, then disable it because it likely isn't compatible
    224 					if (!empty($value)) {
    225 						foreach ($value as $k => $v) {
    226 							if (isset($v['position'])) {
    227 								$module_data = $v;
    228 								$module_data['name'] = ($result['key'] . '_' . $k);
    229 								$module_data['status'] = '0'; // Disable non-core modules
    230 
    231 								$this->db->query("INSERT INTO `" . DB_PREFIX . "module` (`name`, `code`, `setting`) values ('" . $this->db->escape($result['key']) . '_' . $k . "', '" . $this->db->escape($result['code']) . "', '" . $this->db->escape(json_encode($module_data)) . "')");
    232 								//$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `setting_id` = '" . (int)$result['setting_id'] . "'");
    233 								//$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `code` = '" . $this->db->escape($result['code']) . "'");
    234 								//$this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($result['code']) . "'");
    235 							}
    236 						}
    237 					} else {
    238 						$this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = '" . $this->db->escape(json_encode($value)) . "' WHERE `setting_id` = '" . (int)$result['setting_id'] . "'");
    239 					}
    240 				}
    241 			} else {
    242 
    243 			}
    244 		}
    245 	}
    246 }