protected function _getSelect(ParamFetcher $paramFetcher, Request $request)
 {
     $select = new \Kwf_Model_Select();
     $select->limit($paramFetcher->get('limit'), $paramFetcher->get('start'));
     $queryValue = trim($request->get('query'));
     if ($queryValue) {
         $exprs = array();
         if (!$this->_queryColumns) {
             throw new \Kwf_Exception("_queryColumns are required to be set");
         }
         if ($this->_querySplit) {
             $queryValue = explode(' ', $queryValue);
         } else {
             $queryValue = array($queryValue);
         }
         foreach ($queryValue as $q) {
             $e = array();
             foreach ($this->_queryColumns as $c) {
                 $e[] = new \Kwf_Model_Select_Expr_Like($c, '%' . $q . '%');
             }
             if (count($e) > 1) {
                 $exprs[] = new \Kwf_Model_Select_Expr_Or($e);
             } else {
                 $exprs[] = $e[0];
             }
         }
         if (count($exprs) > 1) {
             $select->where(new \Kwf_Model_Select_Expr_And($exprs));
         } else {
             $select->where($exprs[0]);
         }
     }
     return $select;
 }
 public function update()
 {
     parent::update();
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equals('dimension', 'customcrop'), new Kwf_Model_Select_Expr_Equals('dimension', 'custombestfit'))));
     $select->order('dimension', 'asc');
     $rows = Kwf_Model_Abstract::getInstance('Kwc_Abstract_Image_Model')->getRows($select);
     foreach ($rows as $row) {
         if ($row->dimension == 'customcrop') {
             $row->dimension = 'custom';
             $row->crop_x = null;
             $row->crop_y = null;
             $row->crop_width = null;
             $row->crop_heigth = null;
         } else {
             if ($row->dimension == 'custombestfit') {
                 $row->dimension = 'custom';
                 if ($row->imageExists()) {
                     $targetSize = array('width' => $row->width, 'height' => $row->height, 'cover' => false);
                     $outputSize = Kwf_Media_Image::calculateScaleDimensions($row->getParentRow('Image')->getFileSource(), $targetSize);
                     $row->width = $outputSize['width'];
                     $row->height = $outputSize['height'];
                     $row->crop_x = $outputSize['crop']['x'];
                     $row->crop_y = $outputSize['crop']['y'];
                     $row->crop_width = $outputSize['crop']['width'];
                     $row->crop_height = $outputSize['crop']['height'];
                 }
             }
         }
         $row->save();
     }
 }
Пример #3
0
 public function processInput(array $postData)
 {
     parent::processInput($postData);
     $this->_accessByMailRow = false;
     if (isset($postData['key'])) {
         $s = new Kwf_Model_Select();
         $s->whereEquals('key', $postData['key']);
         $s->where(new Kwf_Model_Select_Expr_Higher('date', new Kwf_Date(time() - 24 * 60 * 60)));
         $this->_accessByMailRow = Kwf_Model_Abstract::getInstance('Kwf_Component_Plugin_AccessByMail_Model')->getRow($s);
         if (!$this->_accessByMailRow) {
             $this->_errors[] = array('message' => trlKwf("Invalid or expired Link. Please request a new one."));
         } else {
             $session = new Kwf_Session_Namespace('kwc_' . $this->getData()->parent->componentId);
             $session->login = true;
             $session->key = $postData['key'];
         }
     } else {
         $session = new Kwf_Session_Namespace('kwc_' . $this->getData()->parent->componentId);
         if ($session->login) {
             $s = new Kwf_Model_Select();
             $s->whereEquals('key', $session->key);
             $this->_accessByMailRow = Kwf_Model_Abstract::getInstance('Kwf_Component_Plugin_AccessByMail_Model')->getRow($s);
         }
     }
 }
