Ejemplo n.º 1
0
 public function save()
 {
     if (!isset($this->_struct)) {
         throw new Axis_NSTree_Node_Exception('Операция save() для узлов присутствующих в дереве. ' . 'Предварительно вставьте узел appendChild() или insertSibling()');
     }
     parent::save();
 }
Ejemplo n.º 2
0
	public function save($doAudit = true) {
		$field = $this->table->getPrimary();
		
		// make sure data is valid
		if (!$this->_validated) {
			$this->validate();
		}
		if ($this->isValidated()) {
			$this->generateSafeTitle();
			
			if ($this->row->$field) {
				$this->beforeUpdate();
				$this->row->save();
				$this->afterUpdate();
			}
			else {
				$this->beforeInsert();
				$this->generateHash();
				$this->row->save();
				$this->afterInsert();
			}
			return true;
		}
		else {
			return false;
		}
			
	}
Ejemplo n.º 3
0
 public function save()
 {
     // write to master database pool
     $this->getTable()->getMasterAdapter();
     //logStd(get_class($this).'->save()', 'Write to MASTER.');
     return parent::save();
 }
Ejemplo n.º 4
0
 /**
  * Save this ModelResponseModel object
  *
  * @return boolean
  */
 public function save()
 {
     if (!$this->dirty) {
         return;
     }
     $this->modelResponseRow->save();
     $this->dirty = 0;
 }
 public function save()
 {
     $dbtable = $this->_table;
     if ($dbtable->_cache) {
         $dbtable->_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG);
     }
     return parent::save();
 }
Ejemplo n.º 6
0
 /**
  * Edit action
  */
 public function editAction()
 {
     // Get the request object
     $request = $this->getRequest();
     $populateWithDefaultValues = true;
     // Check if a form is sent
     if ($request->isPost()) {
         $postData = $request->getPost();
         $postData = $this->_parsePostData($postData);
         if (!isset($postData['form_class']) || isset($postData['form_class']) && $postData['form_class'] == get_class($this->_form)) {
             $populateWithDefaultValues = false;
             //Populate the post data to the form
             $this->_form->populate($postData);
             if ($this->_form->cancel->isChecked()) {
                 // Cancel button is pressed
                 $this->_redirect($this->_redirectUrlCancel);
             } elseif ($this->_form->delete !== null && $this->_form->delete->isChecked()) {
                 // Delete button is pressed
                 $this->_redirect($this->_redirectUrlDelete);
             } elseif ($this->validateForm($postData)) {
                 // Form is sent
                 try {
                     // Parse the form data
                     $item = $this->_getItem('edit');
                     if (array_key_exists('form_class', $item)) {
                         unset($item['form_class']);
                     }
                     if (array_key_exists('form_name', $item)) {
                         unset($item['form_name']);
                     }
                     // Save the item
                     $this->_item->setFromArray($item);
                     $this->_item->save();
                     // Actions after the query
                     $this->_afterQuery('edit');
                     // Set the form description
                     $this->_form->setDescription('The item is succesfully saved');
                     $this->_flashMessenger->addMessage('Saved the item succesfully.');
                     // Redirect to the index
                     $this->_redirect($this->_redirectUrlEdit);
                 } catch (Exception $exception) {
                     $this->_form->addErrorMessage($exception->getMessage());
                 }
             }
         }
     }
     if ($populateWithDefaultValues) {
         // Initialize the form with the item values
         $this->_form->populate($this->_getDefaultFormValues());
     }
     // Set the class "error" to subforms with errors
     if (method_exists($this->_form, 'setErrorClass')) {
         $this->_form->setErrorClass('error');
     }
     // Parse the form to the view
     $this->view->form = $this->_form;
 }
