public function __construct() { $this->_configMain = Registry::get('main', 'config'); $this->_lang = Lang::lang(); $this->_db = Application::getDbConnection(); $this->_config = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php'); $this->_session = Store_Session::getInstance('Designer'); $this->_storage = Designer_Storage::getInstance($this->_config->get('storage'), $this->_config); }
/** * (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; } }
public function __construct() { /* * Load classes by autoloader * class should be loaded before unserializing */ class_exists('Db_Query'); class_exists('Db_Query_Part'); parent::__construct(); if ($this->_configMain->get('use_cache') && $this->_cache) { Db_Query_Storage::setCache($this->_cache); } $this->_storage = Db_Query_Storage::getInstance('file'); $this->_session = Store_Session::getInstance('Reports'); }
/** * (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(); }
/** * 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'])); }
protected function __construct() { $this->_model = Model::factory('User'); $this->_session = Store_Session::getInstance(); $this->_checkAuthSession(); }