Пример #4
0
 public function buildSelect(Request $request, array $options = array())
 {
     $select = new \Kwf_Model_Select();
     if ($request->get('limit')) {
         $select->limit($request->get('limit'), $request->get('start'));
     } else {
         $select->limit(25, $request->get('start'));
     }
     $queryValue = trim($request->get('query'));
     if ($queryValue) {
         $queryColumns = null;
         if (isset($options['queryColumns'])) {
             $queryColumns = $options['queryColumns'];
         }
         $exprs = array();
         if (!$queryColumns) {
             throw new \Kwf_Exception("queryColumns are required to be set");
         }
         if (isset($options['querySplit']) && $options['querySplit']) {
             $queryValue = explode(' ', $queryValue);
         } else {
             $queryValue = array($queryValue);
         }
         foreach ($queryValue as $q) {
             $e = array();
             foreach ($queryColumns as $c) {
                 $e[] = new \Kwf_Model_Select_Expr_Like($c, '%' . $q . '%');
             }
             if (count($e) > 1) {
                 $exprs[] = new \Kwf_Model_Select_Expr_Or($e);
             } else {
                 $exprs[] = $e[0];
             }
         }
         if (count($exprs) > 1) {
             $select->where(new \Kwf_Model_Select_Expr_And($exprs));
         } else {
             $select->where($exprs[0]);
         }
     }
     $restColumns = $this->model->getSerializationColumns(array('rest_read', 'rest'));
     $exprColumns = $this->model->getExprColumns();
     foreach (array_intersect(array_keys($restColumns), $exprColumns) as $i) {
         $select->expr($i);
     }
     return $select;
 }
Пример #5
0
 public function getAuthedUser()
 {
     //return first user
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Equal('id', $this->_authedUserId));
     $row = $this->getRow($select);
     return $row;
 }
Пример #6
0
 public function testUpdateRowsIgnoreDeleted()
 {
     $model = $this->_m;
     $model->getRow(1)->delete();
     $s = new Kwf_Model_Select(array('ignoreDeleted' => true));
     $s->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equals('id', 1), new Kwf_Model_Select_Expr_Equals('id', 2))));
     $model->updateRows(array('foo' => 'newBar'), $s);
     $this->assertEquals('newBar', $model->getRow(2)->foo);
 }
Пример #7
0
 private function _fetchRedirectUrl($type, $source, $host)
 {
     $s = new Kwf_Model_Select();
     $s->whereEquals('type', $type);
     $source = rtrim($source, '/');
     if ($type == 'domain' || $type == 'domainPath') {
         $sourceWithoutWww = preg_replace('#^www\\.#', '', $source);
         $sources = array($source, 'http://' . $source, $source . '/', 'http://' . $source . '/', $sourceWithoutWww, 'http://' . $sourceWithoutWww, $sourceWithoutWww . '/', 'http://' . $sourceWithoutWww . '/');
         $s->whereEquals('source', $sources);
     } else {
         if (substr($source, 0, 6) == '/media') {
             $parts = explode('/', $source);
             if (isset($parts[6])) {
                 $source = str_replace($parts[6], '%', $source);
             }
             $s->where(new Kwf_Model_Select_Expr_Like('source', $source));
         } else {
             $sources = array($source, $source . '/');
             $s->whereEquals('source', $sources);
         }
     }
     $s->whereEquals('active', true);
     if ($type == 'path') {
         if ($root = Kwf_Component_Data_Root::getInstance()) {
             $domainComponents = $root->getDomainComponents(array('ignoreVisible' => true));
             if (count($domainComponents) > 1) {
                 $path = $root->getComponent()->formatPath(array('host' => $host, 'path' => ''));
                 if (!is_null($path)) {
                     $path = trim($path, '/');
                     $component = $root->getComponent()->getPageByUrl($path, null);
                     if ($component) {
                         $s->whereEquals('domain_component_id', $component->getDomainComponent()->dbId);
                     } else {
                         return null;
                     }
                 } else {
                     return null;
                 }
             }
         }
     }
     $row = $this->getRow($s);
     $target = null;
     if ($row) {
         if ($row->target_type == 'extern') {
             $target = $row->target;
         } else {
             if ($row->target_type == 'intern' || $row->target_type == 'downloadTag') {
                 $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($row->target);
                 if ($c) {
                     $target = $c->getAbsoluteUrl();
                 }
             }
         }
     }
     return $target;
 }
Пример #8
0
 public function testChildContains2()
 {
     $model = Kwf_Model_Abstract::getInstance('Kwf_Model_Union_Dependent_Parent');
     $childSelect = new Kwf_Model_Select();
     $childSelect->whereEquals('foo', 'xx');
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Child_Contains('TestModel', $childSelect));
     $this->assertEquals(2, count($model->getRows($select)));
     $this->assertEquals(2, $model->countRows($select));
 }
Пример #9
0
 public function testChildReference()
 {
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Parent('Parent', new Kwf_Model_Select_Expr_Equal('foo', 5)));
     $rows = $this->_modelChild->getRows($select);
     $this->assertEquals(count($rows), 3);
     foreach ($rows as $row) {
         $this->assertEquals($row->getParentRow('Parent')->foo, 5);
     }
 }
