예제 #1
0
파일: Object.php 프로젝트: vgrish/dvelum
 /**
  * Load version
  * @param integer $vers
  * @return boolean
  * @throws Exception
  */
 public function loadVersion($vers)
 {
     $this->rejectChanges();
     $versionObject = $this->_model->getStore()->getVersionObjectName();
     $vc = Model::factory($versionObject);
     $data = $vc->getData($this->getName(), $this->getId(), $vers);
     $pKey = $this->_config->getPrimaryKey();
     if (isset($data[$pKey])) {
         unset($data[$pKey]);
     }
     if (empty($data)) {
         throw new Exception('Cannot load version for ' . $this->getName() . ':' . $this->getId() . '. v:' . $vers);
     }
     $iv = false;
     $ivField = false;
     if ($this->_config->hasEncrypted()) {
         $ivField = $this->_config->getIvField();
         if (isset($data[$ivField]) && !empty($data[$ivField])) {
             $iv = base64_decode($data[$ivField]);
         }
     }
     foreach ($data as $k => $v) {
         if ($this->fieldExists($k)) {
             if ($this->_config->isMultiLink($k) && !empty($v)) {
                 $v = array_keys($v);
             }
             try {
                 if ($this->_config->isEncrypted($k)) {
                     if (!empty($iv)) {
                         $v = $this->_config->decrypt($v, $iv);
                     }
                 }
                 if ($k !== $this->_config->getPrimaryKey() && $k !== 'author_id') {
                     $this->set($k, $v);
                 }
             } catch (Exception $e) {
                 throw new Exception('Cannot load version data ' . $this->getName() . ':' . $this->getId() . '. v:' . $vers . '. This version contains incompatible data. ' . $e->getMessage());
             }
         }
     }
     $this->_version = $vers;
 }