Ejemplo n.º 7
0
 /**
  * adds a new message
  *
  * @return void
  * @param Zend_Db_Table_Row $feed the related feed
  * @param string $message the message text
  */
 public function add($feed, $message)
 {
     // insert new error message
     $this->insert(array('feed' => $feed->id, 'datetime' => date('Y-m-d H:i:s'), 'message' => $message));
     // set error in feed table
     $feed->error = 1;
     $feed->save();
     return $message;
 }
Ejemplo n.º 8
0
 public function process(array $post, Zend_Db_Table_Row $row)
 {
     $this->setDefaults($row->toArray());
     //
     if (sizeof($post) && $this->isValid($post)) {
         try {
             $row->setFromArray($this->getValues());
             $row->save();
             return true;
         } catch (Exception $e) {
             $this->addDescription('There was an error saving your details');
             return $this;
         }
     }
     return $this;
 }
Ejemplo n.º 9
0
Archivo: Row.php Proyecto: douggr/benri
 /**
  * Saves the properties to the database.
  *
  * This performs an intelligent insert/update, and reloads the properties
  * with fresh data from the table on success.
  *
  * @return mixed The primary key value(s), as an associative array if the
  *  key is compound, or a scalar if the key is single-column
  */
 public final function save()
 {
     $this->checkReadOnly();
     /*
      * Allows pre-save logic to be applied to any row.
      *
      * Zend_Db_Table_Row only uses to do it on _insert OR _update,
      * here we can use the very same rules to be applied in both methods.
      */
     $this->_save();
     if (count($this->_errors)) {
         throw new Zend_Db_Table_Row_Exception('This row contain errors.');
     }
     foreach ($this->_data as $column => &$value) {
         if ($value instanceof DateTime) {
             // Should replace with Benri_Util_DateTime.
             if (!$value instanceof Benri_Util_DateTime) {
                 $value = new Benri_Util_DateTime($value->format('U'));
             }
             $value->setFormat('Y-m-d H:i:s');
         }
     }
     if ($this->isNewRecord()) {
         if ($this->offsetExists('created_at')) {
             $this->created_at = new Benri_Util_DateTime();
             $this->created_at->setFormat('Y-m-d H:i:s');
         }
     }
     if ($this->offsetExists('updated_at')) {
         $this->updated_at = new Benri_Util_DateTime();
         $this->updated_at->setFormat('Y-m-d H:i:s');
     }
     /// Saves the properties to the database
     parent::save();
     /// Run post-SAVE logic
     $this->_postSave();
     /// chain
     return $this;
 }
Ejemplo n.º 10
0
 /**
  * saves the new icon
  *
  * @return void
  * @param Zend_Db_Table_Row $feed the current feed
  */
 public function saveIcon($feed)
 {
     $icon = false;
     $iconLoader = Zend_Controller_Action_HelperBroker::getStaticHelper('icon');
     // use favicon url (if given)
     if (strlen(trim($feed->favicon)) != 0) {
         if (@file_get_contents($feed->favicon) !== false) {
             $icon = $iconLoader->loadIconFile($feed->favicon, Zend_Registry::get('config')->favicons->path);
         }
     }
     // try url of the htmlurl rss feed
     if ($icon === false && strlen($feed->htmlurl) > 0) {
         $icon = $iconLoader->load($feed->htmlurl, Zend_Registry::get('config')->favicons->path);
     }
     // use datasource icon
     if ($icon === false) {
         $icon = Zend_Controller_Action_HelperBroker::getStaticHelper('pluginloader')->getPlugin($feed->source)->icon;
     }
     // save icon url
     $feed->icon = $icon;
     $feed->dirtyicon = 0;
     $feed->save();
 }