Пример #10
0
 public function testChildContains()
 {
     $select = new Kwf_Model_Select();
     $childSelect = new Kwf_Model_Select();
     $childSelect->whereEquals('bar', 5);
     $s = new Kwf_Model_Select();
     $s->where(new Kwf_Model_Select_Expr_Child_Contains('Reference1', $childSelect));
     $foo = $this->_modelFoo->getRow($s);
     $this->assertEquals('5', $foo->foo);
 }
Пример #11
0
 public function testToArrayFromArray()
 {
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equals('foo', 'bar'), new Kwf_Model_Select_Expr_Not(new Kwf_Model_Select_Expr_Equals('baz', 'buz')))));
     $select->whereEquals('blub', 123);
     $ar = $select->toArray();
     $this->assertEquals(is_array($ar), true);
     $select2 = Kwf_Model_Select::fromArray($ar);
     $this->assertEquals($select, $select2);
 }
 protected function _initFields()
 {
     $fs = $this->_form;
     $sel = new Kwf_Model_Select();
     $sel->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal('id', 1), new Kwf_Model_Select_Expr_Equal('id', 2))));
     $fs->add(new Kwf_Form_Field_MultiCheckbox('Relation', 'Value', 'Relations only'))->setValuesSelect($sel);
     $sel = new Kwf_Model_Select();
     $sel->whereEquals('id', 3);
     $fs->add(new Kwf_Form_Field_MultiCheckbox(Kwf_Model_Abstract::getInstance('Kwf_Form_MultiCheckbox_RelationModel'), 'Value', 'Model and relation'))->setValuesSelect($sel);
     $fs->add(new Kwf_Form_Field_MultiCheckbox(Kwf_Model_Abstract::getInstance('Kwf_Form_MultiCheckbox_RelationModelNoRel'), 'Value', 'Model and relation (no dataToRelation)'));
     $fs->add(new Kwf_Form_Field_MultiCheckbox('Relation', 'Value', 'setShowCheckAllLinks(false)'))->setShowCheckAllLinks(false);
 }
Пример #13
0
 public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event)
 {
     if (count($this->_orExpr->getExpressions())) {
         $select = new Kwf_Model_Select();
         $select->where($this->_orExpr);
         $rows = Kwf_Component_Cache::getInstance()->getModel('url')->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select);
         foreach ($rows as $row) {
             $cacheId = 'url-' . $row['url'];
             Kwf_Cache_Simple::delete($cacheId);
         }
     }
 }
Пример #14
0
 public function jsonClearViewCacheAction()
 {
     $select = new Kwf_Model_Select();
     if ($this->_getParam('dbId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('db_id', $this->_getParam('dbId')));
     }
     if ($this->_getParam('id')) {
         $select->where(new Kwf_Model_Select_Expr_Like('component_id', $this->_getParam('id')));
     }
     if ($this->_getParam('expandedId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $this->_getParam('expandedId')));
     }
     if ($this->_getParam('class')) {
         $c = $this->_getParam('class');
         if (strpos($c, '%') === false) {
             $whereClass = array($c);
             foreach (Kwc_Abstract::getComponentClasses() as $cls) {
                 if (in_array($c, Kwc_Abstract::getSetting($cls, 'parentClasses'))) {
                     $whereClass[] = $cls;
                 }
             }
             $select->whereEquals('component_class', $whereClass);
         } else {
             $select->where(new Kwf_Model_Select_Expr_Like('component_class', $this->_getParam('class')));
         }
     }
     if ($this->_getParam('type')) {
         $select->where(new Kwf_Model_Select_Expr_Like('type', $this->_getParam('type')));
     }
     $select->whereEquals('deleted', false);
     $model = Kwf_Component_Cache::getInstance()->getModel();
     $this->view->entries = $model->countRows($select);
     if (!$this->view->entries) {
         throw new Kwf_Exception_Client("No active view cache entries found; nothing to do.");
     }
     if ($this->_getParam('force')) {
         Kwf_Component_Cache::getInstance()->deleteViewCache($select);
     }
 }
Пример #15
0
 public function onStylesRowUpdate(Kwf_Events_Event_Row_Updated $e)
 {
     $s = new Kwf_Model_Select();
     $s->whereEquals('uses_styles', true);
     $s->where(new Kwf_Model_Select_Expr_Like('content', '%class="style' . $e->row->id . '"%'));
     $rows = Kwc_Basic_Text_Component::createOwnModel($this->_class)->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('component_id')));
     foreach ($rows as $row) {
         foreach (Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($row['component_id']) as $c) {
             if ($c->componentClass == $this->_class) {
                 $this->fireEvent(new Kwf_Component_Event_Component_ContentChanged($this->_class, $c));
             }
         }
     }
 }
