/**
  * Handle DELETE requests
  * @return array
  */
 public function delete()
 {
     $id = $this->getProperty($this->primaryKeyField, false);
     if (empty($id)) {
         return $this->failure($this->modx->lexicon('rest.err_field_ns', array('field' => $this->primaryKeyField)));
     }
     $c = $this->getPrimaryKeyCriteria($id);
     $this->object = $this->modx->getObject($this->classKey, $c);
     if (empty($this->object)) {
         return $this->failure($this->modx->lexicon('rest.err_obj_nf', array('class_key' => $this->classKey)));
     }
     if (!empty($this->deleteRequiredFields)) {
         if (!$this->checkRequiredFields($this->deleteRequiredFields)) {
             return $this->failure();
         }
     }
     $this->object->fromArray($this->getProperties());
     $beforeDelete = $this->beforeDelete();
     if ($beforeDelete !== true) {
         return $this->failure($beforeDelete === false ? $this->errorMessage : $beforeDelete);
     }
     if (!$this->object->{$this->deleteMethod}()) {
         $this->setObjectErrors();
         return $this->failure($this->modx->lexicon('rest.err_class_remove', array('class_key' => $this->classKey)));
     }
     $objectArray = $this->object->toArray();
     $this->afterDelete($objectArray);
     return $this->success('', $objectArray);
 }
예제 #2
0
 /**
  * {@inheritDoc}
  * @return mixed
  */
 public function process()
 {
     /* Run the beforeSet method before setting the fields, and allow stoppage */
     $canSave = $this->beforeSet();
     if ($canSave !== true) {
         return $this->failure($canSave);
     }
     $this->newObject->fromArray($this->object->toArray());
     $name = $this->getNewName();
     $this->setNewName($name);
     if ($this->alreadyExists($name)) {
         $this->addFieldError($this->nameField, $this->modx->lexicon($this->objectType . '_err_ae', array('name' => $name)));
     }
     $canSave = $this->beforeSave();
     if ($canSave !== true) {
         return $this->failure($canSave);
     }
     /* save new chunk */
     if ($this->newObject->save() === false) {
         $this->modx->error->checkValidation($this->newObject);
         return $this->failure($this->modx->lexicon($this->objectType . '_err_duplicate'));
     }
     $this->afterSave();
     $this->logManagerAction();
     return $this->cleanup();
 }