// 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]' ....
core_enum.display_name LIKE '%{$name}%'
");
}
+ if (isset($q['_etypes'])) {
+ $this->whereAddIn('core_enu.etype', explode(',', $q['_etypes']), 'string');
+ }
}
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');
}
}
}
if ($old->etype != $this->etype) {
$x->query("SELECT core_enum_seqmax_update('". $this->escape($old->etype) ."')");
}
- if($this->name != $old->name && empty($old->etype) && empty($this->etype)){
+
+ if($this->name != $old->name && !empty($old->name) && empty($old->etype) && empty($this->etype)){
$x->query("UPDATE core_enum SET etype = '". $this->escape($this->name)
."' WHERE etype = '". $this->escape($old->name)."'");
}
}
- 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');
+
}