Пример #16
0
 protected function _getSelect()
 {
     $ret = parent::_getSelect();
     $users = Kwf_Registry::get('userModel');
     $employeesModel = Kwf_Model_Abstract::getInstance('Employees');
     $employeesSelect = $employeesModel->select()->whereEquals('userId', $users->getAuthedUserId());
     $employee = $employeesModel->getRow($employeesSelect);
     $employeeId = -1;
     if ($employee != NULL) {
         $employeeId = $employee->id;
     }
     $s = new Kwf_Model_Select();
     $s->where(new Kwf_Model_Select_Expr_Sql("employeeId = " . $employeeId . " AND Hidden = 0"));
     $ret->where(new Kwf_Model_Select_Expr_Child_Contains('Flightgroups', $s))->order('flightStartTime');
     return $ret;
 }
Пример #17
0
 protected function _subscriptionExists(Kwc_Newsletter_Subscribe_Row $row)
 {
     if ($row->id) {
         throw new Kwf_Exception("you can only insert unsaved rows");
     }
     $s = new Kwf_Model_Select();
     $s->whereEquals('email', $row->email);
     //what if the email field is not named email?
     $s->whereEquals('newsletter_component_id', $this->getSubscribeToNewsletterComponent()->dbId);
     $s->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal('unsubscribed', 1), new Kwf_Model_Select_Expr_Equal('activated', 1))));
     if ($row->getModel()->countRows($s)) {
         //already subscribed, don't save
         return true;
     }
     return false;
 }
Пример #18
0
 protected function _getSelect()
 {
     $ret = parent::_getSelect();
     $users = Kwf_Registry::get('userModel');
     $employeesModel = Kwf_Model_Abstract::getInstance('Employees');
     $employeesSelect = $employeesModel->select()->whereEquals('userId', $users->getAuthedUserId());
     $employee = $employeesModel->getRow($employeesSelect);
     $employeeId = -1;
     if ($employee != NULL) {
         $employeeId = $employee->id;
     }
     $s = new Kwf_Model_Select();
     $s->where(new Kwf_Model_Select_Expr_Sql("employeeId = " . $employeeId . " AND currentScore = 0 "));
     $ret->where(new Kwf_Model_Select_Expr_Child_Contains('TrainingResults', $s))->where(new Kwf_Model_Select_Expr_Sql("startDate <= NOW() and endDate >= NOW()"));
     return $ret;
 }
Пример #19
0
 public function testParentOrExpr()
 {
     $select = new Kwf_Model_Select();
     $parentExpr = new Kwf_Model_Select_Expr_Parent('Parent', new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Higher('foo', 5), new Kwf_Model_Select_Expr_Lower('foo', 2))));
     $select->where($parentExpr);
     $rows = $this->_modelChild->getRows($select);
     foreach ($rows as $row) {
         $parent = $row->getParentRow('Parent');
         $this->assertTrue($parent->foo > 5 || $parent->foo < 2);
     }
     $rows = $this->_modelChild->getRows();
     foreach ($rows as $row) {
         $parent = $row->getParentRow('Parent');
         $value = $parent->foo > 5 || $parent->foo < 2;
         $exprValue = $this->_modelChild->getExprValue($row, $parentExpr);
         $this->assertTrue($value == $exprValue);
     }
 }
 public function update()
 {
     $model = Kwf_Model_Abstract::getInstance('Kwf_Component_FieldModel');
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Like('data', '%variant%'));
     $variants = array();
     foreach ($model->getRows($select) as $row) {
         $component = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($row->component_id, array('ignoreVisible' => true, 'limit' => 1));
         if ($component && is_instance_of($component->componentClass, 'Kwc_List_Gallery_Component')) {
             $cRow = $component->getComponent()->getRow();
             $cRow->columns = substr($row->variant, 0, 1);
             if (!in_array($cRow->variant, $variants)) {
                 echo "{$cRow->variant} -> {$cRow->columns}\n";
                 $variants[] = $cRow->variant;
             }
             $cRow->save();
         }
     }
 }
 public function indexAction()
 {
     $model = Kwf_Component_Cache_Mysql::getInstance()->getModel();
     $includesModel = Kwf_Component_Cache_Mysql::getInstance()->getModel('includes');
     $s = new Kwf_Model_Select();
     $s->whereEquals('deleted', true);
     $s->where(new Kwf_Model_Select_Expr_Lower('microtime', (time() - 3 * 24 * 60 * 60) * 1000));
     $options = array('columns' => array('component_id'));
     if ($this->_getParam('debug')) {
         echo "querying for garbage in cache_component...\n";
     }
     foreach ($model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, $options) as $row) {
         if ($this->_getParam('debug')) {
             echo "deleting " . $row['component_id'] . "\n";
         }
         $s = new Kwf_Model_Select();
         $s->whereEquals('component_id', $row['component_id']);
         $model->deleteRows($s);
         $includesModel->deleteRows($s);
     }
     exit;
 }
