Example #1
0
File: Vc.php Project: vgrish/dvelum
 /**
  * Create new  version
  * @property Db_Object $object
  * @return boolean
  */
 public function newVersion(Db_Object $object)
 {
     $object->commitChanges();
     $newVersion = $this->getLastVersion($object->getName(), $object->getId()) + 1;
     $newData = $object->getData();
     if ($object->getConfig()->hasEncrypted()) {
         $ivField = $object->getConfig()->getIvField();
         $ivKey = $object->get($ivField);
         if (empty($ivKey)) {
             $ivKey = Utils_String::createEncryptIv();
             $newData[$ivField] = $ivKey;
         }
         $newData = $this->getStore()->encryptData($object, $newData);
     }
     $newData['id'] = $object->getId();
     try {
         $vObject = new Db_Object('vc');
         $vObject->set('date', date('Y-m-d'));
         $vObject->set('data', base64_encode(serialize($newData)));
         $vObject->set('user_id', User::getInstance()->id);
         $vObject->set('version', $newVersion);
         $vObject->set('record_id', $object->getId());
         $vObject->set('object_name', $object->getName());
         $vObject->set('date', date('Y-m-d H:i:s'));
         if ($vObject->save()) {
             return $newVersion;
         }
         return false;
     } catch (Exception $e) {
         $this->logError('Cannot create new version for ' . $object->getName() . '::' . $object->getId() . ' ' . $e->getMessage());
         return false;
     }
 }
Example #2
0
 /**
  * Update object
  * @param Db_Object $object
  * @return void
  */
 public function updateObject(Db_Object $object)
 {
     $changeVal = Request::post('changeVal', 'bool', false);
     if ($changeVal) {
         $object->set('hash', Utils::hash($object->get('hash')));
     }
     if (!$object->save()) {
         Response::jsonError($this->_lang->CANT_EXEC);
     }
     Response::jsonSuccess(array('id' => $object->getId()));
 }
Example #3
0
 public function getHid(Db_Object $object)
 {
     $name = strtolower($object->getName());
     switch ($object->getName()) {
         case 'sysdocs_class':
             return $this->getClassHid($object->get('fileHid'), $object->get('name'));
             break;
         case 'sysdocs_class_method':
             return $this->getMethodHid($object->get('classHid'), $object->get('name'));
             break;
         case 'sysdocs_class_method_param':
             return $this->getParamHid($object->get('methodHid'), $object->get('name'));
             break;
         case 'sysdocs_class_property':
             return $this->getPropertysHid($object->get('classHid'), $object->get('name'));
             break;
         case 'sysdocs_file':
             return $this->getFileHid($object->get('path'), $object->get('name'));
             break;
         default:
             throw new Exception('Undefined HID generator for ' . $name);
     }
 }
Example #4
0
 /**
  * Download file from filestorage
  */
 public function downloadAction()
 {
     $fileId = intval(Request::getInstance()->getPart(3));
     if (!$fileId) {
         Response::redirect('/');
     }
     try {
         $file = new Db_Object('Filestorage', $fileId);
     } catch (Exception $e) {
         Response::redirect('/');
     }
     $storage = Model::factory('Filestorage')->getStorage();
     $storageConfig = $storage->getConfig()->__toArray();
     $storagePath = $storageConfig['filepath'] . $file->get('path');
     if (!file_exists($storagePath)) {
         echo $this->_lang->get('FILE_NOT_FOUND');
         exit;
     }
     header('Content-Description: File Transfer');
     // header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename=' . str_replace(' ', '_', $file->get('name')));
     switch ($storageConfig['download']['type']) {
         case 'native':
             readfile($storagePath);
             break;
         case 'apache':
             $filePath = $storageConfig['redirect_path'] . $file->get('path');
             header('X-Sendfile: ' . $filePath);
             break;
         case 'nginx':
             $filePath = $storageConfig['redirect_path'] . $file->get('path');
             header('X-Accel-Redirect: ' . $filePath);
             break;
     }
     exit;
 }
Example #5
0
File: Vc.php Project: vgrish/dvelum
 /**
  * Unpublish object
  * Sends JSON reply in the result
  * and closes the application.
  * @param Db_Object $object
  */
 public function unpublishObject(Db_Object $object)
 {
     if (!$object->get('published')) {
         Response::jsonError($this->_lang->NOT_PUBLISHED);
     }
     if (!$object->unpublish()) {
         Response::jsonError($this->_lang->CANT_EXEC);
     }
     Response::jsonSuccess();
 }
