From: edward Date: Fri, 4 Nov 2016 05:34:58 +0000 (+0800) Subject: DataObjects/Core_company.php X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=commitdiff_plain;h=95f9a18b3d1dee7025199140c64a4dc935d356c2 DataObjects/Core_company.php --- diff --git a/DataObjects/Core_company.php b/DataObjects/Core_company.php index 6953eef6..bfda8947 100644 --- a/DataObjects/Core_company.php +++ b/DataObjects/Core_company.php @@ -425,4 +425,45 @@ class Pman_Core_DataObjects_Core_Company extends DB_DataObject } return false; } + + function merge($merge_to, $roo) + { + $affects = array(); + + $all_links = $GLOBALS['_DB_DATAOBJECT']['LINKS'][$this->_database]; + + foreach($all_links as $tbl => $links) { + foreach($links as $col => $totbl_col) { + $to = explode(':', $totbl_col); + if ($to[0] != $this->tableName()) { + continue; + } + + $affects[$tbl .'.' . $col] = true; + } + } + print_R($affects);exit; + foreach($affects as $k => $true) { + $ka = explode('.', $k); + + $chk = DB_DataObject::factory($ka[0]); + + if (!is_a($chk,'DB_DataObject')) { + $roo->jerr('Unable to load referenced table, check the links config: ' .$ka[0]); + } + + $chk->{$ka[1]} = $this->id; + + foreach ($chk->fetchAll() as $c){ + $cc = clone ($c); + $c->{$ka[1]} = $merge_to; + $c->update($cc); + } + } + + $this->delete(); + + $roo->jok('Merged'); + + } }