Пример #22
0
 public function insertSubscriptionWithCategory(Kwc_Newsletter_Subscribe_Row $row, $categoryId)
 {
     $exists = $this->_subscriptionExists($row);
     $nl2cat = Kwf_Model_Abstract::getInstance('Kwc_NewsletterCategory_Subscribe_SubscriberToCategory');
     if ($exists) {
         //already subscribed
         $s = new Kwf_Model_Select();
         $s->whereEquals('email', $row->email);
         $s->whereEquals('newsletter_component_id', $this->getSubscribeToNewsletterComponent()->dbId);
         $s->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal('unsubscribed', 1), new Kwf_Model_Select_Expr_Equal('activated', 1))));
         $row = $this->getForm()->getModel()->getRow($s);
         $s = $nl2cat->select()->whereEquals('subscriber_id', $row->id)->whereEquals('category_id', $categoryId);
         if ($nl2cat->countRows($s)) {
             //already subscribed to given category
             return false;
         }
     }
     if (!$exists) {
         $s = new Kwf_Model_Select();
         $s->whereEquals('email', $row->email);
         $s->whereEquals('newsletter_component_id', $this->getSubscribeToNewsletterComponent()->dbId);
         $s->where(new Kwf_Model_Select_Expr_Or(array(new Kwf_Model_Select_Expr_Equal('unsubscribed', 1), new Kwf_Model_Select_Expr_Equal('activated', 0))));
         $deleteRow = $this->getForm()->getModel()->getRow($s);
         if ($deleteRow) {
             $deleteRow->delete();
         }
         $this->_beforeInsert($row);
         $row->save();
     }
     $nl2CatRow = $nl2cat->createRow();
     $nl2CatRow->subscriber_id = $row->id;
     $nl2CatRow->category_id = $categoryId;
     $nl2CatRow->save();
     if (!$exists) {
         $this->_afterInsert($row);
     }
     return true;
 }
Пример #23
0
 public function onComponentAdd(Kwf_Component_Event_Component_Added $event)
 {
     $componentId = $event->component->componentId;
     $model = Kwf_Model_Abstract::getInstance(Kwc_Abstract::getSetting($this->_class, 'favouritesModel'));
     $select = new Kwf_Model_Select();
     $select->where(new Kwf_Model_Select_Expr_Equal('component_id', $componentId));
     $options = array('columns' => array('user_id'));
     $userIds = $model->export(Kwf_Model_Abstract::FORMAT_ARRAY, $select, $options);
     if ($userIds) {
         foreach ($userIds as $userId) {
             $componentIds = Kwf_Cache_Simple::fetch('favCIds' . $userId['user_id'], $success);
             if ($success) {
                 Kwf_Cache_Simple::delete('favCIds' . $userId['user_id']);
                 $componentIds[] = $componentId;
                 Kwf_Cache_Simple::add('favCIds' . $userId['user_id'], $componentIds);
                 $log = Kwf_Events_Log::getInstance();
                 if ($log) {
                     $log->log("favourites cache clear {$componentId}", Zend_Log::INFO);
                 }
             }
         }
     }
 }
