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 } }