Ejemplo n.º 11
0
 public function save()
 {
     $this->a_images = serialize($this->a_images);
     return parent::save();
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     /// A read-only row cannot be saved.
     if ($this->_readOnly === true) {
         throw new Exception('ERR.READ_ONLY');
     }
     /// Allows pre-save logic to be applied to any row.
     /// Zend_Db_Table_Row only uses to do it on _insert OR _update,
     /// why Zend, why?
     ///
     /// Computers are bullshit!
     $this->_save();
     foreach ($this->_data as $column => &$value) {
         if ($value instanceof \DateTime) {
             $value->setFormat('Y:m:d H:i:s');
         }
     }
     if (false !== $this->getErrors()) {
         throw new Exception('ERR.VALIDATION_INVALID');
     }
     $user = Table::getAuthUser();
     if ($user) {
         $created_by = $user->id;
     } else {
         $created_by = 1;
     }
     if ($this->isNewRecord()) {
         if ($this->offsetExists('created_by')) {
             $this->created_by = $created_by;
         }
         if ($this->offsetExists('updated_by')) {
             $this->updated_by = $created_by;
         }
     } else {
         if ($this->offsetExists('updated_by')) {
             $this->updated_by = $created_by;
         }
     }
     ///
     parent::save();
     ///
     $this->_postSave();
 }
Ejemplo n.º 13
0
 /**
  * Saves the properties to the database.
  *
  * This performs an intelligent insert/update, and reloads the
  * properties with fresh data from the table on success.
  *
  * @return mixed The primary key value(s), as an associative array if the
  *     key is compound, or a scalar if the key is single-column.
  */
 public function save()
 {
     $return = parent::save();
     foreach ($this->_table->getManyToManyTables() as $manyTable => $toManyTable) {
         $class = $this->_getClassName($toManyTable);
         $Obj = new $class($this->getTable()->getAdapter());
         $referenceTableClass = $Obj->getReference($this->_tableClass);
         $referenceManyTableClass = $Obj->getReference($manyTable);
         $fieldTableClass = reset($referenceTableClass["columns"]);
         $fieldManyTableClass = reset($referenceManyTableClass["columns"]);
         $Obj->delete($this->_table->getAdapter()->quoteInto("{$fieldTableClass}=?", $this->id));
         if (!is_array($this->_manyToManyData[$manyTable])) {
             continue;
         }
         foreach ($this->_manyToManyData[$manyTable] as $id) {
             $Obj->insert(array($fieldTableClass => $this->getId(), $fieldManyTableClass => $id));
         }
     }
     return $return;
 }
Ejemplo n.º 14
0
 /**
  * Persists the intal Fields to the primary table row.
  *
  * @return string The id of the primary table row is returned.
  */
 protected function _storeInternalFields()
 {
     try {
         // Store basic simple fields to complete the table row
         foreach ($this->_fields as $fieldname => $field) {
             // Skip external fields.
             if (isset($this->_externalFields[$fieldname])) {
                 continue;
             }
             // map field values: Cannot process array-valued fields
             $fieldValue = $field->getValue();
             // Check if the store mechanism for the field is overwritten in model.
             $callname = '_store' . $fieldname;
             if (method_exists($this, $callname) === true) {
                 // Call custom store method
                 $this->{$callname}($fieldValue);
             } else {
                 if ($field->isModified() === false) {
                     // Skip non-modified field.
                     continue;
                 } else {
                     $colname = self::convertFieldnameToColumn($fieldname);
                     $this->_primaryTableRow->{$colname} = $fieldValue;
                 }
             }
             // Clear modification status of successfully stored field.
             $field->clearModified();
         }
         // Backing up values to check for truncated fields after save().
         $backupValues = $this->_primaryTableRow->toArray();
         // Save the row.
         // This returnes the id needed to store external fields.
         $id = $this->_primaryTableRow->save();
         // Hack to check truncated fields.  (See ticket OPUSVIER-2111)
         // TODO: Better use MySQL strict mode "STRICT_TRANS_TABLES".
         foreach ($this->_primaryTableRow->toArray() as $key => $new_value) {
             // skip id-field
             if ($key === 'id') {
                 continue;
             }
             // if field was empty/too short before storing, skip it!
             if (!isset($backupValues[$key]) || strlen($backupValues[$key]) <= 4) {
                 continue;
             }
             if (strlen($backupValues[$key]) > strlen($new_value)) {
                 $truncateLength = strlen($backupValues[$key]) - strlen($new_value);
                 $msg = get_class($this);
                 $msg .= ": Database column '{$key}' has been truncated";
                 $msg .= " by {$truncateLength} characters!";
                 throw new Opus_Model_DbTruncateException(get_class($this) . ":  {$msg}");
             }
         }
     } catch (Zend_Db_Statement_Exception $ze) {
         if ($ze->getChainedException() instanceof PDOException and $ze->getCode() === 23000) {
             throw new Opus_Model_DbConstrainViolationException($ze->getMessage(), $ze->getCode(), $ze);
         }
         throw new Opus_Model_DbException($ze->getMessage(), $ze->getCode(), $ze);
     } catch (Opus_Model_Exception $ome) {
         // Needed to let instances of Opus_Model_Exception pass without
         // modifying their type.
         throw $ome;
     } catch (Exception $e) {
         $msg = $e->getMessage() . ' Model: ' . get_class($this);
         // this works with php >= 5.3.0: throw new Opus_Model_Exception($msg, $e->getCode(), $e);
         // workaround:
         $msg .= "\nThrown in " . $e->getFile() . ':' . $e->getLine();
         throw new Opus_Model_Exception($msg);
     }
     return $id;
 }