Пример #24
0
 protected function _getPageIds($parentData, $select)
 {
     if (!$parentData && ($p = $select->getPart(Kwf_Component_Select::WHERE_CHILD_OF))) {
         if ($p->getPage()) {
             $p = $p->getPage();
         }
         $parentData = $p;
     }
     $pageIds = array();
     if ($parentData && !$select->hasPart(Kwf_Component_Select::WHERE_ID)) {
         // diese Abfragen sind implizit recursive=true
         $parentId = $parentData->dbId;
         if ($select->getPart(Kwf_Component_Select::WHERE_HOME)) {
             $s = new Kwf_Model_Select();
             $s->whereEquals('is_home', true);
             $s->whereEquals('parent_subroot_id', $parentData->getSubroot()->dbId);
             //performance to look only in subroot - correct filterting done below
             Kwf_Benchmark::count('GenPage::query', 'home');
             $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('id')));
             $homePages = array();
             foreach ($rows as $row) {
                 $homePages[] = $row['id'];
             }
             foreach ($homePages as $pageId) {
                 $pd = $this->_getPageData($pageId);
                 if (substr($pd['parent_id'], 0, strlen($parentId)) == $parentId) {
                     $pageIds[] = $pageId;
                     continue;
                 }
                 foreach ($pd['parent_ids'] as $pageParentId) {
                     if ($pageParentId == $parentId) {
                         $pageIds[] = $pageId;
                         break;
                     }
                 }
             }
         } else {
             if ($select->hasPart(Kwf_Component_Select::WHERE_FILENAME)) {
                 $filename = $select->getPart(Kwf_Component_Select::WHERE_FILENAME);
                 $cacheId = 'pcFnIds-' . $parentId . '-' . $filename;
                 $pageIds = Kwf_Cache_Simple::fetch($cacheId);
                 if ($pageIds === false) {
                     $s = new Kwf_Model_Select();
                     $s->whereEquals('filename', $filename);
                     if (is_numeric($parentId)) {
                         $s->whereEquals('parent_id', $parentId);
                     } else {
                         $s->where(new Kwf_Model_Select_Expr_Like('parent_id', $parentId . '%'));
                     }
                     Kwf_Benchmark::count('GenPage::query', 'filename');
                     $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('id')));
                     $pageIds = array();
                     foreach ($rows as $row) {
                         $pageIds[] = $row['id'];
                     }
                     Kwf_Cache_Simple::add($cacheId, $pageIds);
                 }
             } else {
                 if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
                     $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
                     $keys = array();
                     foreach ($selectClasses as $selectClass) {
                         $key = array_search($selectClass, $this->_settings['component']);
                         if ($key) {
                             $keys[] = $key;
                         }
                     }
                     $s = new Kwf_Model_Select();
                     $s->whereEquals('component', array_unique($keys));
                     if (is_numeric($parentId)) {
                         $s->whereEquals('parent_id', $parentId);
                     } else {
                         $s->where(new Kwf_Model_Select_Expr_Like('parent_id', $parentId . '%'));
                     }
                     Kwf_Benchmark::count('GenPage::query', 'component');
                     $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $s, array('columns' => array('id')));
                     foreach ($rows as $row) {
                         $pageIds[] = $row['id'];
                     }
                 } else {
                     $pageIds = $this->_getChildPageIds($parentId);
                 }
             }
         }
     } else {
         $pagesSelect = new Kwf_Model_Select();
         if ($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) {
             //query only by id, no db query required
             $pageIds = array($id);
             if ($sr = $select->getPart(Kwf_Component_Select::WHERE_SUBROOT)) {
                 $pd = $this->_getPageData($id);
                 if ($pd['parent_subroot_id'] != $sr[0]->dbId) {
                     $pageIds = array();
                 }
             }
             if ($pageIds && $select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
                 $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
                 $keys = array();
                 foreach ($selectClasses as $selectClass) {
                     $key = array_search($selectClass, $this->_settings['component']);
                     if ($key && !in_array($key, $keys)) {
                         $keys[] = $key;
                     }
                 }
                 $pd = $this->_getPageData($id);
                 if (!in_array($pd['component'], $keys)) {
                     $pageIds = array();
                 }
             }
             if ($pageIds && $select->getPart(Kwf_Component_Select::WHERE_HOME)) {
                 $pd = $this->_getPageData($id);
                 if (!$pd['is_home']) {
                     $pageIds = array();
                 }
             }
         } else {
             $benchmarkType = '';
             if ($select->hasPart(Kwf_Component_Select::WHERE_SUBROOT)) {
                 $subroot = $select->getPart(Kwf_Component_Select::WHERE_SUBROOT);
                 $subroot = $subroot[0];
                 $pagesSelect->whereEquals('parent_subroot_id', $subroot->dbId);
                 $benchmarkType .= 'subroot ';
             }
             if ($select->getPart(Kwf_Component_Select::WHERE_HOME)) {
                 $pagesSelect->whereEquals('is_home', true);
                 $benchmarkType .= 'home ';
             }
             if ($id = $select->getPart(Kwf_Component_Select::WHERE_ID)) {
                 $pagesSelect->whereEquals('id', $id);
                 $benchmarkType .= 'id ';
             }
             if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
                 $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
                 $keys = array();
                 foreach ($selectClasses as $selectClass) {
                     $key = array_search($selectClass, $this->_settings['component']);
                     if ($key && !in_array($key, $keys)) {
                         $keys[] = $key;
                     }
                 }
                 $pagesSelect->whereEquals('component', $keys);
                 $benchmarkType .= 'component ';
             }
             Kwf_Benchmark::count('GenPage::query', "noparent(" . trim($benchmarkType) . ")");
             $rows = $this->_getModel()->export(Kwf_Model_Interface::FORMAT_ARRAY, $pagesSelect, array('columns' => array('id')));
             $pageIds = array();
             foreach ($rows as $row) {
                 $pageIds[] = $row['id'];
             }
         }
         if ($parentData) {
             $parentId = $parentData->dbId;
             foreach ($pageIds as $k => $pageId) {
                 $match = false;
                 $pd = $this->_getPageData($pageId);
                 if (!$pd) {
                     continue;
                 }
                 if (substr($pd['parent_id'], 0, strlen($parentId)) == $parentId) {
                     $match = true;
                 }
                 if (!$match) {
                     foreach ($pd['parent_ids'] as $pageParentId) {
                         if ($pageParentId == $parentId) {
                             $match = true;
                             break;
                         }
                     }
                 }
                 if (!$match) {
                     unset($pageIds[$k]);
                 }
             }
         }
     }
     return $pageIds;
 }
