Esempio n. 1
0
 /**
  *
  * @param string $objectName            
  * @param array $fields
  *            - fields to check
  * @return array or false on error
  */
 public static function checkImportORMFields($objectName, array $fields)
 {
     if (!$objectName || empty($fields)) {
         return false;
     }
     $data = array();
     $config = Db_Object::factory($objectName)->getConfig();
     foreach ($fields as $field) {
         if (!$config->fieldExists($field)) {
             continue;
         }
         $fieldConfig = $config->getFieldConfig($field);
         $o = Ext_Factory::object('Data_Field', array('name' => $field, 'type' => self::convetDBFieldTypeToJS($fieldConfig['db_type'])));
         switch ($fieldConfig['db_type']) {
             case 'date':
                 $o->dateFormat = 'Y-m-d';
                 break;
             case 'datetime':
                 $o->dateFormat = 'Y-m-d H:i:s';
                 break;
             case 'time':
                 $o->dateFormat = 'H:i:s';
                 break;
         }
         $data[] = $o;
     }
     return $data;
 }
Esempio n. 2
0
 public function testFactory()
 {
     $page = $this->createPage();
     $o = Db_Object::factory('Page', $page->getId());
     $o2 = new Db_Object('page', $page->getId());
     $this->assertEquals($o, $o2);
 }
Esempio n. 3
0
 /**
  * (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();
 }
Esempio n. 4
0
 /**
  * (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();
 }
Esempio n. 5
0
 protected function _collectLinksData($field, $ids)
 {
     $ids = array_map('intval', $ids);
     $linkedObjectConfig = Db_Object_Config::getInstance($this->getLinkedObject($field));
     $linkedObjectName = $linkedObjectConfig->getName();
     $pKey = $linkedObjectConfig->getPrimaryKey();
     /*
      * Init object model
      */
     $model = Model::factory($linkedObjectName);
     /*
      * Find title field for link
      */
     $title = $pKey;
     $lt = $linkedObjectConfig->getLinkTitle();
     if ($lt) {
         $title = $lt;
     }
     $objects = Db_Object::factory($linkedObjectName, $ids);
     $result = array();
     foreach ($ids as $v) {
         if (!isset($objects[$v])) {
             throw new Exception('Invalid link');
         }
         $o = $objects[$v];
         $result[$v] = array('id' => $v, 'title' => $o->getTitle());
     }
     return $result;
 }
Esempio n. 6
0
 /**
  * Get object title
  */
 public function otitleAction()
 {
     $object = Request::post('object', 'string', false);
     $id = Request::post('id', 'string', false);
     if (!$object || !Db_Object_Config::configExists($object)) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     if (!in_array(strtolower($object), $this->_canViewObjects, true)) {
         Response::jsonError($this->_lang->CANT_VIEW);
     }
     $objectConfig = Db_Object_Config::getInstance($object);
     // Check ACL permissions
     $acl = $objectConfig->getAcl();
     if ($acl) {
         if (!$acl->can(Db_Object_Acl::ACCESS_VIEW, $object)) {
             Response::jsonError($this->_lang->get('ACL_ACCESS_DENIED'));
         }
     }
     try {
         $o = Db_Object::factory($object, $id);
         Response::jsonSuccess(array('title' => $o->getTitle()));
     } catch (Exception $e) {
         Model::factory($object)->logError('Cannot get title for ' . $object . ':' . $id);
         Response::jsonError($this->_lang->get('CANT_EXEC'));
     }
 }
Esempio n. 7
0
 public function otitleAction()
 {
     $object = Request::post('object', 'string', false);
     $id = Request::post('id', 'string', false);
     if (!$object || !Db_Object_Config::configExists($object)) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     try {
         $o = Db_Object::factory($object, $id);
         Response::jsonSuccess(array('title' => $o->getTitle()));
     } catch (Exception $e) {
         Model::factory($object)->logError('Cannot get title for ' . $object . ':' . $id);
         Response::jsonError($this->_lang->get('CANT_EXEC'));
     }
 }
Esempio n. 8
0
 /**
  * Delete Db object
  * @param string $objectName
  * @param array $ids
  * @return boolean
  */
 public function deleteObjects($objectName, array $ids)
 {
     $objectConfig = Db_Object_Config::getInstance($objectName);
     if ($objectConfig->isReadOnly()) {
         if ($this->_log) {
             $this->_log->log('ORM :: cannot delete readonly objects ' . $objectConfig->getName());
         }
         return false;
     }
     $objectModel = Model::factory($objectName);
     $tableName = $objectModel->table();
     if (empty($ids)) {
         return true;
     }
     $specialCase = Db_Object::factory($objectName);
     $db = $this->_getDbConnection($specialCase);
     $where = $db->quoteInto('`id` IN(?)', $ids);
     if ($this->_eventManager) {
         foreach ($ids as $id) {
             $specialCase->setId($id);
             $this->_eventManager->fireEvent(Db_Object_Event_Manager::BEFORE_DELETE, $specialCase);
         }
     }
     if (!$db->delete($tableName, $where)) {
         return false;
     }
     /*
      * Clear object liks (links from object)
      */
     Model::factory($this->_linksObject)->clearLinksFor($objectName, $ids);
     $history = Model::factory($this->_historyObject);
     $userId = User::getInstance()->id;
     /*
      * Save history if required
      */
     if ($objectConfig->hasHistory()) {
         foreach ($ids as $v) {
             $history->log($userId, $v, Model_Historylog::Delete, $tableName);
         }
     }
     if ($this->_eventManager) {
         /*
          * Fire "AFTER_DELETE" event for each deleted object
          */
         foreach ($ids as $id) {
             $specialCase->setId($id);
             $this->_eventManager->fireEvent(Db_Object_Event_Manager::AFTER_DELETE, $specialCase);
         }
     }
     return true;
 }
Esempio n. 9
0
 /**
  * Store class method
  * @param array $data
  * @throws Exception
  * @return Db_Object
  */
 protected function storeMethod(array $data)
 {
     $o = Db_Object::factory('sysdocs_class_method');
     $o->setValues($data);
     $hid = $this->historyId->getHid($o);
     $o->setValues($data);
     $o->set('hid', $hid);
     if (!$o->save(false, false)) {
         throw new Exception('cannot save sysdocs_class_method classId:' . $data['classId'] . ' -> ' . $data['name']);
     }
     return $o;
 }