Ejemplo n.º 15
0
 /**
  * Persist a role to the database
  *
  * @return RoleModel
  */
 public function save()
 {
     $this->row->ACLstring = serialize($this->acl);
     $this->row->save();
     return $this;
 }
Ejemplo n.º 16
0
 /**
  * Save the row
  *
  * @param object $result    The current result item
  * @return void
  * @throws
  */
 protected function _saveRow($result)
 {
     try {
         $this->_tableRow->setFromArray($this->_data);
         unset($this->_data);
         $this->_tableRow->save();
         if ($this->_showProgress && !empty($result->id) && !empty($result->name)) {
             echo '<h1>' . 'Successful ' . $this->_rowAction . ' of ' . $result->id . ': ' . $result->name . '</h1>' . PHP_EOL;
         }
     } catch (Exception $e) {
         if ($this->_showProgress && !empty($result->id) && !empty($result->name)) {
             echo '<h1 class="error">' . 'Error attempting to ' . $this->_rowAction . ' ' . $result->id . ': ' . $result->name . '</h1>' . PHP_EOL;
         }
         throw new TicketEvolution_DataLoader_Exception($e);
     }
 }
 /**
  * Save the row
  *
  * @param object $result    The current result item
  * @return void
  * @throws
  */
 protected function _saveRow($result)
 {
     if ($this->_rowAction === 'INSERT' && $this->endpointState === 'deleted') {
         // No need to INSERT rows of deleted items.
         if ($this->_showProgress) {
             echo '<p>Skipping INSERT of deleted item ' . $result->id . '</p>' . PHP_EOL;
         }
         unset($this->_data);
     } else {
         try {
             $this->_tableRow->setFromArray($this->_data);
             unset($this->_data);
             $this->_tableRow->save();
             if ($this->_showProgress) {
                 $message = 'Successful ' . $this->_rowAction . ' of ' . $result->id;
                 if (!empty($result->name)) {
                     $message .= ': ' . $result->name;
                 }
                 echo '<p>' . $message . '</p>' . PHP_EOL;
             }
         } catch (Exception $e) {
             if ($this->_showProgress) {
                 $message = 'Error attempting to ' . $this->_rowAction . ' ' . $result->id;
                 if (!empty($result->name)) {
                     $message .= ': ' . $result->name;
                 }
                 echo '<h2 class="error">' . $message . '</h2>' . PHP_EOL;
             }
             throw new namespace\Exception($e);
         }
     }
 }