Пример #25
0
 private function _convertSelectForSibling($select, $m)
 {
     $s = new Kwf_Model_Select();
     if ($p = $select->getPart(Kwf_Model_Select::WHERE_EQUALS)) {
         foreach ($p as $f => $v) {
             if (!in_array($f, $this->_getOwnColumns()) && $m->hasColumn($f)) {
                 $s->whereEquals($f, $v);
             }
         }
     }
     if ($p = $select->getPart(Kwf_Model_Select::WHERE_NOT_EQUALS)) {
         foreach ($p as $f => $v) {
             if (!in_array($f, $this->_getOwnColumns()) && $m->hasColumn($f)) {
                 $s->whereNotEquals($f, $v);
             }
         }
     }
     if ($p = $select->getPart(Kwf_Model_Select::WHERE_NULL)) {
         foreach ($p as $f) {
             if (!in_array($f, $this->_getOwnColumns()) && $m->hasColumn($f)) {
                 $s->whereNull($f);
             }
         }
     }
     if ($p = $select->getPart(Kwf_Model_Select::WHERE_EXPRESSION)) {
         foreach ($p as $expr) {
             $e = $this->_convertExprForSibling($expr, $m);
             if ($e) {
                 $s->where($e);
             }
         }
     }
     return $s;
 }
