public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event) { if ($this->_updates) { $or = array(); foreach ($this->_updates as $key => $values) { if ($key === 'component_id') { $or[] = new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('component_id', array_unique($values)), new Kwf_Model_Select_Expr_Equal('type', 'component'))); } else { if ($key === 'master-component_id') { $or[] = new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('component_id', array_unique($values)), new Kwf_Model_Select_Expr_Equal('type', 'master'))); } else { $and = array(); foreach ($values as $k => $v) { if (substr($v, -1) == '%') { $v = substr($v, 0, -1); $and[] = new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal($k, $v), new Kwf_Model_Select_Expr_Like($k, $v . '-%'), new Kwf_Model_Select_Expr_Like($k, $v . '_%'))); } else { if (strpos($v, '%') !== false) { $and[] = new Kwf_Model_Select_Expr_Like($k, $v); } else { $and[] = new Kwf_Model_Select_Expr_Equal($k, $v); } } } $or[] = new Kwf_Model_Select_Expr_And($and); } } } $select = new Kwf_Model_Select(); $select->where($or[0]); unset($or[0]); foreach ($or as $i) { $s = new Kwf_Model_Select(); $s->where($i); $select->union($s); } Kwf_Component_Cache::getInstance()->deleteViewCache($select); $this->_updates = array(); } foreach ($this->_pageParentChanges as $changes) { $oldParentId = $changes['oldParentId']; $newParentId = $changes['newParentId']; $componentId = $changes['componentId']; $length = strlen($oldParentId); $like = $oldParentId . '_' . $componentId; $model = Kwf_Component_Cache::getInstance()->getModel(); while ($model instanceof Kwf_Model_Proxy) { $model = $model->getProxyModel(); } if ($model instanceof Kwf_Model_Db) { $db = Kwf_Registry::get('db'); $newParentId = $db->quote($newParentId); $where[] = 'expanded_component_id = ' . $db->quote($like); $where[] = 'expanded_component_id LIKE ' . str_replace('_', '\\_', $db->quote($like . '-%')); $where[] = 'expanded_component_id LIKE ' . str_replace('_', '\\_', $db->quote($like . '_%')); $sql = "UPDATE cache_component\n SET expanded_component_id=CONCAT(\n {$newParentId}, SUBSTRING(expanded_component_id, {$length})\n )\n WHERE " . implode(' OR ', $where); $model->executeSql($sql); $this->_log("expanded_component_id={$like}%->{$newParentId}"); } else { $model = Kwf_Component_Cache::getInstance()->getModel(); $select = $model->select()->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $like . '%')); foreach ($model->getRows($select) as $row) { $oldExpandedId = $row->expanded_component_id; $newExpandedId = $newParentId . substr($oldExpandedId, $length); $row->expanded_component_id = $newExpandedId; $row->save(); $this->_log("expanded_component_id={$oldExpandedId}->{$newExpandedId}"); } } } $this->_pageParentChanges = array(); }
public function testUnion() { $model = new Kwf_Model_DbWithConnection_ImportExport_Model(array("table" => $this->_tableName)); $s1 = new Kwf_Model_Select(); $s1->whereEquals('id', 1); $s2 = new Kwf_Model_Select(); $s2->whereEquals('id', 2); $s1->union($s2); $this->assertEquals(count($model->export(Kwf_Model_Interface::FORMAT_ARRAY, $s1)), 2); $this->assertEquals(count($model->getRows($s1)), 2); }
public function testUnion() { $model = new Kwf_Model_FnF(); $model->setData(array(array('id' => 1, 'value' => 'foo'), array('id' => 2, 'value' => 'bar'))); $s1 = new Kwf_Model_Select(); $s1->whereEquals('id', 1); $s2 = new Kwf_Model_Select(); $s2->whereEquals('id', 2); $s1->union($s2); $this->assertEquals($model->countRows($s1), 2); $this->assertEquals(count($model->getRows($s1)), 2); $this->assertEquals(count($model->export(Kwf_Model_Interface::FORMAT_ARRAY, $s1)), 2); }
protected function _buildSelectForDelete($updates) { $or = array(); foreach ($updates as $key => $values) { if ($key === 'component_id') { $or[] = new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('component_id', array_unique($values)), new Kwf_Model_Select_Expr_Equal('type', 'component'))); } else { if ($key === 'master-component_id') { $or[] = new Kwf_Model_Select_Expr_And(array(new Kwf_Model_Select_Expr_Equal('component_id', array_unique($values)), new Kwf_Model_Select_Expr_Equal('type', 'master'))); } else { $and = array(); foreach ($values as $k => $v) { if (!is_array($v)) { $v = array($v); } $ors = array(); foreach ($v as $value) { if (substr($value, -1) == '%') { $value = substr($value, 0, -1); $ors[] = new Kwf_Model_Select_Expr_Equal($k, $value); $ors[] = new Kwf_Model_Select_Expr_Like($k, $value . '-%'); $ors[] = new Kwf_Model_Select_Expr_Like($k, $value . '_%'); } else { if (strpos($value, '%') !== false) { $ors[] = new Kwf_Model_Select_Expr_Like($k, $value . '_%'); } else { $ors[] = new Kwf_Model_Select_Expr_Equal($k, $value); } } } $and[] = new Kwf_Model_Select_Expr_Or($ors); } if ($and) { $and = new Kwf_Model_Select_Expr_And($and); if (!in_array($and, $or)) { $or[] = $and; } } } } } $select = new Kwf_Model_Select(); if ($or) { $select->where($or[0]); unset($or[0]); foreach ($or as $i) { $s = new Kwf_Model_Select(); $s->where($i); $select->union($s); } } $select->whereEquals('deleted', false); return $select; }