public function addCategory($parentCategoryId = null, $categoryId, $siteId = 1) { $where = new \Zend\Db\Sql\Where(); $where->equalTo('website_id', $siteId)->equalTo('category_id', $categoryId); if (null === $parentCategoryId) { $where->isNull('parent_category_id'); } else { $where->equalTo('parent_category_id', $parentCategoryId); } $table = 'catalog_category_website'; $row = array('category_id' => $categoryId, 'parent_category_id' => $parentCategoryId, 'website_id' => $siteId); $select = $this->getSelect($table)->where($where); $result = $this->selectOne($select); if (false === $result) { $this->insert($row, $table); } }
/** * Update package assignments * * Sets a new package on existing assignments. Updated assignments have * their status reset to "not notified" and their options (force, schedule, * post cmd) removed. * * @param integer $oldPackageId package to be replaced * @param integer $newPackageId new package * @param bool $deployNonnotified Update assignments with status 'not notified' * @param bool $deploySuccess Update assignments with status 'success' * @param bool $deployNotified Update assignments with status 'notified' * @param bool $deployError Update assignments with status 'error' * @param bool $deployGroups Update assignments for groups * @throws RuntimeException if an error occurs */ public function updateAssignments($oldPackageId, $newPackageId, $deployNonnotified, $deploySuccess, $deployNotified, $deployError, $deployGroups) { if (!($deployNonnotified or $deploySuccess or $deployNotified or $deployError or $deployGroups)) { return; // nothing to do } $clientConfig = $this->_serviceManager->get('Database\\Table\\ClientConfig'); $groupInfo = $this->_serviceManager->get('Database\\Table\\GroupInfo'); $where = new \Zend\Db\Sql\Where(); $where->equalTo('ivalue', $oldPackageId); // Additional filters are only necessary if not all conditions are set if (!($deployNonnotified and $deploySuccess and $deployNotified and $deployError and $deployGroups)) { $groups = $groupInfo->getSql()->select()->columns(array('hardware_id')); $filters = new \Zend\Db\Sql\Where(null, \Zend\Db\Sql\Where::COMBINED_BY_OR); if ($deployNonnotified) { $filters->isNull('tvalue')->and->notIn('hardware_id', $groups); } if ($deploySuccess) { $filters->equalTo('tvalue', \Model\Package\Assignment::SUCCESS); } if ($deployNotified) { $filters->equalTo('tvalue', \Model\Package\Assignment::NOTIFIED); } if ($deployError) { $filters->like('tvalue', \Model\Package\Assignment::ERROR_PREFIX . '%'); } if ($deployGroups) { $filters->in('hardware_id', $groups); } $where->addPredicate($filters); } $now = $this->_serviceManager->get('Library\\Now')->format(\Model\Package\Assignment::DATEFORMAT); try { // Remove DOWNLOAD_* options from updated assignments $subquery = $clientConfig->getSql()->select()->columns(array('hardware_id'))->where(array('name' => 'DOWNLOAD', $where)); $delete = new \Zend\Db\Sql\Where(); $delete->equalTo('ivalue', $oldPackageId)->in('hardware_id', $subquery)->notEqualTo('name', 'DOWNLOAD_SWITCH')->like('name', 'DOWNLOAD_%'); $clientConfig->delete($delete); // Update package ID and reset status $clientConfig->update(array('ivalue' => $newPackageId, 'tvalue' => \Model\Package\Assignment::NOT_NOTIFIED, 'comments' => $now), array('name' => 'DOWNLOAD', $where)); } catch (\Exception $e) { throw new RuntimeException($e->getMessage(), (int) $e->getCode(), $e); } }
/** * Update package assignments * * Sets a new package on existing assignments. Updated assignments have * their status reset to "pending" and their options (force, schedule, * post cmd) removed. * * @param integer $oldPackageId package to be replaced * @param integer $newPackageId new package * @param bool $deployPending Update assignments with status 'pending' * @param bool $deployRunning Update assignments with status 'running' * @param bool $deploySuccess Update assignments with status 'success' * @param bool $deployError Update assignments with status 'error' * @param bool $deployGroups Update assignments for groups * @throws RuntimeException if an error occurs */ public function updateAssignments($oldPackageId, $newPackageId, $deployPending, $deployRunning, $deploySuccess, $deployError, $deployGroups) { if (!($deployPending or $deployRunning or $deploySuccess or $deployError or $deployGroups)) { return; // nothing to do } $clientConfig = $this->_serviceManager->get('Database\\Table\\ClientConfig'); $groupInfo = $this->_serviceManager->get('Database\\Table\\GroupInfo'); $where = new \Zend\Db\Sql\Where(); $where->equalTo('ivalue', $oldPackageId); $where->equalTo('name', 'DOWNLOAD'); // Additional filters are only necessary if not all conditions are set if (!($deployPending and $deployRunning and $deploySuccess and $deployError and $deployGroups)) { $groups = $groupInfo->getSql()->select()->columns(array('hardware_id')); $filters = new \Zend\Db\Sql\Where(null, \Zend\Db\Sql\Where::COMBINED_BY_OR); if ($deployPending) { $filters->isNull('tvalue')->and->notIn('hardware_id', $groups); } if ($deployRunning) { $filters->equalTo('tvalue', \Model\Package\Assignment::RUNNING); } if ($deploySuccess) { $filters->equalTo('tvalue', \Model\Package\Assignment::SUCCESS); } if ($deployError) { $filters->like('tvalue', \Model\Package\Assignment::ERROR_PREFIX . '%'); } if ($deployGroups) { $filters->in('hardware_id', $groups); } $where->addPredicate($filters); } $now = $this->_serviceManager->get('Library\\Now')->format(\Model\Package\Assignment::DATEFORMAT); try { // Remove DOWNLOAD_* options from updated assignments $subquery = $clientConfig->getSql()->select()->columns(array('hardware_id'))->where($where); // @codeCoverageIgnoreStart if ($clientConfig->getAdapter()->getPlatform()->getName() == 'MySQL') { // MySQL does not allow subquery on the same table for DELETE // statements. Fetch result as a list instead. $subquery = array_column($clientConfig->selectWith($subquery)->toArray(), 'hardware_id'); } // @codeCoverageIgnoreEnd if ($subquery) { // $subquery is either an SQL statement or a non-empty array. $delete = new \Zend\Db\Sql\Where(); $delete->equalTo('ivalue', $oldPackageId)->notEqualTo('name', 'DOWNLOAD_SWITCH')->in('hardware_id', $subquery)->like('name', 'DOWNLOAD_%'); $clientConfig->delete($delete); } // Update package ID and reset status $clientConfig->update(array('ivalue' => $newPackageId, 'tvalue' => \Model\Package\Assignment::PENDING, 'comments' => $now), $where); } catch (\Exception $e) { throw new RuntimeException($e->getMessage(), (int) $e->getCode(), $e); } }