本文整理汇总了PHP中nzedb\utility\Misc::getDirFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Misc::getDirFiles方法的具体用法?PHP Misc::getDirFiles怎么用?PHP Misc::getDirFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nzedb\utility\Misc
的用法示例。
在下文中一共展示了Misc::getDirFiles方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkSQLFileLatest
/**
* Checks the numeric value from the last SQL patch file, updating the versions file if desired.
*
* @param bool $update Whether to update the versions file.
*
* @return bool|int False if there is a problem, otherwise the number from the last patch file.
*/
public function checkSQLFileLatest($update = true)
{
$options = ['data' => nZEDb_RES . 'db' . DS . 'schema' . DS . 'data' . DS, 'ext' => 'sql', 'path' => nZEDb_RES . 'db' . DS . 'patches' . DS . 'mysql', 'regex' => '#^' . Misc::PATH_REGEX . '(?P<patch>\\d{4})~(?P<table>\\w+)\\.sql$#', 'safe' => true];
$files = Misc::getDirFiles($options);
natsort($files);
$last = preg_match($options['regex'], end($files), $matches) ? (int) $matches['patch'] : false;
if ($update) {
if ($last !== false && $this->_vers->sql->file->__toString() != $last) {
echo $this->out->primary("Updating latest patch file to " . $last);
$this->_vers->sql->file = $last;
$this->_changes |= self::UPDATED_SQL_FILE_LAST;
}
if ($this->_vers->sql->file->__toString() != $last) {
$this->_vers->sql->file = $last;
$this->_changes |= self::UPDATED_SQL_DB_PATCH;
}
}
return $last;
}
示例2: processPatches
public function processPatches(array $options = [])
{
$patched = 0;
$defaults = ['data' => nZEDb_RES . 'db' . DS . 'schema' . DS . 'data' . DS, 'ext' => 'sql', 'path' => nZEDb_RES . 'db' . DS . 'patches' . DS . $this->_DbSystem, 'regex' => '#^' . Misc::PATH_REGEX . '(?P<patch>\\d{4})~(?P<table>\\w+)\\.sql$#', 'safe' => true];
$options += $defaults;
$currentVersion = $this->settings->getSetting(['setting' => 'sqlpatch']);
if (!is_numeric($currentVersion)) {
exit("Bad sqlpatch value: '{$currentVersion}'\n");
}
$files = empty($options['files']) ? Misc::getDirFiles($options) : $options['files'];
if (count($files)) {
natsort($files);
$local = $this->pdo->isLocalDb() ? '' : 'LOCAL ';
$data = $options['data'];
echo $this->log->primary('Looking for unprocessed patches...');
foreach ($files as $file) {
$setPatch = false;
$fp = fopen($file, 'r');
$patch = fread($fp, filesize($file));
if (preg_match($options['regex'], str_replace('\\', '/', $file), $matches)) {
$patch = (int) $matches['patch'];
$setPatch = true;
} else {
if (preg_match('/UPDATE `?site`? SET `?value`? = \'?(?P<patch>\\d+)\'? WHERE `?setting`? = \'sqlpatch\'/i', $patch, $matches)) {
$patch = (int) $matches['patch'];
} else {
throw new \RuntimeException("No patch information available, stopping!!");
}
}
if ($patch > $currentVersion) {
echo $this->log->header('Processing patch file: ' . $file);
if ($options['safe'] && !$this->backedUp) {
$this->_backupDb();
}
$this->splitSQL($file, ['local' => $local, 'data' => $data]);
if ($setPatch) {
$this->pdo->queryExec("UPDATE settings SET value = '{$patch}' WHERE setting = 'sqlpatch';");
}
$patched++;
}
}
} else {
exit($this->log->error("\nHave you changed the path to the patches folder, or do you have the right permissions?\n"));
}
if ($patched === 0) {
echo $this->log->info("Nothing to patch, you are already on version {$currentVersion}");
}
return $patched;
}