本文整理汇总了PHP中Versions::restore方法的典型用法代码示例。如果您正苦于以下问题:PHP Versions::restore方法的具体用法?PHP Versions::restore怎么用?PHP Versions::restore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Versions
的用法示例。
在下文中一共展示了Versions::restore方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
/**
* Auto-generate a form to edit the current database record
*
* @param integer $intId
* @param integer $ajaxId
*
* @return string
*/
public function edit($intId = null, $ajaxId = null)
{
if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) {
$this->log('Table "' . $this->strTable . '" is not editable', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
if ($intId != '') {
$this->intId = $intId;
}
// Get the current record
$objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->intId);
// Redirect if there is no record with the given ID
if ($objRow->numRows < 1) {
$this->log('Could not load record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$this->objActiveRecord = $objRow;
$return = '';
$this->values[] = $this->intId;
$this->procedure[] = 'id=?';
$this->blnCreateNewVersion = false;
$objVersions = new \Versions($this->strTable, $this->intId);
if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) {
// Compare versions
if (\Input::get('versions')) {
$objVersions->compare();
}
// Restore a version
if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') {
$objVersions->restore(\Input::post('version'));
$this->reload();
}
}
$objVersions->initialize();
// Build an array from boxes and rows
$this->strPalette = $this->getPalette();
$boxes = trimsplit(';', $this->strPalette);
$legends = array();
if (!empty($boxes)) {
foreach ($boxes as $k => $v) {
$eCount = 1;
$boxes[$k] = trimsplit(',', $v);
foreach ($boxes[$k] as $kk => $vv) {
if (preg_match('/^\\[.*\\]$/', $vv)) {
++$eCount;
continue;
}
if (preg_match('/^\\{.*\\}$/', $vv)) {
$legends[$k] = substr($vv, 1, -1);
unset($boxes[$k][$kk]);
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) {
unset($boxes[$k][$kk]);
}
}
// Unset a box if it does not contain any fields
if (count($boxes[$k]) < $eCount) {
unset($boxes[$k]);
}
}
$class = 'tl_tbox';
$fs = $this->Session->get('fieldset_states');
$blnIsFirst = true;
// Render boxes
foreach ($boxes as $k => $v) {
$strAjax = '';
$blnAjax = false;
$key = '';
$cls = '';
$legend = '';
if (isset($legends[$k])) {
list($key, $cls) = explode(':', $legends[$k]);
$legend = "\n" . '<legend onclick="AjaxRequest.toggleFieldset(this,\'' . $key . '\',\'' . $this->strTable . '\')">' . (isset($GLOBALS['TL_LANG'][$this->strTable][$key]) ? $GLOBALS['TL_LANG'][$this->strTable][$key] : $key) . '</legend>';
}
if (isset($fs[$this->strTable][$key])) {
$class .= $fs[$this->strTable][$key] ? '' : ' collapsed';
} else {
$class .= $cls && $legend ? ' ' . $cls : '';
}
$return .= "\n\n" . '<fieldset' . ($key ? ' id="pal_' . $key . '"' : '') . ' class="' . $class . ($legend ? '' : ' nolegend') . '">' . $legend;
// Build rows of the current box
foreach ($v as $vv) {
if ($vv == '[EOF]') {
if ($blnAjax && \Environment::get('isAjaxRequest')) {
return $strAjax . '<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">';
}
$blnAjax = false;
$return .= "\n" . '</div>';
continue;
}
if (preg_match('/^\\[.*\\]$/', $vv)) {
$thisId = 'sub_' . substr($vv, 1, -1);
$blnAjax = $ajaxId == $thisId && \Environment::get('isAjaxRequest') ? true : false;
//.........这里部分代码省略.........
示例2: diff
/**
* Compare two versions of a Model object. Returns an array of properties
* that have changed between the two versions, but does no comparison
* of the changes themselves. Note that this looks at the data array
* of the Model objects, not object properties, so it will not work
* on ordinary objects, only Model-based objects and objects returned
* by the `recent()` and `history()` methods.
*/
public static function diff($obj1, $obj2)
{
if (get_class($obj1) === 'stdClass') {
$v = new Versions();
$obj1 = $v->restore($obj1);
}
if (get_class($obj2) === 'stdClass') {
$v = new Versions();
$obj2 = $v->restore($obj2);
}
// are there extended fields?
$ext = is_subclass_of($obj2, 'ExtendedModel') ? $obj2->_extended_field : false;
$changed = array();
$obj1_orig = (array) $obj1->orig();
$obj2_orig = (array) $obj2->orig();
foreach ($obj1_orig as $key => $value) {
if ($ext === $key) {
// skip extended field
continue;
}
if ($value !== $obj2_orig[$key]) {
$changed[] = $key;
}
}
return $changed;
}
示例3: source
/**
* Load the source editor
*
* @return string
*/
public function source()
{
$this->isValid($this->intId);
if (is_dir(TL_ROOT . '/' . $this->intId)) {
$this->log('Folder "' . $this->intId . '" cannot be edited', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
} elseif (!file_exists(TL_ROOT . '/' . $this->intId)) {
$this->log('File "' . $this->intId . '" does not exist', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$this->import('BackendUser', 'User');
// Check user permission
if (!$this->User->hasAccess('f5', 'fop')) {
$this->log('Not enough permissions to edit the file source of file "' . $this->intId . '"', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$objFile = new \File($this->intId, true);
// Check whether file type is editable
if (!in_array($objFile->extension, trimsplit(',', strtolower(\Config::get('editableFiles'))))) {
$this->log('File type "' . $objFile->extension . '" (' . $this->intId . ') is not allowed to be edited', __METHOD__, TL_ERROR);
$this->redirect('contao/main.php?act=error');
}
$objMeta = null;
$objVersions = null;
// Add the versioning routines
if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->intId)) {
$objMeta = \FilesModel::findByPath($objFile->value);
if ($objMeta === null) {
$objMeta = \Dbafs::addResource($objFile->value);
}
$objVersions = new \Versions($this->strTable, $objMeta->id);
if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) {
// Compare versions
if (\Input::get('versions')) {
$objVersions->compare();
}
// Restore a version
if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') {
$objVersions->restore(\Input::post('version'));
// Purge the script cache (see #7005)
if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') {
$this->import('Automator');
$this->Automator->purgeScriptCache();
}
$this->reload();
}
}
$objVersions->initialize();
}
$strContent = $objFile->getContent();
if ($objFile->extension == 'svgz') {
$strContent = gzdecode($strContent);
}
// Process the request
if (\Input::post('FORM_SUBMIT') == 'tl_files') {
// Restore the basic entities (see #7170)
$strSource = \StringUtil::restoreBasicEntities(\Input::postRaw('source'));
// Save the file
if (md5($strContent) != md5($strSource)) {
if ($objFile->extension == 'svgz') {
$strSource = gzencode($strSource);
}
// Write the file
$objFile->write($strSource);
$objFile->close();
// Update the database
if ($this->blnIsDbAssisted && $objMeta !== null) {
/** @var \FilesModel $objMeta */
$objMeta->hash = $objFile->hash;
$objMeta->save();
$objVersions->create();
}
// Purge the script cache (see #7005)
if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') {
$this->import('Automator');
$this->Automator->purgeScriptCache();
}
}
if (\Input::post('saveNclose')) {
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
$this->redirect($this->getReferer());
}
$this->reload();
}
$codeEditor = '';
// Prepare the code editor
if (\Config::get('useCE')) {
$selector = 'ctrl_source';
$type = $objFile->extension;
// Load the code editor configuration
ob_start();
include TL_ROOT . '/system/config/ace.php';
$codeEditor = ob_get_contents();
ob_end_clean();
unset($selector, $type);
//.........这里部分代码省略.........
示例4: Versions
* Restores a previous version of a Model object, replacing the
* current version, and adding a new version to the history
* as well.
*/
$page->layout = 'admin';
if (!User::require_admin()) {
$this->redirect('/admin');
}
$ver = new Versions($_GET['id']);
$lock = new Lock($ver->class, $ver->pkey);
if ($lock->exists()) {
$page->title = __('Editing Locked');
echo $tpl->render('admin/locked', $lock->info());
return;
} else {
$lock->add();
}
$obj = $ver->restore();
$obj->put();
if ($obj->error) {
$page->title = __('An Error Occurred');
echo __('Error Message') . ': ' . $obj->error;
return;
}
Versions::add($obj);
$this->add_notification(__('Item restored.'));
if ($ver->class == 'Webpage') {
$cache->delete('_admin_page_' . $obj->id);
$this->redirect('/' . $obj->id);
}
$this->redirect('/');
示例5: diff
/**
* Compare two versions of a Model object. Returns an array of properties
* that have changed between the two versions, but does no comparison
* of the changes themselves. Note that this looks at the data array
* of the Model objects, not object properties, so it will not work
* on ordinary objects, only Model-based objects and objects returned
* by the `recent()` and `history()` methods.
*/
public static function diff($obj1, $obj2)
{
if (get_class($obj1) === 'stdClass') {
$v = new Versions();
$obj1 = $v->restore($obj1);
}
if (get_class($obj2) === 'stdClass') {
$v = new Versions();
$obj2 = $v->restore($obj2);
}
$changed = array();
foreach ($obj1->data as $key => $value) {
if ($value !== $obj2->data[$key]) {
$changed[] = $key;
}
}
return $changed;
}
示例6: elseif
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// not found
} elseif (!isset($item['id'])) {
include '../error.php';
// an anchor is mandatory
} elseif (!is_object($anchor)) {
Safe::header('Status: 404 Not Found', TRUE, 404);
Logger::error(i18n::s('No anchor has been found.'));
// permission denied
} elseif (!$permitted) {
// surfer has to be authenticated
if (!Surfer::is_logged()) {
Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'users/login.php?url=' . urlencode(Versions::get_url($item['id'], 'restore')));
}
// permission denied to authenticated user
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// restoration
} else {
// update the database
if (Versions::restore($item['id'])) {
// provide some feed-back
$context['text'] .= '<p>' . i18n::s('The page has been successfully restored.') . '</p>';
// follow-up commands
$context['text'] .= Skin::build_link($anchor->get_url(), i18n::s('Done'), 'button');
// clear the cache; the article may be listed at many places
Cache::clear();
}
}
// render the skin
render_skin();
示例7: edit
/**
* Auto-generate a form to edit the current database record
* @param integer
* @param integer
* @return string
*/
public function edit($intID = false, $ajaxId = false)
{
if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) {
\System::log('Table ' . $this->strTable . ' is not editable', __METHOD__, TL_ERROR);
\Controller::redirect('contao/main.php?act=error');
}
if ($intID) {
$this->intId = $intID;
}
// Get the current record
$objRow = \Database::getInstance()->prepare("SELECT * FROM {$this->strTable} WHERE id=?")->limit(1)->execute($this->intId);
// Redirect if there is no record with the given ID
if ($objRow->numRows < 1) {
\System::log('Could not load record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR);
\Controller::redirect('contao/main.php?act=error');
} elseif ($objRow->language != '') {
\System::log('Cannot edit language record "' . $this->strTable . '.id=' . $this->intId . '"', __METHOD__, TL_ERROR);
\Controller::redirect('contao/main.php?act=error');
}
$this->objActiveRecord = $objRow;
$return = '';
$this->values[] = $this->intId;
$this->procedure[] = 'id=?';
$this->blnCreateNewVersion = false;
$objVersions = new \Versions($this->strTable, $this->intId);
// Compare versions
if (\Input::get('versions')) {
$objVersions->compare();
}
// Restore a version
if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') {
$objVersions->restore(\Input::post('version'));
$this->reload();
}
$objVersions->initialize();
// Load and/or change language
$this->blnEditLanguage = false;
if (!empty($this->arrTranslations)) {
$blnLanguageUpdated = false;
$session = $this->Session->getData();
if (\Input::post('FORM_SUBMIT') == 'tl_language') {
if (in_array(\Input::post('language'), $this->arrTranslations)) {
$session['language'][$this->strTable][$this->intId] = \Input::post('language');
} else {
unset($session['language'][$this->strTable][$this->intId]);
}
$blnLanguageUpdated = true;
} elseif (\Input::post('FORM_SUBMIT') == $this->strTable && isset($_POST['deleteLanguage'])) {
$this->Database->prepare("DELETE FROM {$this->strTable} WHERE pid=? AND language=?")->execute($this->intId, $session['language'][$this->strTable][$this->intId]);
unset($session['language'][$this->strTable][$this->intId]);
$blnLanguageUpdated = true;
}
if ($blnLanguageUpdated) {
$this->Session->setData($session);
$_SESSION['TL_INFO'] = '';
\Controller::reload();
}
if ($_SESSION['BE_DATA']['language'][$this->strTable][$this->intId] != '' && in_array($_SESSION['BE_DATA']['language'][$this->strTable][$this->intId], $this->arrTranslations)) {
$objRow = $this->Database->prepare("SELECT * FROM {$this->strTable} WHERE pid=? AND language=?")->execute($this->intId, $_SESSION['BE_DATA']['language'][$this->strTable][$this->intId]);
if (!$objRow->numRows) {
$intId = $this->Database->prepare("INSERT INTO {$this->strTable} (pid,tstamp,language) VALUES (?,?,?)")->execute($this->intId, time(), $_SESSION['BE_DATA']['language'][$this->strTable][$this->intId])->insertId;
$objRow = $this->Database->prepare("SELECT * FROM {$this->strTable} WHERE id=?")->execute($intId);
}
$this->objActiveRecord = $objRow;
$this->values = array($this->intId, $_SESSION['BE_DATA']['language'][$this->strTable][$this->intId]);
$this->procedure = array('pid=?', 'language=?');
$this->blnEditLanguage = true;
}
}
// Build an array from boxes and rows
$this->strPalette = $this->getPalette();
$boxes = trimsplit(';', $this->strPalette);
$legends = array();
if (!empty($boxes)) {
foreach ($boxes as $k => $v) {
$eCount = 1;
$boxes[$k] = trimsplit(',', $v);
foreach ($boxes[$k] as $kk => $vv) {
if (preg_match('/^\\[.*\\]$/i', $vv)) {
++$eCount;
continue;
}
if (preg_match('/^\\{.*\\}$/', $vv)) {
$legends[$k] = substr($vv, 1, -1);
unset($boxes[$k][$kk]);
} elseif ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['exclude'] || !is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv])) {
unset($boxes[$k][$kk]);
} elseif ($this->blnEditLanguage && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$vv]['attributes']['multilingual']) {
unset($boxes[$k][$kk]);
}
}
// Unset a box if it does not contain any fields
if (count($boxes[$k]) < $eCount) {
unset($boxes[$k]);
//.........这里部分代码省略.........
示例8: Versions
<?php
/**
* Compares a previous version of a Model object to the
* current version, allowing you to restore the previous
* version if desired.
*/
$page->layout = 'admin';
if (!User::require_admin()) {
$this->redirect('/admin');
}
$ver = new Versions($_GET['id']);
$old = $ver->restore();
$class = $ver->class;
$cur = new $class($ver->pkey);
if ($cur->error) {
// deleted item
foreach (json_decode($ver->serialized) as $key => $value) {
$cur->{$key} = $value;
}
}
$diff = Versions::diff($old, $cur);
$data = array();
foreach ((array) $cur->orig() as $key => $value) {
$data[$key] = array('cur' => $value, 'old' => $old->{$key}, 'diff' => in_array($key, $diff) ? true : false);
}
$page->title = i18n_get('Comparing') . ' ' . $ver->class . ' / ' . $ver->pkey;
echo $tpl->render('admin/compare', array('fields' => $data, 'class' => $ver->class, 'pkey' => $ver->pkey, 'ts' => $ver->ts));