當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Storage::rollback方法代碼示例

本文整理匯總了PHP中OCA\Files_Versions\Storage::rollback方法的典型用法代碼示例。如果您正苦於以下問題:PHP Storage::rollback方法的具體用法?PHP Storage::rollback怎麽用?PHP Storage::rollback使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OCA\Files_Versions\Storage的用法示例。


在下文中一共展示了Storage::rollback方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: doTestRestore

 private function doTestRestore()
 {
     $filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt';
     $this->rootView->file_put_contents($filePath, 'test file');
     $t0 = $this->rootView->filemtime($filePath);
     // not exactly the same timestamp as the file
     $t1 = time() - 60;
     // second version is two weeks older
     $t2 = $t1 - 60 * 60 * 24 * 14;
     // create some versions
     $v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1;
     $v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2;
     $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub');
     $this->rootView->file_put_contents($v1, 'version1');
     $this->rootView->file_put_contents($v2, 'version2');
     $oldVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt');
     $this->assertCount(2, $oldVersions);
     $this->assertEquals('test file', $this->rootView->file_get_contents($filePath));
     $info1 = $this->rootView->getFileInfo($filePath);
     $params = array();
     $this->connectMockHooks('rollback', $params);
     \OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2);
     $expectedParams = array('path' => '/sub/test.txt');
     $this->assertEquals($expectedParams, $params);
     $this->assertEquals('version2', $this->rootView->file_get_contents($filePath));
     $info2 = $this->rootView->getFileInfo($filePath);
     $this->assertNotEquals($info2['etag'], $info1['etag'], 'Etag must change after rolling back version');
     $this->assertEquals($info2['fileid'], $info1['fileid'], 'File id must not change after rolling back version');
     $this->assertEquals($info2['mtime'], $t2, 'Restored file has mtime from version');
     $newVersions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/sub/test.txt');
     $this->assertTrue($this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0), 'A version file was created for the file before restoration');
     $this->assertTrue($this->rootView->file_exists($v1), 'Untouched version file is still there');
     $this->assertFalse($this->rootView->file_exists($v2), 'Restored version file gone from files_version folder');
     $this->assertCount(2, $newVersions, 'Additional version created');
     $this->assertTrue(isset($newVersions[$t0 . '#' . 'test.txt']), 'A version was created for the file before restoration');
     $this->assertTrue(isset($newVersions[$t1 . '#' . 'test.txt']), 'Untouched version is still there');
     $this->assertFalse(isset($newVersions[$t2 . '#' . 'test.txt']), 'Restored version is not in the list any more');
 }
開發者ID:nem0xff,項目名稱:core,代碼行數:38,代碼來源:versions.php


注:本文中的OCA\Files_Versions\Storage::rollback方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。