From e055181e9fdfefbe73ad9fefa8e2da0a2b7764fa Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 30 Jun 2022 14:03:03 +0200 Subject: [PATCH] Added script to create AddressLink records from Order->billingaddress_id --- .../order-billingaddress-to-addresslink.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/order-billingaddress-to-addresslink.php diff --git a/scripts/order-billingaddress-to-addresslink.php b/scripts/order-billingaddress-to-addresslink.php new file mode 100644 index 000000000..d80a560e6 --- /dev/null +++ b/scripts/order-billingaddress-to-addresslink.php @@ -0,0 +1,45 @@ +#!/usr/bin/php +billingaddress_id, if it doesn't exist + */ +require("../config/config.php"); + +define('FRONKDB_SQLDEBUG',false); +error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED)); + +require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php"); +require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php"); +require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php"); + +$me = new User(1); + +$i = 0; + +foreach(OrderModel::getAll() as $order) { + if(!$order->billingaddress_id) { + continue; + } + + $data['address_id'] = $order->billingaddress_id; + $data['origin_address_id'] = $order->owner_id; + $data['type'] = "billing"; + + $link = AddressLinkModel::getFirst($data); + if($link && $link->id) { + continue; + } + + $data['create_by'] = $order->create_by; + $data['edit_by'] = $order->edit_by; + + $link = AddressLinkModel::create($data); + if(!$link->save()) { + echo "Unable to save billingaddress: ".$data['address_id'].", origin address: ".$data['origin_address_id']."\n"; + continue; + } + + $i++; +} + +echo "Created $i billingaddress linkings\n";