本文整理汇总了PHP中Akeeba\Engine\Factory::getLog方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::getLog方法的具体用法?PHP Factory::getLog怎么用?PHP Factory::getLog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Akeeba\Engine\Factory
的用法示例。
在下文中一共展示了Factory::getLog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepare
protected function _prepare()
{
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Processing parameters");
// Get the DB connection parameters
if (is_array($this->_parametersArray)) {
$driver = array_key_exists('driver', $this->_parametersArray) ? $this->_parametersArray['driver'] : 'mysql';
$host = array_key_exists('host', $this->_parametersArray) ? $this->_parametersArray['host'] : '';
$port = array_key_exists('port', $this->_parametersArray) ? $this->_parametersArray['port'] : '';
$username = array_key_exists('username', $this->_parametersArray) ? $this->_parametersArray['username'] : '';
$username = array_key_exists('user', $this->_parametersArray) ? $this->_parametersArray['user'] : $username;
$password = array_key_exists('password', $this->_parametersArray) ? $this->_parametersArray['password'] : '';
$database = array_key_exists('database', $this->_parametersArray) ? $this->_parametersArray['database'] : '';
$prefix = array_key_exists('prefix', $this->_parametersArray) ? $this->_parametersArray['prefix'] : '';
}
if ($driver == 'mysql' && !function_exists('mysql_connect')) {
$driver = 'mysqli';
}
$options = array('driver' => $driver, 'host' => $host . ($port != '' ? ':' . $port : ''), 'user' => $username, 'password' => $password, 'database' => $database, 'prefix' => is_null($prefix) ? '' : $prefix);
$db = Factory::getDatabase($options);
$driverType = $db->getDriverType();
if ($driverType == 'mssql') {
$driverType = 'sqlsrv';
}
$className = '\\Akeeba\\Engine\\Dump\\Reverse\\' . ucfirst($driverType);
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Instanciating new reverse engineering database dump engine {$className}");
if (!class_exists($className, true)) {
$this->setState('error', 'Akeeba Engine does not have a reverse engineering dump engine for ' . $driverType . ' databases');
} else {
$this->_engine = new $className();
$this->_engine->setup($this->_parametersArray);
$this->_engine->callStage('_prepare');
$this->setState($this->_engine->getState(), $this->_engine->getError());
$this->propagateFromObject($this->_engine);
}
}
示例2: _prepare
protected function _prepare()
{
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Processing parameters");
$options = null;
// Get the DB connection parameters
if (is_array($this->_parametersArray)) {
$driver = array_key_exists('driver', $this->_parametersArray) ? $this->_parametersArray['driver'] : 'mysql';
$host = array_key_exists('host', $this->_parametersArray) ? $this->_parametersArray['host'] : '';
$port = array_key_exists('port', $this->_parametersArray) ? $this->_parametersArray['port'] : '';
$username = array_key_exists('username', $this->_parametersArray) ? $this->_parametersArray['username'] : '';
$username = array_key_exists('user', $this->_parametersArray) ? $this->_parametersArray['user'] : $username;
$password = array_key_exists('password', $this->_parametersArray) ? $this->_parametersArray['password'] : '';
$database = array_key_exists('database', $this->_parametersArray) ? $this->_parametersArray['database'] : '';
$prefix = array_key_exists('prefix', $this->_parametersArray) ? $this->_parametersArray['prefix'] : '';
$options = array('driver' => $driver, 'host' => $host . ($port != '' ? ':' . $port : ''), 'user' => $username, 'password' => $password, 'database' => $database, 'prefix' => is_null($prefix) ? '' : $prefix);
}
$db = Factory::getDatabase($options);
$driverType = $db->getDriverType();
$className = '\\Akeeba\\Engine\\Dump\\Native\\' . ucfirst($driverType);
// Check if we have a native dump driver
if (!class_exists($className, true)) {
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Native database dump engine {$className} not found; trying Reverse Engineering instead");
// Native driver nor found, I will try falling back to reverse engineering
$className = '\\Akeeba\\Engine\\Dump\\Reverse\\' . ucfirst($driverType);
}
if (!class_exists($className, true)) {
$this->setState('error', 'Akeeba Engine does not have a native dump engine for ' . $driverType . ' databases');
} else {
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Instanciating new native database dump engine {$className}");
$this->_engine = new $className();
$this->_engine->setup($this->_parametersArray);
$this->_engine->callStage('_prepare');
$this->setState($this->_engine->getState(), $this->_engine->getError());
}
}
示例3: stepDatabaseDump
/**
* Performs one more step of dumping database data
*
* @return void
*/
protected function stepDatabaseDump()
{
// We do not create any dump file, we will simply include the whole database file inside the backup
Factory::getLog()->log(LogLevel::INFO, "SQLite database detected, no SQL dump files will be created.");
$this->setState('postrun');
$this->setStep('');
$this->setSubstep('');
}
示例4: execute
/**
* Execute the JSON API task
*
* @param array $parameters The parameters to this task
*
* @return mixed
*
* @throws \RuntimeException In case of an error
*/
public function execute(array $parameters = array())
{
// Get the passed configuration values
$defConfig = array('tag' => 'remote');
$defConfig = array_merge($defConfig, $parameters);
$tag = (int) $defConfig['tag'];
$filename = Factory::getLog()->getLogFilename($tag);
return file_get_contents($filename);
}
示例5: updateMultipart
/**
* Updates the multipart status of the current backup attempt's statistics record
*
* @param int $multipart The new multipart status
*/
public function updateMultipart($multipart)
{
if ($this->multipart_lock) {
return;
}
Factory::getLog()->log(LogLevel::DEBUG, 'Updating multipart status to ' . $multipart);
// Cache this change and commit to db only after the backup is done, or failed
$registry = Factory::getConfiguration();
$registry->set('volatile.statistics.multipart', $multipart);
}
示例6: echoRawLog
public function echoRawLog()
{
$tag = $this->getState('tag', '');
echo "WARNING: Do not copy and paste lines from this file!\r\n";
echo "You are supposed to ZIP and attach it in your support forum post.\r\n";
echo "If you fail to do so, your support request will receive minimal priority.\r\n";
echo "\r\n";
echo "--- START OF RAW LOG --\r\n";
@readfile(Factory::getLog()->getLogFilename($tag));
// The at sign is necessary to skip showing PHP errors if the file doesn't exist or isn't readable for some reason
echo "--- END OF RAW LOG ---\r\n";
}
示例7: echoRawLog
/**
* Output the raw text log file to the standard output
*
* @return void
*/
public function echoRawLog()
{
$tag = $this->getState('tag', '');
echo "WARNING: Do not copy and paste lines from this file!\r\n";
echo "You are supposed to ZIP and attach it in your support forum post.\r\n";
echo "If you fail to do so, we will be unable to provide efficient support.\r\n";
echo "\r\n";
echo "--- START OF RAW LOG --\r\n";
// The at sign (silence operator) is necessary to prevent PHP showing a warning if the file doesn't exist or
// isn't readable for any reason.
@readfile(Factory::getLog()->getLogFilename($tag));
echo "--- END OF RAW LOG ---\r\n";
}
示例8: crc32_file_php512
/**
* Very efficient CRC32 calculation for PHP 5.1.2 and greater, requiring
* the 'hash' PECL extension
*
* @param string $filename Absolute filepath
*
* @return integer The CRC32
*/
protected function crc32_file_php512($filename)
{
// Detection of buggy PHP hosts
static $mustInvert = null;
if (is_null($mustInvert)) {
$test_crc = @hash('crc32b', 'test', false);
$mustInvert = strtolower($test_crc) == '0c7e7fd8';
// Normally, it's D87F7E0C :)
if ($mustInvert) {
Factory::getLog()->log(LogLevel::WARNING, 'Your server has a buggy PHP version which produces inverted CRC32 values. Attempting a workaround. ZIP files may appear as corrupt.');
}
}
$res = @hash_file('crc32b', $filename, false);
if ($mustInvert) {
// Workaround for buggy PHP versions (I think before 5.1.8) which produce inverted CRC32 sums
$res2 = substr($res, 6, 2) . substr($res, 4, 2) . substr($res, 2, 2) . substr($res, 0, 2);
$res = $res2;
}
$res = hexdec($res);
return $res;
}
示例9: onBeforeMain
/**
* The main page of the log viewer. It allows you to select a profile to display. When you do it displays the IFRAME
* with the actual log content and the button to download the raw log file.
*
* @return void
*/
public function onBeforeMain()
{
// Get a list of log names
/** @var Log $model */
$model = $this->getModel();
$this->logs = $model->getLogList();
$tag = $model->getState('tag');
if (empty($tag)) {
$tag = null;
}
$this->tag = $tag;
// Let's check if the file is too big to display
if ($this->tag) {
$file = Factory::getLog()->getLogFilename($this->tag);
if (@file_exists($file)) {
$this->logSize = filesize($file);
$this->logTooBig = $this->logSize >= self::bigLogSize;
}
}
if ($this->logTooBig) {
$src = 'index.php?option=com_akeeba&view=Log&task=download&attachment=0&tag=' . urlencode($this->tag);
$js = <<<JS
;// Prevent broken 3PD Javascript from causing errors
akeeba.jQuery(document).ready(function (\$){
\$('#showlog').click(function(){
\$('<iframe width="99%" src="{$src}" height="400px"/>').appendTo('.iframe-holder');
\$(this).hide();
})
});
JS;
$this->addJavascriptInline($js);
}
$this->getProfileIdAndName();
JHtml::_('formbehavior.chosen');
}
示例10: _createNewPart
/**
* Creates a new part for the spanned archive
*
* @param bool $finalPart Is this the final archive part?
*
* @return bool True on success
*/
protected function _createNewPart($finalPart = false)
{
// Close any open file pointers
if (is_resource($this->fp)) {
$this->_fclose($this->fp);
}
if (is_resource($this->cdfp)) {
$this->_fclose($this->cdfp);
}
// Remove the just finished part from the list of resumable offsets
$this->_removeFromOffsetsList($this->_dataFileName);
// Set the file pointers to null
$this->fp = null;
$this->cdfp = null;
// Push the previous part if we have to post-process it immediately
$configuration = Factory::getConfiguration();
if ($configuration->get('engine.postproc.common.after_part', 0)) {
// The first part needs its header overwritten during archive
// finalization. Skip it from immediate processing.
if ($this->_currentFragment != 1) {
$this->finishedPart[] = $this->_dataFileName;
}
}
$this->_totalFragments++;
$this->_currentFragment = $this->_totalFragments;
if ($finalPart) {
$this->_dataFileName = $this->_dataFileNameBase . '.jpa';
} else {
$this->_dataFileName = $this->_dataFileNameBase . '.j' . sprintf('%02d', $this->_currentFragment);
}
Factory::getLog()->log(LogLevel::INFO, 'Creating new JPA part #' . $this->_currentFragment . ', file ' . $this->_dataFileName);
$statistics = Factory::getStatistics();
$statistics->updateMultipart($this->_totalFragments);
// Try to remove any existing file
@unlink($this->_dataFileName);
// Touch the new file
$result = @touch($this->_dataFileName);
if (function_exists('chmod')) {
chmod($this->_dataFileName, 0666);
}
// Try to write 6 bytes to it
if ($result) {
$result = @file_put_contents($this->_dataFileName, 'AKEEBA') == 6;
}
if ($result) {
@unlink($this->_dataFileName);
$result = @touch($this->_dataFileName);
if (function_exists('chmod')) {
chmod($this->_dataFileName, 0666);
}
}
return $result;
}
示例11:
/**
* Implements the _run() abstract method
*/
function _run()
{
if ($this->getState() == 'postrun') {
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . " :: Already finished");
$this->setStep('');
$this->setSubstep('');
} else {
$this->setState('running');
}
// Try to step the archiver
$archive = Factory::getArchiverEngine();
$ret = $archive->transformJPA($this->xformIndex, $this->offset);
// Error propagation
$this->propagateFromObject($archive);
if ($ret !== false && $archive->getError() == '') {
$this->offset = $ret['offset'];
$this->xformIndex = $ret['index'];
$this->setStep($ret['filename']);
}
// Check for completion
if ($ret['done']) {
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . ":: archive is initialized");
$this->setState('finished');
}
// Calculate percentage
$this->runningSize += $ret['chunkProcessed'];
if ($ret['filesize'] > 0) {
$this->progress = $this->runningSize / $ret['filesize'];
}
}
示例12: forceRefreshTokens
/**
* Forcibly refresh the Google Drive tokens
*
* @return void
*/
protected function forceRefreshTokens()
{
// Retrieve engine configuration data
$config = Factory::getConfiguration();
$pingResult = $this->googleDrive->ping(true);
Factory::getLog()->log(LogLevel::DEBUG, __CLASS__ . '::' . __METHOD__ . " - Google Drive tokens were forcibly refreshed");
$config->set('engine.postproc.googledrive.access_token', $pingResult['access_token'], false);
$profile_id = Platform::getInstance()->get_active_profile();
Platform::getInstance()->save_configuration($profile_id);
}
示例13: enforce_min_exec_time
/**
* Enforce the minimum execution time
*
* @param bool $log Should I log what I'm doing? Default is true.
* @param bool $serverSideSleep Should I sleep on the server side? If false we return the amount of time to wait in msec
*
* @return int Wait time to reach min_execution_time in msec
*/
public function enforce_min_exec_time($log = true, $serverSideSleep = true)
{
// Try to get a sane value for PHP's maximum_execution_time INI parameter
if (@function_exists('ini_get')) {
$php_max_exec = @ini_get("maximum_execution_time");
} else {
$php_max_exec = 10;
}
if ($php_max_exec == "" || $php_max_exec == 0) {
$php_max_exec = 10;
}
// Decrease $php_max_exec time by 500 msec we need (approx.) to tear down
// the application, as well as another 500msec added for rounding
// error purposes. Also make sure this is never gonna be less than 0.
$php_max_exec = max($php_max_exec * 1000 - 1000, 0);
// Get the "minimum execution time per step" Akeeba Backup configuration variable
$configuration = Factory::getConfiguration();
$minexectime = $configuration->get('akeeba.tuning.min_exec_time', 0);
if (!is_numeric($minexectime)) {
$minexectime = 0;
}
// Make sure we are not over PHP's time limit!
if ($minexectime > $php_max_exec) {
$minexectime = $php_max_exec;
}
// Get current running time
$elapsed_time = $this->getRunningTime() * 1000;
$clientSideSleep = 0;
// Only run a sleep delay if we haven't reached the minexectime execution time
if ($minexectime > $elapsed_time && $elapsed_time > 0) {
$sleep_msec = $minexectime - $elapsed_time;
if (!$serverSideSleep) {
Factory::getLog()->log(LogLevel::DEBUG, "Asking client to sleep for {$sleep_msec} msec");
$clientSideSleep = $sleep_msec;
} elseif (function_exists('usleep')) {
if ($log) {
Factory::getLog()->log(LogLevel::DEBUG, "Sleeping for {$sleep_msec} msec, using usleep()");
}
usleep(1000 * $sleep_msec);
} elseif (function_exists('time_nanosleep')) {
if ($log) {
Factory::getLog()->log(LogLevel::DEBUG, "Sleeping for {$sleep_msec} msec, using time_nanosleep()");
}
$sleep_sec = floor($sleep_msec / 1000);
$sleep_nsec = 1000000 * ($sleep_msec - $sleep_sec * 1000);
time_nanosleep($sleep_sec, $sleep_nsec);
} elseif (function_exists('time_sleep_until')) {
if ($log) {
Factory::getLog()->log(LogLevel::DEBUG, "Sleeping for {$sleep_msec} msec, using time_sleep_until()");
}
$until_timestamp = time() + $sleep_msec / 1000;
time_sleep_until($until_timestamp);
} elseif (function_exists('sleep')) {
$sleep_sec = ceil($sleep_msec / 1000);
if ($log) {
Factory::getLog()->log(LogLevel::DEBUG, "Sleeping for {$sleep_sec} seconds, using sleep()");
}
sleep($sleep_sec);
}
} elseif ($elapsed_time > 0) {
// No sleep required, even if user configured us to be able to do so.
if ($log) {
Factory::getLog()->log(LogLevel::DEBUG, "No need to sleep; execution time: {$elapsed_time} msec; min. exec. time: {$minexectime} msec");
}
}
return $clientSideSleep;
}
示例14: resetState
/**
* Resets the engine state, wiping out any pending backups and/or stale
* temporary data.
*
* @param array $config Configuration parameters for the reset operation
*/
public static function resetState($config = array())
{
$default_config = array('global' => true, 'log' => false, 'maxrun' => 180);
$config = (object) array_merge($default_config, $config);
// Pause logging if so desired
if (!$config->log) {
Factory::getLog()->pause();
}
$originTag = null;
if (!$config->global) {
// If we're not resetting globally, get a list of running backups per tag
$originTag = Platform::getInstance()->get_backup_origin();
}
// Cache the factory before proceeding
$factory = self::serialize();
$runningList = Platform::getInstance()->get_running_backups($originTag);
// Origins we have to clean
$origins = array(Platform::getInstance()->get_backup_origin());
// 1. Detect failed backups
if (is_array($runningList) && !empty($runningList)) {
// The current timestamp
$now = time();
// Mark running backups as failed
foreach ($runningList as $running) {
if (empty($originTag)) {
// Check the timestamp of the log file to decide if it's stuck,
// but only if a tag is not set
$tstamp = Factory::getLog()->getLastTimestamp($running['origin']);
if (!is_null($tstamp)) {
// We can only check the timestamp if it's returned. If not, we assume the backup is stale
$difference = abs($now - $tstamp);
// Backups less than maxrun seconds old are not considered stale (default: 3 minutes)
if ($difference < $config->maxrun) {
continue;
}
}
}
$filenames = Factory::getStatistics()->get_all_filenames($running, false);
$totalSize = 0;
// Process if there are files to delete...
if (!is_null($filenames)) {
// Delete the failed backup's archive, if exists
foreach ($filenames as $failedArchive) {
if (file_exists($failedArchive)) {
$totalSize += (int) @filesize($failedArchive);
Platform::getInstance()->unlink($failedArchive);
}
}
}
// Mark the backup failed
if (!$running['total_size']) {
$running['total_size'] = $totalSize;
}
$running['status'] = 'fail';
$running['multipart'] = 0;
$dummy = null;
Platform::getInstance()->set_or_update_statistics($running['id'], $running, $dummy);
$backupId = isset($running['backupid']) ? '.' . $running['backupid'] : '';
$origins[] = $running['origin'] . $backupId;
}
}
if (!empty($origins)) {
$origins = array_unique($origins);
foreach ($origins as $originTag) {
self::loadState($originTag);
// Remove temporary files
Factory::getTempFiles()->deleteTempFiles();
// Delete any stale temporary data
self::getFactoryStorage()->reset($originTag);
}
}
// Reload the factory
self::unserialize($factory);
unset($factory);
// Unpause logging if it was previously paused
if (!$config->log) {
Factory::getLog()->unpause();
}
}
示例15: postProcessDonePartFile
/**
* @param \Akeeba\Engine\Archiver\Base $archiver
* @param \Akeeba\Engine\Configuration $configuration
*
* @return bool
*/
protected function postProcessDonePartFile(\Akeeba\Engine\Archiver\Base $archiver, \Akeeba\Engine\Configuration $configuration)
{
$filename = array_shift($archiver->finishedPart);
Factory::getLog()->log(LogLevel::INFO, 'Preparing to post process ' . basename($filename));
// Add this part's size to the volatile storage
$volatileTotalSize = $configuration->get('volatile.engine.archiver.totalsize', 0);
$volatileTotalSize += (int) @filesize($filename);
$configuration->set('volatile.engine.archiver.totalsize', $volatileTotalSize);
$post_proc = Factory::getPostprocEngine();
$result = $post_proc->processPart($filename);
$this->propagateFromObject($post_proc);
if ($result === false) {
$this->setWarning('Failed to process file ' . basename($filename));
} else {
Factory::getLog()->log(LogLevel::INFO, 'Successfully processed file ' . basename($filename));
}
// Should we delete the file afterwards?
if ($configuration->get('engine.postproc.common.delete_after', false) && $post_proc->allow_deletes && $result !== false) {
Factory::getLog()->log(LogLevel::DEBUG, 'Deleting already processed file ' . basename($filename));
Platform::getInstance()->unlink($filename);
}
if ($post_proc->break_after && $result !== false) {
$configuration->set('volatile.breakflag', true);
return true;
}
// This is required to let the backup continue even after a post-proc failure
$this->resetErrors();
$this->setState('running');
return false;
}