本文整理汇总了PHP中wcf\util\FileUtil::uncompressFile方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::uncompressFile方法的具体用法?PHP FileUtil::uncompressFile怎么用?PHP FileUtil::uncompressFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\FileUtil
的用法示例。
在下文中一共展示了FileUtil::uncompressFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: installPackages
/**
* Registers with wcf setup delivered packages in the package installation queue.
*/
protected function installPackages()
{
// init database connection
$this->initDB();
// get admin account
$admin = new User(1);
// get delivered packages
$wcfPackageFile = '';
$otherPackages = array();
$tar = new Tar(SETUP_FILE);
foreach ($tar->getContentList() as $file) {
if ($file['type'] != 'folder' && mb_strpos($file['filename'], 'install/packages/') === 0) {
$packageFile = basename($file['filename']);
// ignore any files which aren't an archive
if (preg_match('~\\.(tar\\.gz|tgz|tar)$~', $packageFile)) {
$packageName = preg_replace('!\\.(tar\\.gz|tgz|tar)$!', '', $packageFile);
if ($packageName == 'com.woltlab.wcf') {
$wcfPackageFile = $packageFile;
} else {
$isStrato = !empty($_SERVER['DOCUMENT_ROOT']) && strpos($_SERVER['DOCUMENT_ROOT'], 'strato') !== false;
if (!$isStrato && preg_match('!\\.(tar\\.gz|tgz)$!', $packageFile)) {
// try to unzip zipped package files
if (FileUtil::uncompressFile(TMP_DIR . 'install/packages/' . $packageFile, TMP_DIR . 'install/packages/' . $packageName . '.tar')) {
@unlink(TMP_DIR . 'install/packages/' . $packageFile);
$packageFile = $packageName . '.tar';
}
}
$otherPackages[$packageName] = $packageFile;
}
}
}
}
$tar->close();
// register packages in queue
// get new process id
$sql = "SELECT\tMAX(processNo) AS processNo\n\t\t\tFROM\twcf" . WCF_N . "_package_installation_queue";
$statement = self::getDB()->prepareStatement($sql);
$statement->execute();
$result = $statement->fetchArray();
$processNo = intval($result['processNo']) + 1;
// search existing wcf package
$sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_package\n\t\t\tWHERE\tpackage = 'com.woltlab.wcf'";
$statement = self::getDB()->prepareStatement($sql);
$statement->execute();
$row = $statement->fetchArray();
if (!$row['count']) {
if (empty($wcfPackageFile)) {
throw new SystemException('the essential package com.woltlab.wcf is missing.');
}
// register essential wcf package
$queue = PackageInstallationQueueEditor::create(array('processNo' => $processNo, 'userID' => $admin->userID, 'package' => 'com.woltlab.wcf', 'packageName' => 'WoltLab Community Framework', 'archive' => TMP_DIR . 'install/packages/' . $wcfPackageFile, 'isApplication' => 1));
}
// register all other delivered packages
asort($otherPackages);
foreach ($otherPackages as $packageName => $packageFile) {
// extract packageName from archive's package.xml
$archive = new PackageArchive(TMP_DIR . 'install/packages/' . $packageFile);
try {
$archive->openArchive();
} catch (\Exception $e) {
// we've encountered a broken archive, revert everything and then fail
$sql = "SELECT\tqueueID, parentQueueID\n\t\t\t\t\tFROM\twcf" . WCF_N . "_package_installation_queue";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute();
$queues = array();
while ($row = $statement->fetchArray()) {
$queues[$row['queueID']] = $row['parentQueueID'];
}
$queueIDs = array();
$queueID = $queue->queueID;
while ($queueID) {
$queueIDs[] = $queueID;
$queueID = isset($queues[$queueID]) ? $queues[$queueID] : 0;
}
// remove previously created queues
if (!empty($queueIDs)) {
$sql = "DELETE FROM\twcf" . WCF_N . "_package_installation_queue\n\t\t\t\t\t\tWHERE\t\tqueueID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
WCF::getDB()->beginTransaction();
foreach ($queueIDs as $queueID) {
$statement->execute(array($queueID));
}
WCF::getDB()->commitTransaction();
}
// remove package files
@unlink(TMP_DIR . 'install/packages/' . $wcfPackageFile);
foreach ($otherPackages as $packageFile) {
@unlink(TMP_DIR . 'install/packages/' . $packageFile);
}
// throw exception again
throw new SystemException('', 0, '', $e);
}
$queue = PackageInstallationQueueEditor::create(array('parentQueueID' => $queue->queueID, 'processNo' => $processNo, 'userID' => $admin->userID, 'package' => $packageName, 'packageName' => $archive->getLocalizedPackageInfo('packageName'), 'archive' => TMP_DIR . 'install/packages/' . $packageFile, 'isApplication' => 1));
}
// login as admin
$factory = new ACPSessionFactory();
$factory->load();
//.........这里部分代码省略.........
示例2: unzipPackageArchive
/**
* Unzips compressed package archives and returns the temporary file name.
*
* @param string $archive filename
* @return string
*/
public static function unzipPackageArchive($archive) {
if (!FileUtil::isURL($archive)) {
$tar = new Tar($archive);
$tar->close();
if ($tar->isZipped()) {
$tmpName = FileUtil::getTemporaryFilename('package_');
if (FileUtil::uncompressFile($archive, $tmpName)) {
return $tmpName;
}
}
}
return $archive;
}