Esempio n. 1
0
 /**
  * Update data from a addTable record
  *
  * @param $row
  */
 public function _dataUpdate($row, $primaryKeys)
 {
     $keys = G::decrypt($row['__index__'], 'pmtable');
     $keys = explode(',', $keys);
     unset($row['__index__']);
     $params = array();
     foreach ($keys as $key) {
         $params[] = is_numeric($key) ? $key : "'{$key}'";
     }
     $obj = null;
     eval('$obj = ' . $this->classPeerName . '::retrieveByPk(' . implode(',', $params) . ');');
     if (is_object($obj)) {
         foreach ($row as $key => $value) {
             // validation, don't modify primary keys
             if (in_array($key, $primaryKeys)) {
                 throw new Exception(G::loadTranslation('ID_DONT_MODIFY_PK_VALUE', array($key)));
             }
             $action = 'set' . AdditionalTables::getPHPName($key);
             $obj->{$action}($value);
         }
         if ($r = $obj->validate()) {
             $obj->save();
             $result = true;
         } else {
             $msg = '';
             foreach ($obj->getValidationFailures() as $objValidationFailure) {
                 $msg .= $objValidationFailure->getMessage() . "\n";
             }
             throw new Exception($msg);
         }
     } else {
         $result = false;
     }
     return $result;
 }