当前位置: 首页>>代码示例>>PHP>>正文


PHP TempFSFile::autocollect方法代码示例

本文整理汇总了PHP中TempFSFile::autocollect方法的典型用法代码示例。如果您正苦于以下问题:PHP TempFSFile::autocollect方法的具体用法?PHP TempFSFile::autocollect怎么用?PHP TempFSFile::autocollect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TempFSFile的用法示例。


在下文中一共展示了TempFSFile::autocollect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: importUpload

 /**
  * @return bool
  */
 function importUpload()
 {
     # Construct a file
     $archiveName = $this->getArchiveName();
     if ($archiveName) {
         wfDebug(__METHOD__ . "Importing archived file as {$archiveName}\n");
         $file = OldLocalFile::newFromArchiveName($this->getTitle(), RepoGroup::singleton()->getLocalRepo(), $archiveName);
     } else {
         $file = wfLocalFile($this->getTitle());
         $file->load(File::READ_LATEST);
         wfDebug(__METHOD__ . 'Importing new file as ' . $file->getName() . "\n");
         if ($file->exists() && $file->getTimestamp() > $this->getTimestamp()) {
             $archiveName = $file->getTimestamp() . '!' . $file->getName();
             $file = OldLocalFile::newFromArchiveName($this->getTitle(), RepoGroup::singleton()->getLocalRepo(), $archiveName);
             wfDebug(__METHOD__ . "File already exists; importing as {$archiveName}\n");
         }
     }
     if (!$file) {
         wfDebug(__METHOD__ . ': Bad file for ' . $this->getTitle() . "\n");
         return false;
     }
     # Get the file source or download if necessary
     $source = $this->getFileSrc();
     $autoDeleteSource = $this->isTempSrc();
     if (!strlen($source)) {
         $source = $this->downloadSource();
         $autoDeleteSource = true;
     }
     if (!strlen($source)) {
         wfDebug(__METHOD__ . ": Could not fetch remote file.\n");
         return false;
     }
     $tmpFile = new TempFSFile($source);
     if ($autoDeleteSource) {
         $tmpFile->autocollect();
     }
     $sha1File = ltrim(sha1_file($source), '0');
     $sha1 = $this->getSha1();
     if ($sha1 && $sha1 !== $sha1File) {
         wfDebug(__METHOD__ . ": Corrupt file {$source}.\n");
         return false;
     }
     $user = $this->getUserObj() ?: User::newFromName($this->getUser());
     # Do the actual upload
     if ($archiveName) {
         $status = $file->uploadOld($source, $archiveName, $this->getTimestamp(), $this->getComment(), $user);
     } else {
         $flags = 0;
         $status = $file->upload($source, $this->getComment(), $this->getComment(), $flags, false, $this->getTimestamp(), $user);
     }
     if ($status->isGood()) {
         wfDebug(__METHOD__ . ": Successful\n");
         return true;
     } else {
         wfDebug(__METHOD__ . ': failed: ' . $status->getHTML() . "\n");
         return false;
     }
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:61,代码来源:WikiRevision.php

示例2: testTrickyDomain

 public function testTrickyDomain()
 {
     global $wgDBtype;
     if ($wgDBtype === 'sqlite') {
         $tmpDir = $this->getNewTempDirectory();
         $dbPath = "{$tmpDir}/unit_test_db.sqlite";
         file_put_contents($dbPath, '');
         $tempFsFile = new TempFSFile($dbPath);
         $tempFsFile->autocollect();
     } else {
         $dbPath = null;
     }
     $dbname = 'unittest-domain';
     $factory = $this->newLBFactoryMulti(['localDomain' => $dbname], ['dbname' => $dbname, 'dbFilePath' => $dbPath]);
     $lb = $factory->getMainLB();
     /** @var Database $db */
     $db = $lb->getConnection(DB_MASTER, [], '');
     $lb->reuseConnection($db);
     // don't care
     $this->assertEquals('', $db->getDomainID());
     $this->assertEquals($this->quoteTable($db, 'page'), $db->tableName('page'), "Correct full table name");
     $this->assertEquals($this->quoteTable($db, $dbname) . '.' . $this->quoteTable($db, 'page'), $db->tableName("{$dbname}.page"), "Correct full table name");
     $this->assertEquals($this->quoteTable($db, 'nice_db') . '.' . $this->quoteTable($db, 'page'), $db->tableName('nice_db.page'), "Correct full table name");
     $factory->setDomainPrefix('my_');
     $this->assertEquals($this->quoteTable($db, 'my_page'), $db->tableName('page'), "Correct full table name");
     $this->assertEquals($this->quoteTable($db, 'other_nice_db') . '.' . $this->quoteTable($db, 'page'), $db->tableName('other_nice_db.page'), "Correct full table name");
     \MediaWiki\suppressWarnings();
     $this->assertFalse($db->selectDB('garbage-db'));
     \MediaWiki\restoreWarnings();
     $this->assertEquals($this->quoteTable($db, 'garbage-db') . '.' . $this->quoteTable($db, 'page'), $db->tableName('garbage-db.page'), "Correct full table name");
     $factory->closeAll();
     $factory->destroy();
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:33,代码来源:LBFactoryTest.php


注:本文中的TempFSFile::autocollect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。