/** * (non-PHPdoc) * @see Bgtask_Abstract::run() */ public function run() { $object = $this->_config['object']; $container = $this->_config['session_container']; /* * Save task ID into session for UI */ $session = Store_Session::getInstance(); $session->set($container, $this->_pid); $this->goBackground(); $objectConfig = Db_Object_Config::getInstance($object); $ivField = $objectConfig->getIvField(); $primaryKey = $objectConfig->getPrimaryKey(); if (!$objectConfig->hasEncrypted()) { $this->finish(); } $filter = array($ivField => new Db_Select_Filter($ivField, false, Db_Select_Filter::NOT_NULL)); $model = Model::factory($object); $count = Model::factory($object)->getCount($filter); $this->setTotalCount($count); if (!$count) { $this->finish(); } $data = $model->getList(array('limit' => $this->buckedSize), $filter, array($primaryKey)); $encryptedFields = $objectConfig->getEncryptedFields(); while (!empty($data)) { $ids = Utils::fetchCol($primaryKey, $data); $objectList = Db_Object::factory($object, $ids); $count = 0; foreach ($objectList as $dataObject) { $data = array(); foreach ($encryptedFields as $name) { $data[$name] = $dataObject->get($name); $model->logError($dataObject->getId() . ' ' . $name . ': ' . $data[$name]); } $data[$ivField] = null; try { $model->getDbConnection()->update($model->table(), $data, $primaryKey . ' = ' . $dataObject->getId()); $count++; } catch (Exception $e) { $errorText = 'Cannot decrypt ' . $dataObject->getName() . ' ' . $dataObject->getId() . ' ' . $e->getMessage(); $model->logError($errorText); $this->error($errorText); } } /* * Update task status and check for signals */ $this->incrementCompleted($count); $this->updateState(); $this->processSignals(); $data = $model->getList(array('limit' => $this->buckedSize), $filter, array($primaryKey)); } $this->finish(); }
/** * Store factory * @param int $type - const * @param string $name * @return Store_Interface or boolean false */ public static function factory($type = Store::Local, $name = 'default') { switch ($type) { case self::Local: return Store_Local::getInstance($name); break; case self::Session: return Store_Session::getInstance($name); break; default: return false; } }
/** * (non-PHPdoc) * @see Bgtask_Abstract::run() */ public function run() { $object = $this->_config['object']; $container = $this->_config['session_container']; /* * Save task ID into session for UI */ $session = Store_Session::getInstance(); $session->set($container, $this->_pid); $this->goBackground(); $objectConfig = Db_Object_Config::getInstance($object); $ivField = $objectConfig->getIvField(); $primaryKey = $objectConfig->getPrimaryKey(); $model = Model::factory($object); $count = Model::factory($object)->getCount(array($ivField => null)); $this->setTotalCount($count); if (!$count) { $this->finish(); } $ignore = array(); $data = $model->getList(array('limit' => $this->buckedSize), array($ivField => null), array($primaryKey)); while (!empty($data)) { $ids = Utils::fetchCol($primaryKey, $data); $objectList = Db_Object::factory($object, $ids); $count = 0; foreach ($objectList as $dataObject) { if (!$dataObject->save()) { $ignore[] = $dataObject->getId(); $this->log('Cannot encrypt ' . $dataObject->getName() . ' ' . $dataObject->getId()); } else { $count++; } } /* * Update task status and check for signals */ $this->incrementCompleted($count); $this->updateState(); $this->processSignals(); if (!empty($ignore)) { $filters = array($ivField => null, $primaryKey => new Db_Select_Filter($primaryKey, $ignore, Db_Select_Filter::NOT_IN)); } else { $filters = array($ivField => null); } $data = $model->getList(array('limit' => $this->buckedSize), $filters, array($primaryKey)); } $this->finish(); }
/** * Get Db_Query_Condition config */ public function loadconditionAction() { $this->_checkLoaded(); $query = $this->_session->get('query'); $id = Request::post('id', 'integer', false); if ($id === false) { Response::jsonError($this->_lang->WRONG_REQUEST . ' code 2'); } $condition = $query->getCondition($id); if ($condition === false) { Response::jsonError($this->_lang->WRONG_REQUEST . ' code 3'); } $data = get_object_vars($condition); $data['id'] = $id; Response::jsonSuccess($data); }
/** * Store project data */ protected function _storeProject() { $this->_session->set('project', serialize($this->_getProject())); }
/** * Check background process status */ public function taskstatAction() { $object = Request::post('object', 'string', false); $type = Request::post('type', 'string', false); $field = Request::post('field', 'string', false); if (!$object || !$type) { Response::jsonError(); } switch ($type) { case 'encrypt': $container = $this->encryptContainerPrefix . $object; break; case 'decrypt': $field = $container = $this->decryptContainerPrefix . $object; break; default: Response::jsonError($this->_lang->get('WRONG_REQUEST')); } $session = Store_Session::getInstance(); if (!$session->keyExists($container)) { Response::jsonError(); } $pid = $session->get($container); $taskModel = Model::factory('bgtask'); $statusData = $taskModel->getItem($pid); if (empty($statusData)) { Response::jsonError($this->_lang->get('CANT_EXEC')); } Response::jsonSuccess(array('status' => $statusData['status'], 'op_total' => $statusData['op_total'], 'op_finished' => $statusData['op_finished'])); }
/** * Check if user auth session exists */ protected function _checkAuthSession() { if ($this->_session->keyExists('auth') && $this->_session->get('auth') && $this->_session->keyExists('auth_id') && $this->_session->get('auth_id')) { $this->setId($this->_session->get('auth_id')); } }