protected function orderShippingAddress_50() { $explanation = "\r\n\t\t\t<h1>50. Order Shipping Address</h1>\r\n\t\t\t<p>Move a shipping address from within Order to its own class.</p>\r\n\t\t"; if ($this->retrieveInfoOnly) { return $explanation; } else { echo $explanation; } if ($this->hasTableAndField("Order", "ShippingAddress")) { if ($this->hasTableAndField("Order", "UseShippingAddress")) { $orders = Order::get()->where("\"UseShippingAddress\" = 1 AND \"ShippingAddress\".\"ID\" IS NULL")->leftJoin("ShippingAddress", "\"Order\".\"ShippingAddressID\" = \"ShippingAddress\".\"ID\"")->limit($this->limit, $this->start); if ($orders->count()) { foreach ($orders as $order) { if (!$order->ShippingAddressID) { $obj = ShippingAddress::create(); if (isset($order->ShippingName)) { $obj->ShippingName = $order->ShippingName; } if (isset($order->ShippingAddress)) { $obj->ShippingAddress = $order->ShippingAddress; } if (isset($order->ShippingAddress2)) { $obj->ShippingAddress2 = $order->ShippingAddress2; } if (isset($order->ShippingCity)) { $obj->ShippingCity = $order->ShippingCity; } if (isset($order->ShippingPostalCode)) { $obj->ShippingPostalCode = $order->ShippingPostalCode; } if (isset($order->ShippingState)) { $obj->ShippingState = $order->ShippingState; } if (isset($order->ShippingCountry)) { $obj->ShippingCountry = $order->ShippingCountry; } if (isset($order->ShippingPhone)) { $obj->ShippingPhone = $order->ShippingPhone; } if (isset($order->ShippingHomePhone)) { $obj->ShippingPhone .= $order->ShippingHomePhone; } if (isset($order->ShippingMobilePhone)) { $obj->ShippingMobilePhone = $order->ShippingMobilePhone; } $obj->OrderID = $order->ID; $obj->write(); $order->ShippingAddressID = $obj->ID; $order->write(); } else { $this->DBAlterationMessageNow("Strange contradiction occurred in Order with ID" . $order->ID, "deleted"); } } return $this->start + $this->limit; } else { $this->DBAlterationMessageNow("No orders need adjusting even though they followed the old pattern."); } $this->makeFieldObsolete("Order", "ShippingName"); $this->makeFieldObsolete("Order", "ShippingAddress"); $this->makeFieldObsolete("Order", "ShippingAddress2"); $this->makeFieldObsolete("Order", "ShippingCity"); $this->makeFieldObsolete("Order", "ShippingPostalCode"); $this->makeFieldObsolete("Order", "ShippingState"); $this->makeFieldObsolete("Order", "ShippingCountry"); $this->makeFieldObsolete("Order", "ShippingPhone"); $this->makeFieldObsolete("Order", "ShippingHomePhone"); $this->makeFieldObsolete("Order", "ShippingMobilePhone"); } else { $this->DBAlterationMessageNow("There is no UseShippingAddress field even though there is a ShippingAddress Field - this is an issue.", "deleted"); } } else { $this->DBAlterationMessageNow("Orders do not have the shipping address to migrate."); } return 0; }