Example #6
0
 /**
  * Add new object version
  * @param Db_Object $object
  * @param boolean $log - optional, log changes
  * @param boolean $useTransaction - optional , use transaction if available
  * @return boolean|integer - vers number
  */
 public function addVersion(Db_Object $object, $log = true, $useTransaction = true)
 {
     if ($object->getConfig()->isReadOnly()) {
         if ($this->_log) {
             $this->_log->log('ORM :: cannot addVersion for readonly object ' . $object->getConfig()->getName());
         }
         return false;
     }
     /*
      * Check object id
      */
     if (!$object->getId()) {
         return false;
     }
     if (!$object->getConfig()->isRevControl()) {
         if ($this->_log) {
             $this->_log->log($object->getName() . '::publish Cannot addVersion. Object is not under version control');
         }
         return false;
     }
     /*
      * Fire "BEFORE_ADD_VERSION" Event if event manager exists
      */
     if ($this->_eventManager) {
         $this->_eventManager->fireEvent(Db_Object_Event_Manager::BEFORE_ADD_VERSION, $object);
     }
     /*
      * Create new revision
      */
     $versNum = Model::factory($this->_versionObject)->newVersion($object);
     if (!$versNum) {
         return false;
     }
     try {
         $oldObject = new Db_Object($object->getName(), $object->getId());
         /**
          * Update object if not published
          */
         if (!$oldObject->get('published')) {
             $data = $object->getData();
             foreach ($data as $k => $v) {
                 if (!is_null($v)) {
                     $oldObject->set($k, $v);
                 }
             }
         }
         $oldObject->set('date_updated', $object->get('date_updated'));
         $oldObject->set('editor_id', $object->get('editor_id'));
         if (!$oldObject->save(false, $useTransaction)) {
             throw new Exception('Cannot save object');
         }
     } catch (Exception $e) {
         if ($this->_log) {
             $this->_log->log('Cannot update unpublished object data ' . $e->getMessage());
         }
         return false;
     }
     /*
      * Save history if required
      * @todo удалить жесткую связанность
      */
     if ($log && $object->getConfig()->get('save_history')) {
         Model::factory($this->_historyObject)->log(User::getInstance()->getId(), $object->getId(), Model_Historylog::NewVersion, $object->getTable());
     }
     /*
      * Fire "AFTER_ADD_VERSION" Event if event manager exists
      */
     if ($this->_eventManager) {
         $this->_eventManager->fireEvent(Db_Object_Event_Manager::AFTER_ADD_VERSION, $object);
     }
     return $versNum;
 }
Example #7
0
 protected function processMethods(Db_Object $class, sysdocs_Analyzer $analyzer)
 {
     $methods = $analyzer->getMethods();
     $paramsList = array();
     if (!empty($methods)) {
         foreach ($methods as $method) {
             $data = array('classId' => $class->getId(), 'name' => $method['name'], 'returnType' => $method['returnType'], 'deprecated' => intval($method['deprecated']), 'description' => $this->clearDescription($method['description']), 'abstract' => $method['abstract'], 'throws' => $method['throws'], 'vers' => $this->vers, 'hid' => '', 'static' => intval($method['static']), 'visibility' => $method['visibility'], 'classHid' => $class->get('hid'), 'inherited' => $method['inherited'], 'returnsReference' => $method['returnsReference']);
             $methodObject = $this->storeMethod($data);
             $params = $analyzer->getParametrs($method['name']);
             if (!empty($params)) {
                 $methodId = $methodObject->getId();
                 $methodHid = $methodObject->get('hid');
                 foreach ($params as $param) {
                     $paramsList[] = array('methodId' => $methodId, 'hid' => $this->historyId->getParamHid($methodHid, $param['name']), 'name' => $param['name'], 'vers' => $this->vers, 'index' => $param['index'], 'default' => $param['default'], 'isRef' => $param['isRef'], 'description' => $this->clearDescription($param['description']), 'methodHid' => $methodObject->get('hid'), 'optional' => $param['optional']);
                 }
             }
         }
         if (!Model::factory('sysdocs_class_method_param')->multiInsert($paramsList)) {
             throw new Exception('Cannot save sysdocs_class_method_param');
         }
     }
 }