shop.balmet.com

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

1003.php (7392B)


      1 <?php
      2 class ModelUpgrade1003 extends Model {
      3 	public function upgrade() {
      4 		// affiliate_activity
      5 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "affiliate_activity'");
      6 		
      7 		if ($query->num_rows) {
      8 			$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "affiliate_activity' AND COLUMN_NAME = 'activity_id'");
      9 	
     10 			if ($query->num_rows) {
     11 				$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "affiliate_activity' AND COLUMN_NAME = 'affiliate_activity_id'");
     12 	
     13 				if ($query->num_rows) {
     14 					$this->db->query("UPDATE `" . DB_PREFIX . "affiliate_activity` SET `affiliate_activity_id` = `activity_id` WHERE `affiliate_activity_id` IS NULL or `affiliate_activity_id` = ''");
     15 					$this->db->query("ALTER TABLE `" . DB_PREFIX . "affiliate_activity` DROP `activity_id`");
     16 				} else {
     17 					$this->db->query("ALTER TABLE `" . DB_PREFIX . "affiliate_activity` CHANGE `activity_id` `affiliate_activity_id` INT(11) NOT NULL AUTO_INCREMENT");
     18 				}
     19 			}
     20 		}
     21 
     22 		// customer_activity
     23 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "customer_activity' AND COLUMN_NAME = 'activity_id'");
     24 
     25 		if ($query->num_rows) {
     26 			$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "customer_activity' AND COLUMN_NAME = 'activity_id'");
     27 
     28 			if ($query->num_rows) {
     29 				$this->db->query("UPDATE `" . DB_PREFIX . "customer_activity` SET `customer_activity_id` = `activity_id` WHERE `customer_activity_id` IS NULL or `customer_activity_id` = ''");
     30 				$this->db->query("ALTER TABLE `" . DB_PREFIX . "customer_activity` DROP `activity_id`");
     31 			} else {
     32 				$this->db->query("ALTER TABLE `" . DB_PREFIX . "customer_activity` CHANGE `activity_id` `customer_activity_id` INT(11) NOT NULL AUTO_INCREMENT");
     33 			}
     34 		}
     35 
     36 		// setting
     37 		$query = $this->db->query("SELECT setting_id,value FROM `" . DB_PREFIX . "setting` WHERE serialized = '1' AND value LIKE 'a:%'");
     38 
     39 		foreach ($query->rows as $result) {
     40 			if (preg_match('/^(a:)/', $result['value'])) {
     41 				$this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = '" . $this->db->escape(json_encode(unserialize($result['value']))) . "' WHERE `setting_id` = '" . (int)$result['setting_id'] . "'");
     42 			}
     43 		}
     44 
     45 		// customer
     46 		$query = $this->db->query("SELECT customer_id,cart,wishlist,custom_field FROM `" . DB_PREFIX . "customer` WHERE custom_field LIKE 'a:%' OR cart LIKE 'a:%' OR wishlist LIKE 'a:%'");
     47 
     48 		foreach ($query->rows as $result) {
     49 			if (preg_match('/^(a:)/', $result['cart'])) {
     50 				$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `cart` = '" . $this->db->escape(json_encode(unserialize($result['cart']))) . "' WHERE `customer_id` = '" . (int)$result['customer_id'] . "'");
     51 			}
     52 
     53 			if (preg_match('/^(a:)/', $result['wishlist'])) {
     54 				$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `wishlist` = '" . $this->db->escape(json_encode(unserialize($result['wishlist']))) . "' WHERE `customer_id` = '" . (int)$result['customer_id'] . "'");
     55 			}
     56 
     57 			if (preg_match('/^(a:)/', $result['custom_field'])) {
     58 				$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `custom_field` = '" . $this->db->escape(json_encode(unserialize($result['custom_field']))) . "' WHERE `customer_id` = '" . (int)$result['customer_id'] . "'");
     59 			}
     60 		}
     61 
     62 		// address
     63 		$query = $this->db->query("SELECT address_id,custom_field FROM `" . DB_PREFIX . "address` WHERE custom_field LIKE 'a:%'");
     64 
     65 		foreach ($query->rows as $result) {
     66 			if (preg_match('/^(a:)/', $result['custom_field'])) {
     67 				$this->db->query("UPDATE `" . DB_PREFIX . "address` SET `custom_field` = '" . $this->db->escape(json_encode(unserialize($result['custom_field']))) . "' WHERE `address_id` = '" . (int)$result['address_id'] . "'");
     68 			}
     69 		}
     70 
     71 		// order
     72 		$query = $this->db->query("SELECT order_id, custom_field, payment_custom_field, shipping_custom_field FROM `" . DB_PREFIX . "order` WHERE custom_field LIKE 'a:%' OR payment_custom_field LIKE 'a:%' OR shipping_custom_field LIKE 'a:%'");
     73 
     74 		foreach ($query->rows as $result) {
     75 			if (preg_match('/^(a:)/', $result['custom_field'])) {
     76 				$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `custom_field` = '" . $this->db->escape(json_encode(unserialize($result['shipping_custom_field']))) . "' WHERE `order_id` = '" . (int)$result['order_id'] . "'");
     77 			}
     78 
     79 			if (preg_match('/^(a:)/', $result['payment_custom_field'])) {
     80 				$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `payment_custom_field` = '" . $this->db->escape(json_encode(unserialize($result['shipping_custom_field']))) . "' WHERE `order_id` = '" . (int)$result['order_id'] . "'");
     81 			}
     82 
     83 			if (preg_match('/^(a:)/', $result['shipping_custom_field'])) {
     84 				$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `shipping_custom_field` = '" . $this->db->escape(json_encode(unserialize($result['shipping_custom_field']))) . "' WHERE `order_id` = '" . (int)$result['order_id'] . "'");
     85 			}
     86 		}
     87 
     88 		// user_group
     89 		$query = $this->db->query("SELECT user_group_id,permission FROM `" . DB_PREFIX . "user_group`");
     90 
     91 		foreach ($query->rows as $result) {
     92 			if (preg_match('/^(a:)/', $result['permission'])) {
     93 				$this->db->query("UPDATE `" . DB_PREFIX . "user_group` SET `permission` = '" . $this->db->escape(json_encode(unserialize($result['permission']))) . "' WHERE `user_group_id` = '" . (int)$result['user_group_id'] . "'");
     94 			}
     95 		}
     96 
     97 		// affiliate_activity
     98 		$query = $this->db->query("SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . DB_PREFIX . "affiliate_activity'");
     99 
    100 		if ($query->num_rows) {
    101 			$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "affiliate_activity` WHERE data LIKE 'a:%'");
    102 	
    103 			foreach ($query->rows as $result) {
    104 				if (preg_match('/^(a:)/', $result['data'])) {
    105 					$this->db->query("UPDATE `" . DB_PREFIX . "affiliate_activity` SET `data` = '" . $this->db->escape(json_encode(unserialize($result['data']))) . "' WHERE `affiliate_activity_id` = '" . (int)$result['affiliate_activity_id'] . "'");
    106 				}
    107 			}
    108 		}
    109 		
    110 		// customer_activity
    111 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_activity` WHERE data LIKE 'a:%'");
    112 
    113 		foreach ($query->rows as $result) {
    114 			if (preg_match('/^(a:)/', $result['data'])) {
    115 				$this->db->query("UPDATE `" . DB_PREFIX . "customer_activity` SET `data` = '" . $this->db->escape(json_encode(unserialize($result['data']))) . "' WHERE `customer_activity_id` = '" . (int)$result['customer_activity_id'] . "'");
    116 			}
    117 		}
    118 
    119 		// module
    120 		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module`");
    121 
    122 		foreach ($query->rows as $result) {
    123 			if (preg_match('/^(a:)/', $result['setting'])) {
    124 				$this->db->query("UPDATE `" . DB_PREFIX . "module` SET `setting` = '" . $this->db->escape(json_encode(unserialize($result['setting']))) . "' WHERE `module_id` = '" . (int)$result['module_id'] . "'");
    125 			}
    126 		}
    127 	}
    128 }