Esempio n. 1
0
 function pre_update(&$rec, $modified_field, $datatype)
 {
     trigger_before('pre_update', $rec, $this);
     if (isset($this->models[$rec->table]->field_attrs[$modified_field]['required'])) {
         if (!(strlen($rec->attributes[$modified_field]) > 0)) {
             trigger_error("Sorry, you must provide a value for {$modified_field}", E_USER_ERROR);
         }
     }
     if (isset($this->models[$rec->table]->field_attrs[$modified_field]['unique'])) {
         $result = $this->get_result("select " . $modified_field . " from " . $this->prefix . $rec->table . " where " . $modified_field . " = '" . $rec->attributes[$modified_field] . "' and " . $rec->primary_key . " != '" . $rec->attributes[$rec->primary_key] . "'");
         if ($this->num_rows($result) > 0) {
             trigger_error("Sorry, that {$modified_field} has already been taken.", E_USER_ERROR);
         }
     }
     if ($datatype == 'blob' && strlen($rec->attributes[$modified_field]) > 0) {
         if (environment('max_upload_mb')) {
             $max = 1048576 * environment('max_upload_mb');
             $size = filesize($rec->attributes[$modified_field]);
             if ($size > $max) {
                 trigger_error('Sorry but that file is too big, the limit is ' . environment('max_upload_mb') . ' megabytes', E_USER_ERROR);
             }
         }
         global $request;
         $coll = environment('collection_cache');
         if (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'aws') {
             $this->file_upload = array($modified_field, $rec->attributes[$modified_field]);
             $this->aws_delfile($rec, $rec->id);
             $this->aws_putfile($rec, $rec->id);
             $rec->set_value($modified_field, '');
         } elseif (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'uploads') {
             update_uploadsfile($this->prefix . $rec->table, $rec->id, $rec->attributes[$modified_field]);
             $rec->set_value($modified_field, '');
         } else {
             unlink_cachefile($this->prefix . $rec->table, $rec->id, $coll);
             $oid_result = $this->get_result("select " . $modified_field . " from " . $this->prefix . $rec->table . " where " . $rec->primary_key . " = '" . $rec->attributes[$rec->primary_key] . "'");
             if ($this->num_rows($oid_result) > 0) {
                 $prev_oid = $this->fetch_array($oid_result);
                 if (isset($prev_oid[0]) && $prev_oid[0] > 0) {
                     $result = $this->large_object_delete($prev_oid);
                 }
             }
             $oid = $this->large_object_create($this->prefix . $rec->table, $rec->attributes[$modified_field]);
             if ($oid > 0) {
                 $rec->attributes[$modified_field] = $oid;
             }
         }
     }
 }
Esempio n. 2
0
 function pre_update(&$rec, $modified_field, $datatype)
 {
     trigger_before('pre_update', $rec, $this);
     global $request;
     $req =& $request;
     if (isset($this->models[$rec->table]->field_attrs[$modified_field]['required'])) {
         if (!(strlen($rec->attributes[$modified_field]) > 0)) {
             trigger_error("{$modified_field} is a required field", E_USER_ERROR);
         }
     }
     if (isset($this->models[$rec->table]->field_attrs[$modified_field]['unique'])) {
         $result = $this->get_result("select " . $modified_field . " from " . $this->prefix . $rec->table . " where " . $modified_field . " = '" . $rec->attributes[$modified_field] . "' and " . $rec->primary_key . " != '" . $rec->attributes[$rec->primary_key] . "'");
         if ($this->num_rows($result) > 0) {
             trigger_error("Sorry but that {$modified_field} has already been taken.", E_USER_ERROR);
         }
     }
     if ($datatype == 'bool') {
         if (in_array($rec->attributes[$modified_field], $this->true_values, true)) {
             $rec->attributes[$modified_field] = "1";
         } else {
             $rec->attributes[$modified_field] = "false";
         }
     }
     if ($datatype == 'blob' && !empty($req->params[strtolower(classify($rec->table))][$modified_field])) {
         if (strlen($rec->attributes[$modified_field]) > 0) {
             if (environment('max_upload_mb')) {
                 $max = 1048576 * environment('max_upload_mb');
                 $size = filesize($rec->attributes[$modified_field]);
                 if ($size > $max) {
                     trigger_error('Sorry but that file is too big, the limit is ' . environment('max_upload_mb') . ' megabytes', E_USER_ERROR);
                 }
             }
             $coll = environment('collection_cache');
             if (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'aws') {
                 $this->file_upload = array($modified_field, $rec->attributes[$modified_field]);
                 $this->aws_delfile($rec, $rec->id);
                 $this->aws_putfile($rec, $rec->id);
                 $rec->set_value($modified_field, '');
             } elseif (isset($coll[$request->resource]) && $coll[$request->resource]['location'] == 'uploads') {
                 update_uploadsfile($this->prefix . $rec->table, $rec->id, $rec->attributes[$modified_field]);
                 $rec->set_value($modified_field, '');
             } else {
                 unlink_cachefile($this->prefix . $rec->table, $rec->id, $coll);
                 $data =& $this->large_object_create($this->prefix . $rec->table, $rec->attributes[$modified_field]);
                 $rec->attributes[$modified_field] =& $data;
             }
         }
     }
 }