예제 #1
0
 function handle(&$params)
 {
     if (!@$_POST['history__id']) {
         return PEAR::raiseError("No history id specified", DATAFACE_E_ERROR);
     }
     $historyid = $_POST['history__id'];
     if (!preg_match('/\\d+/', $historyid)) {
         return PEAR::raiseError("Invalid history id provided.", DATAFACE_E_ERROR);
     }
     $app =& Dataface_Application::getInstance();
     $record =& $app->getRecord();
     if (!$record) {
         return PEAR::raiseError("No record was specified", DATAFACE_E_ERROR);
     }
     import("Dataface/HistoryTool.php");
     $ht = new Dataface_HistoryTool();
     $hrecord = $ht->getRecordById($record->_table->tablename, $historyid);
     // make sure that this history record matches the current record.
     $keys = array_keys($record->_table->keys());
     if ($record->strvals($keys) != $hrecord->strvals($keys)) {
         return PEAR::raiseError("Attempt to restore record history from unmatching history record.", DATAFACE_E_ERROR);
     }
     // Now that we are convinced that we have the correct record, we can restore it.
     if (@$_POST['-fieldname']) {
         $fieldname = $_POST['-fieldname'];
     } else {
         $fieldname = null;
     }
     $res = $ht->restore($record, $historyid, $fieldname, true);
     if (PEAR::isError($res)) {
         return $res;
     }
     $url = false;
     //$app->getPreviousUrl(true);
     if (@$_POST['-locationid']) {
         $url = DATAFACE_SITE_HREF . '?' . $app->decodeLocation($_POST['-locationid']);
     }
     if (!$url) {
         // If the url is not specified we will just create a url to return
         // to the specified record's history listing.
         $url = $record->getURL('-action=history');
     }
     if ($fieldname) {
         $msg = "Field '{$fieldname}' successfully restored to its value from '" . $hrecord->strval('history__modified') . "'.";
     } else {
         $msg = "Record successfully restored to its value from '" . $hrecord->strval('history__modified') . "'.";
     }
     $url .= "&--msg=" . urlencode($msg);
     header('Location: ' . $url);
     exit;
 }
예제 #2
0
 function test_restore()
 {
     $app =& Dataface_Application::getInstance();
     $record = df_get_record('HistoryToolTest', array('name' => 'Johnny'));
     $this->assertEquals('john.gif', $record->val('container_field'));
     $record->setValue('container_field', 'john2.gif');
     $record->save();
     $ht = new Dataface_HistoryTool();
     $hid = $ht->logRecord($record);
     $history1 = $ht->getRecordById('HistoryToolTest', $hid);
     $this->assertEquals(array('name' => 'Johnny', 'container_field' => 'john2.gif'), $history1->strvals(array('name', 'container_field')));
     $record->setValue('container_field', 'john3.gif');
     $record->save();
     $hid2 = $ht->logRecord($record);
     $history2 = $ht->getRecordById('HistoryToolTest', $hid2);
     $this->assertEquals(array('name' => 'Johnny', 'container_field' => 'john3.gif'), $history2->strvals(array('name', 'container_field')));
     $record2 = df_get_record('HistoryToolTest', array('name' => 'Johnny'));
     $this->assertEquals($record2->strvals(array('name', 'container_field')), $history2->strvals(array('name', 'container_field')));
     $ht->restore($record, $hid);
     $record3 = df_get_record('HistoryToolTest', array('name' => 'Johnny'));
     $this->assertEquals(array('name' => 'Johnny', 'container_field' => 'john2.gif'), $record3->strvals(array('name', 'container_field')));
 }