Пример #26
0
 public function getChildData($parentData, $select = array())
 {
     Kwf_Benchmark::count('GenStaticSelect::getChildData');
     if (is_array($select)) {
         $select = new Kwf_Component_Select($select);
     }
     if ($select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
         $continue = false;
         foreach ($select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES) as $componentClass) {
             if (in_array($componentClass, $this->getChildComponentClasses())) {
                 $continue = true;
             }
         }
         if (!$continue) {
             return array();
         }
     }
     if (!$parentData) {
         if (!$select->hasPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES)) {
             throw new Kwf_Exception_NotYetImplemented();
         }
         $selectClasses = $select->getPart(Kwf_Component_Select::WHERE_COMPONENT_CLASSES);
         $possibleClasses = $this->getChildComponentClasses();
         if (in_array(array_shift($possibleClasses), $selectClasses)) {
             throw new Kwf_Exception("You can't search for component which is first (=default) in StaticSelect");
         }
         $searchFor = array();
         foreach ($selectClasses as $c) {
             $searchFor[] = array_search($c, $possibleClasses);
         }
         $s = new Kwf_Model_Select();
         $s->whereEquals('component', $searchFor);
         $s->where(new Kwf_Model_Select_Expr_Like('component_id', '%-' . $this->getGeneratorKey()));
         $rows = $this->_getModel()->export(Kwf_Model_Abstract::FORMAT_ARRAY, $s, array('columns' => array('component_id')));
         $parentDatas = array();
         foreach ($rows as $row) {
             $id = substr($row['component_id'], 0, -(strlen($this->getGeneratorKey()) + 1));
             $s = new Kwf_Component_Select();
             $s->copyParts(array(Kwf_Component_Select::IGNORE_VISIBLE, Kwf_Component_Select::WHERE_SUBROOT), $select);
             $d = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($id, $s);
             if ($d) {
                 $parentDatas[] = $d;
             }
         }
     } else {
         $parentDatas = array($parentData);
     }
     $ret = array();
     foreach ($parentDatas as $parentData) {
         $data = $this->_createData($parentData, $this->getGeneratorKey(), $select);
         if (!$data) {
             continue;
         }
         if ($select->hasPart('whereId')) {
             if ('-' . $data->id != $select->getPart('whereId')) {
                 continue;
             }
         }
         $ret[] = $data;
     }
     return $ret;
 }
 public function indexAction()
 {
     Kwf_Util_MemoryLimit::set(512);
     $select = new Kwf_Model_Select();
     if ($this->_getParam('all')) {
     }
     if ($this->_getParam('dbId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('db_id', $this->_getParam('dbId')));
     }
     if ($this->_getParam('id')) {
         $select->where(new Kwf_Model_Select_Expr_Like('component_id', $this->_getParam('id')));
     }
     if ($this->_getParam('expandedId')) {
         $select->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $this->_getParam('expandedId')));
     }
     if ($this->_getParam('type')) {
         $select->where(new Kwf_Model_Select_Expr_Like('type', $this->_getParam('type')));
     }
     if ($this->_getParam('class')) {
         $c = $this->_getParam('class');
         if (strpos($c, '%') === false) {
             $whereClass = array($c);
             foreach (Kwc_Abstract::getComponentClasses() as $cls) {
                 if (in_array($c, Kwc_Abstract::getSetting($cls, 'parentClasses'))) {
                     $whereClass[] = $cls;
                 }
             }
             $select->whereEquals('component_class', $whereClass);
         } else {
             $select->where(new Kwf_Model_Select_Expr_Like('component_class', $this->_getParam('class')));
         }
     }
     if (!$this->_getParam('all') && !$this->_getParam('dbId') && !$this->_getParam('id') && !$this->_getParam('expandedId') && !$this->_getParam('type') && !$this->_getParam('class')) {
         throw new Kwf_Exception_Client("required parameter: --all, --id, --dbId, --expandedId, --type or --class");
     }
     $select->whereEquals('deleted', false);
     $model = Kwf_Component_Cache::getInstance()->getModel();
     $entries = $model->countRows($select);
     if (!$entries) {
         echo "No active view cache entries found; nothing to do.\n";
         exit;
     }
     if (!$this->_getParam('force')) {
         echo "Will delete {$entries} view cache entries. Continue? [Y/n]\n";
         $stdin = fopen('php://stdin', 'r');
         $input = trim(strtolower(fgets($stdin, 2)));
         fclose($stdin);
         if (!($input == '' || $input == 'j' || $input == 'y')) {
             exit(1);
         }
     }
     echo "Deleting view cache...\n";
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     Kwf_Component_Cache::getInstance()->deleteViewCache($select, $c);
     echo "done\n";
     if ($this->_getParam('clear')) {
         echo "Clearing table...";
         $model->deleteRows($select);
         echo "done\n";
     }
     exit;
 }
Пример #28
0
 public function deleteRecursive()
 {
     if (is_numeric($this->page_id)) {
         $page = Kwf_Component_Data_Root::getInstance()->getComponentById($this->page_id, array('ignoreVisible' => true));
         $pages = $page->getChildPages(array('pageGenerator' => true));
         foreach ($pages as $p) {
             $row = $this->getModel()->getRow($p->componentId);
             if ($row) {
                 $row->deleteRecursive();
             }
         }
     }
     $deleteSelect = new Kwf_Model_Select();
     $deleteSelect->where(new Kwf_Model_Select_Expr_Like('expanded_component_id', $this->page_id . '%'));
     $this->getModel()->updateRows(array('deleted' => true), $deleteSelect);
 }
Пример #29
0
 public function createHashes()
 {
     $db = Kwf_Registry::get('db');
     $s = new Kwf_Model_Select();
     $s->where("md5_hash = ''");
     $it = new Kwf_Model_Iterator_Packages(new Kwf_Model_Iterator_Rows(Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model'), $s));
     foreach ($it as $row) {
         $this->_progressBar->next(1, 'calculating md5 ' . $row->id);
         if (file_exists($row->getFileSource())) {
             $md5Hash = md5_file($row->getFileSource());
             $db->query("UPDATE `kwf_uploads` SET  `md5_hash` =  '{$md5Hash}' WHERE  `id` = '{$row->id}';");
         }
     }
 }
Пример #30
0
 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();
 }