Exemplo n.º 1
0
 /**
  * Save the data, by loading it from the old revision and storing it as a new revision
  *
  * @param Doku_Event $event event object by reference
  * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return bool
  */
 public function handle_pagesave_after(Doku_Event $event, $param)
 {
     global $ACT;
     global $REV;
     if ($ACT != 'revert' || !$REV) {
         return false;
     }
     $assignments = new Assignments();
     //  we load the data to restore from DB:
     $tosave = $assignments->getPageAssignments($event->data['id']);
     foreach ($tosave as $table) {
         $accessOld = AccessTable::byTableName($table, $event->data['id'], $REV);
         $accessNew = AccessTable::byTableName($table, $event->data['id'], $event->data['newRevision']);
         $accessNew->saveData($accessOld->getDataArray());
         // make sure this schema is assigned
         $assignments->assignPageSchema($event->data['id'], $table);
     }
     return true;
 }
 /**
  * Saves struct data for given page and schema
  *
  * Please note that setting the $rev only influences the struct data timestamp,
  * not the page and changelog entries.
  *
  * @param string $page
  * @param string $schema
  * @param array $data
  * @param int $rev allows to override the revision timestamp
  */
 protected function saveData($page, $schema, $data, $rev = 0)
 {
     if (!$rev) {
         $rev = time();
     }
     saveWikiText($page, "test for {$page}", "saved for testing");
     $schemaData = AccessTable::byTableName($schema, $page, $rev);
     $schemaData->saveData($data);
     $assignments = new Assignments();
     $assignments->assignPageSchema($page, $schema);
 }
Exemplo n.º 3
0
 /**
  * Saves data for a given page (creates a new revision)
  *
  * If this call succeeds you can assume your data has either been saved or it was
  * not necessary to save it because the data already existed in the wanted form or
  * the given schemas are no longer assigned to that page.
  *
  * Important: You have to check write permissions for the given page before calling
  * this function yourself!
  *
  * this duplicates a bit of code from entry.php - we could also fake post data and let
  * entry handle it, but that would be rather unclean and might be problematic when multiple
  * calls are done within the same request.
  *
  * @todo should this try to lock the page?
  *
  *
  * @param string $page
  * @param array $data ('schema' => ( 'fieldlabel' => 'value', ...))
  * @param string $summary
  * @throws StructException
  */
 public function saveData($page, $data, $summary = '')
 {
     $page = cleanID($page);
     $summary = trim($summary);
     if (!$summary) {
         $summary = $this->getLang('summary');
     }
     if (!page_exists($page)) {
         throw new StructException("Page does not exist. You can not attach struct data");
     }
     // validate and see if anything changes
     $valid = AccessDataValidator::validateDataForPage($data, $page, $errors);
     if ($valid === false) {
         throw new StructException("Validation failed:\n%s", join("\n", $errors));
     }
     if (!$valid) {
         return;
     }
     // empty array when no changes were detected
     $newrevision = self::createPageRevision($page, $summary);
     // save the provided data
     $assignments = new Assignments();
     foreach ($valid as $v) {
         $v->saveData($newrevision);
         // make sure this schema is assigned
         $assignments->assignPageSchema($page, $v->getAccessTable()->getSchema()->getTable());
     }
 }
Exemplo n.º 4
0
 /**
  * Save the data
  *
  * When this is called, INPUT data has been validated already.
  *
  * @param Doku_Event $event event object by reference
  * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
  *                           handler was registered]
  * @return bool
  */
 public function handle_pagesave_after(Doku_Event $event, $param)
 {
     global $ACT;
     if ($ACT == 'revert') {
         return false;
     }
     // handled in revert
     $assignments = new Assignments();
     if ($event->data['changeType'] == DOKU_CHANGE_TYPE_DELETE && empty($GLOBALS['PLUGIN_MOVE_WORKING'])) {
         // clear all data on delete unless it's a move operation
         $tables = $assignments->getPageAssignments($event->data['id']);
         foreach ($tables as $table) {
             $schemaData = AccessTable::byTableName($table, $event->data['id'], time());
             if ($schemaData->getSchema()->isEditable()) {
                 $schemaData->clearData();
             }
         }
     } else {
         // save the provided data
         if ($this->tosave) {
             foreach ($this->tosave as $validation) {
                 if ($validation->getAccessTable()->getSchema()->isEditable()) {
                     $validation->saveData($event->data['newRevision']);
                     // make sure this schema is assigned
                     $assignments->assignPageSchema($event->data['id'], $validation->getAccessTable()->getSchema()->getTable());
                 }
             }
         }
     }
     return true;
 }