/** * * * @since 0.1 * * @param EPRevisionAction $revAction * @param array $conditions * * @return boolean */ public static function deleteAndLog(EPRevisionAction $revAction, array $conditions) { $objects = static::select(null, $conditions); $success = true; if (count($objects) > 0) { $success = static::delete($conditions); if ($success) { $revAction->setDelete(true); foreach ($objects as $object) { $object->handleRemoved($revAction); } } } return $success; }
/** * Create a new revision object for the provided EPRevisionedObject. * The EPRevisionedObject should have all it's fields loaded. * * @since 0.1 * * @param EPDBObject $object * @param EPRevisionAction $revAction * * @return EPRevision */ public static function newFromObject(EPRevisionedObject $object, EPRevisionAction $revAction) { $fields = array('object_id' => $object->getId(), 'user_id' => $revAction->getUser()->getID(), 'user_text' => $revAction->getUser()->getName(), 'type' => get_class($object), 'comment' => $revAction->getComment(), 'minor_edit' => $revAction->isMinor(), 'time' => $revAction->getTime(), 'deleted' => $revAction->isDelete(), 'data' => serialize($object->toArray())); $identifier = $object->getIdentifier(); if (!is_null($identifier)) { $fields['object_identifier'] = $identifier; } return new static($fields); }
/** * Log an action. * * @since 0.1 * * @param string $subType */ protected function log($subType) { if ($this->log) { $info = $this->getLogInfo($subType); if ($info !== false) { if ($this->revAction !== false) { $info['user'] = $this->revAction->getUser(); $info['comment'] = $this->revAction->getComment(); } $info['subtype'] = $subType; EPUtils::log($info); } } }
public function execute() { $params = $this->extractRequestParams(); if (!$this->userIsAllowed($params['type'], $params) || $this->getUser()->isBlocked()) { $this->dieUsageMsg(array('badaccess-groups')); } $everythingOk = true; // foreach ( $params['ids'] as $id ) { // // $instance->remove is used instead of Class::delete, // // so that linked data also gets deleted. // $c = self::$typeMap[$params['type']]; // $object = new $c( array( 'id' => $id ) ); // $everythingOk = $object->remove() && $everythingOk; // } $class = self::$typeMap[$params['type']]; if (count($params['ids']) > 0) { $revAction = new EPRevisionAction(); $revAction->setUser($this->getUser()); $revAction->setComment($params['comment']); $class::deleteAndLog($revAction, array('id' => $params['ids'])); } $this->getResult()->addValue(null, 'success', $everythingOk); }
/** * Process the form. At this point we know that the user passes all the criteria in * userCanExecute(). * * @param array $data * * @return Bool|Array */ public function handleSubmission(array $data) { $fields = array(); $unknownValues = array(); $c = $this->getItemClass(); // Yeah, this is needed in PHP 5.3 >_> foreach ($data as $name => $value) { $matches = array(); if (preg_match('/item-(.+)/', $name, $matches)) { if ($matches[1] === 'id' && ($value === '' || $value === '0')) { $value = null; } if ($c::canHasField($matches[1])) { $fields[$matches[1]] = $value; } else { $unknownValues[$matches[1]] = $value; } } } $keys = array_keys($fields); $fields = array_combine($keys, array_map(array($this, 'handleKnownField'), $keys, $fields)); /* EPPageObject */ $item = new $c($fields, is_null($fields['id'])); foreach ($unknownValues as $name => $value) { $this->handleUnknownField($item, $name, $value); } $revAction = new EPRevisionAction(); $revAction->setUser($this->getUser()); $revAction->setComment(''); // TODO $revAction->setMinor(false); // TODO $success = $item->revisionedSave($revAction); if ($success) { return true; } else { return array(); // TODO } }