protected function memberBillingAddress_52() { $explanation = "\r\n\t\t\t<h1>52. Member Billing Address</h1>\r\n\t\t\t<p>Move address details in the member table to its own class (billingaddress)</p>\r\n\t\t"; if ($this->retrieveInfoOnly) { return $explanation; } else { echo $explanation; } if ($this->hasTableAndField("Member", "Address")) { if ($this->hasTableAndField("Member", "City")) { $orders = Order::get()->where("\"MemberID\" > 0")->leftJoin("BillingAddress", "\"Order\".\"BillingAddressID\" = \"BillingAddress\".\"ID\"")->limit($this->limit, $this->start); if ($orders->count()) { foreach ($orders as $order) { $member = Member::get()->byID($order->MemberID); if ($member) { if ($obj = $order->BillingAddress()) { $this->DBAlterationMessageNow("Order (id = " . $order->ID . ") already has a billing address"); //do nothing } else { $this->DBAlterationMessageNow("Order (id = " . $order->ID . ") now gets its own billing address..."); $obj = BillingAddress::create(); } if (isset($member->Email) && !$obj->Email) { $obj->Email = $member->Email; } if (isset($member->FirstName) && !$obj->FirstName) { $obj->FirstName = $member->FirstName; } if (isset($member->Surname) && !$obj->Surname) { $obj->Surname = $member->Surname; } if (isset($member->Address) && !$obj->Address) { $obj->Address = $member->Address; } if (isset($member->AddressLine2) && !$obj->Address2) { $obj->Address2 = $member->AddressLine2; } if (isset($member->City) && !$obj->City) { $obj->City = $member->City; } if (isset($member->PostalCode) && !$obj->PostalCode) { $obj->PostalCode = $member->PostalCode; } if (isset($member->State) && !$obj->State) { $obj->State = $member->State; } if (isset($member->Country) && !$obj->Country) { $obj->Country = $member->Country; } if (isset($member->Phone) && !$obj->Phone) { $obj->Phone = $member->Phone; } if (isset($member->HomePhone) && !$obj->HomePhone) { $obj->HomePhone .= $member->HomePhone; } if (isset($member->MobilePhone) && !$obj->MobilePhone) { $obj->MobilePhone = $member->MobilePhone; } $obj->OrderID = $order->ID; $obj->write(); $this->DBAlterationMessageNow("Updated Order #" . $order->ID . " with Member details", "created"); DB::query("Update \"Order\" SET \"BillingAddressID\" = " . $obj->ID . " WHERE \"Order\".ID = " . $order->ID); } else { $this->DBAlterationMessageNow("There is no member associated with this order " . $order->ID, "deleted"); } } return $this->start + $this->limit; } else { $this->DBAlterationMessageNow("No orders need adjusting even though they followed the old pattern."); } } else { $this->DBAlterationMessageNow("There is no Address2 field, but there is an Address field in Member - this might be an issue.", "deleted"); } } else { $this->DBAlterationMessageNow("Members do not have a billing address to migrate."); } return 0; }