// DB_DataObject::debugLevel(1);
if (!empty($q['query']['empty_etype'])) {
- $this->whereAdd("etype = ''");
+ $this->whereAdd("core_enum.etype = ''");
}
// this should be handled by roo... using '!name[0]' ....
function beforeUpdate($old, $request,$roo)
{
if(!empty($request['_merge_id'])){
- $this->merge($request['_merge_id']);
+ $this->merge($request['_merge_id'], $roo);
}
$tn = $this->tableName();
$x = $this->factory($tn);
- if(!($old->etype == $request['etype'] && $old->name == $request['name'])){
+ // check if record exists?
+ if(isset($request['etype']) && !($old->etype == $request['etype'] && $old->name == $request['name'])){
$x->whereAdd("etype = '{$this->escape($request['etype'])}' AND name = '{$this->escape($request['name'])}'");
$x->find(true);
if($x->count() > 0){
- $roo->jerr('is exsiting');
+ $roo->jerr('record already exists');
}
}
}
}
- function merge($id)
+ function merge($merge_to, $roo)
{
$affects = array();
$ka = explode('.', $k);
$chk = DB_DataObject::factory($ka[0]);
+
if (!is_a($chk,'DB_DataObject')) {
- $this->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
+ $roo->jerr('Unable to load referenced table, check the links config: ' .$ka[0]);
}
- // print_r(array($chk->tablename() , $ka[1] , $xx->tablename() , $this->key ));
- $chk->{$ka[1]} = $xx->{$this->key};
+
+ $chk->{$ka[1]} = $this->id;
- if (count($chk->keys())) {
- $matches = $chk->count();
- } else {
- //DB_DataObject::DebugLevel(1);
- $matches = $chk->count($ka[1]);
+ foreach ($chk->fetchAll() as $c){
+ $cc = clone ($c);
+ $c->{$ka[1]} = $merge_to;
+ $c->update($cc);
}
-
- if ($matches) {
- $chk->_match_key = $ka[1];
- $match_ar[] = clone($chk);
- continue;
- }
}
+ $this->delete();
+
+ $roo->jok('Merged');
+
}