/** * Implements the _run() abstract method */ function _run() { if ($this->_getState() == 'postrun') { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, __CLASS__ . " :: Already finished"); $this->_Step = ''; $this->_Substep = ''; } else { $this->setState('running'); $this->_isRunning = true; $this->_hasRan = false; } // Try to step the archiver $cube =& JoomlapackCUBE::getInstance(); $archive =& $cube->provisioning->getArchiverEngine(); $ret = $archive->transformJPA($this->_offset); // Error propagation if ($ret === false || $archive->getError() != '') { $this->setError($archive->getError()); } else { $this->_offset = $ret['offset']; $this->_Step = $ret['filename']; } // Check for completion if ($ret['done']) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, __CLASS__ . ":: archive is initialized"); $this->_hasRan = true; $this->_isRunning = false; } }
/** * Step through the backup, informing user of the progress */ function step() { // Enforce raw mode - I need to be in full control! $format = JRequest::getCmd('format', 'html'); if ($format != 'raw') { $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=light&format=raw'); parent::redirect(); } else { JRequest::setVar('tpl', 'step'); jpimport('core.cube'); $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); if ($array['Error'] != '') { // An error occured $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=light&format=raw&task=error&error=' . $array['Error']); parent::redirect(); } elseif ($array['HasRun'] == 1) { // All done $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=light&format=raw&task=done'); parent::redirect(); } else { $cube->tick(); $cube->save(); parent::display(); } } }
function addWarning($warning) { jpimport('core.cube'); jpimport('helpers.backup', true); $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning($warning); $cube->save(); return; }
/** * Step through the backup * @return */ function step() { // Check permissions $this->_checkPermissions(); // Set the profile $this->_setProfile(); jpimport('core.cube'); $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); if ($array['Error'] == '' && $array['HasRun'] != 1) { $cube->tick(); $cube->save(); } // Return the JSON output parent::display(false); }
function step() { jpimport('core.cube'); $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); if ($array['Error'] != '') { // An error occured die('500 ERROR -- ' . $array['Error']); } elseif ($array['HasRun'] == 1) { // All done die('200 OK'); } else { $cube->tick(); $cube->save(); $this->setRedirect(JURI::base() . 'index.php?option=com_joomlapack&view=backup&task=step&key=' . JRequest::getVar('key') . '&profile=' . JRequest::getInt('profile', 1) . '&format=raw'); } }
function _processCUBE() { jpimport('core.cube'); $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); if ($array['Error'] != '') { $action = 'error'; $message = $array['Error']; } elseif ($array['HasRun'] == 1) { $action = 'finished'; $message = ''; } else { $action = 'step'; $message = ''; } return array($action, $message); }
function echoHTML() { jpimport('helpers.lang'); $errorStack = array(); // Initialize an errors stack // Cleanup locks jpimport('classes.core.cube'); JoomlapackCUBE::cleanup(); // Test for the existence of a default temporary folder if (!is_dir(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup')) { // Temp dir doesn't exist; try to create one if (!@mkdir(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup')) { $errorStack[] = JoomlapackLangManager::_('UNLOCK_CANTCREATEDIR'); } else { // Try creating a deafult .htaccess $htaccess = <<<END Deny from all END; $fp = @fopen(JPATH_COMPONENT_ADMINISTRATOR . DS . 'backup' . DS . '.htaccess'); if ($fp === false) { $errorStack[] = JoomlapackLangManager::_('UNLOCK_CANTCREATEHTACCESS'); } else { @fputs($fp, $htaccess); @fclose($fp); } } } // Get some more HTML fragments echo JoomlapackCommonHTML::getAdminHeadingHTML(JoomlapackLangManager::_('CPANEL_UNLOCK')); ?> <p> <?php if (count($errorStack) == 0) { echo JoomlapackLangManager::_('UNLOCK_DONE'); } else { foreach ($errorStack as $error) { echo "<p class=\"error\">{$error}</p>"; } } ?> </p> <?php }
function display($tpl = null) { $task = JRequest::getCmd('task', 'default'); switch ($task) { case 'step': $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); $this->assign('cube', $array); break; case 'error': $this->assign('errormessage', JRequest::getVar('error', '')); break; case 'done': break; case 'default': default: $model =& $this->getModel(); $this->assignRef('profilelist', $model->getProfiles()); break; } parent::display(JRequest::getCmd('tpl', null)); }
function &getFolders($folder) { // Initialize variables $arr = array(); $false = false; if (!is_dir($folder)) { return $false; } $counter = 0; $registry =& JoomlapackModelRegistry::getInstance(); $maxCounter = $registry->get('mnMaxFragmentFiles', 50) * 2; $cube =& JoomlapackCUBE::getInstance(); $allowBreakflag = $cube->operationCounter != 0; $handle = @opendir($folder); // If directory is not accessible, just return FALSE if ($handle === FALSE) { JoomlapackLogger::WriteLog(_JP_LOG_WARNING, 'Unreadable directory ' . $dirName); return $false; } while (($file = @readdir($handle)) !== false && !$this->BREAKFLAG) { if ($file != '.' && $file != '..') { $dir = $folder . DS . $file; $isDir = is_dir($dir); if ($isDir) { $data = JPISWINDOWS ? JoomlapackHelperUtils::TranslateWinPath($dir) : $dir; if ($data) { $arr[] = $data; } } } $counter++; if ($counter >= $maxCounter) { $this->BREAKFLAG = $allowBreakflag; } } @closedir($handle); return $arr; }
/** * Displays the Control Panel (main page) * Accessible at index.php?option=com_joomlapack * */ function display() { $registry =& JoomlapackModelRegistry::getInstance(); // FIX 2.1.b2 - Disabled the nag screen because of incompatibility with some servers /* // Make sure the user has seen the license nag screen $nagscreen = $registry->get('nagscreen',false); if(!$nagscreen) { $this->setRedirect(JURI::base().'index.php?option=com_joomlapack&view=nag' ); return; } */ // Invalidate stale backups jpimport('core.cube'); JoomlapackCUBE::reset(); // If this is the Easy Mode, force switch to profile #1 (default profile) if ($registry->get('easymode', false)) { $session =& JFactory::getSession(); $session->set('profile', 1, 'joomlapack'); } // Display the panel parent::display(); }
/** * Smart step algorithm. Runs the tick() function until we have consumed 75% * of the maximum_execution_time (minus 1 seconds) within this procedure. If * the available time is less than 1 seconds, it defaults to multi-step. * @param JoomlapackCUBEParts $object The CUBE part to step * @return integer 0 if more work is to be done, 1 if we finished correctly, * 2 if error eccured. * @access private */ function _algoSmartStep(&$object) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Smart Stepping"); if ($this->_maxExecTime <= mnMinimumExectime) { // If the available time is less than the trigger value, switch to // multi-step return $this->_algoMultiStep($object); } else { // All checks pass, this is a SmartStep-enabled case $runTime = 0; $finished = false; $error = false; $breakFlag = false; // BREAKFLAG is optionally passed by domains to force-break current operation $opsRemaining = max(1, mnMaxOpsPerStep); // Run at least one step, even if mnMaxOpsPerStep=0 // Loop until time's up, we're done or an error occured, or BREAKFLAG is set while ($this->getTimeLeft() > 0 && !$finished && !$error && $opsRemaining > 0 && !$breakFlag) { $opsRemaining--; // Decrease the number of possible available operations count $result = $object->tick(); // Advance operation counter $cube =& JoomlapackCUBE::getInstance(); $cube->operationCounter++; $currentOperationNumber = $cube->operationCounter; unset($cube); // Process return array $this->currentDomain = $result['Domain']; $this->currentStep = $result['Step']; $this->currentSubstep = $result['Substep']; // Check for BREAKFLAG if (isset($result['BREAKFLAG'])) { $breakFlag = $result['BREAKFLAG']; } // Process errors $error = false; if ($object->getError()) { $error = true; $this->setError($object->getError()); $result['Error'] = $this->getError(); } // Check if the backup procedure should finish now $finished = $error ? true : !$result['HasRun']; // Log operation end JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, '----- Finished operation ' . $currentOperationNumber . ' ------'); } // while // Return the result if (!$error) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Successful Smart algorithm on " . get_class($object)); } else { JoomlapackLogger::WriteLog(_JP_LOG_ERROR, "Failed Smart algorithm on " . get_class($object)); } // @todo Warnings propagation return $error ? 2 : ($finished ? 1 : 0); } }
function _createNewPart($finalPart = false) { $this->_totalFragments++; $this->_currentFragment = $this->_totalFragments; if ($finalPart) { $this->_dataFileName = $this->_dataFileNameBase . '.jpa'; } else { $this->_dataFileName = $this->_dataFileNameBase . '.j' . sprintf('%02d', $this->_currentFragment); } JoomlapackLogger::WriteLog(_JP_LOG_INFO, 'Creating new JPA part #' . $this->_currentFragment . ', file ' . $this->_dataFileName); // Inform CUBE that we have chenged the multipart number $cube =& JoomlapackCUBE::getInstance(); $cube->updateMultipart($this->_totalFragments); // Try to remove any existing file @unlink($this->_dataFileName); // Touch the new file return @touch($this->_dataFileName); }
/** * Starts a backup in JS redirects mode * */ function start() { $document =& JFactory::getDocument(); JRequest::setVar('tpl', 'start'); $description = JRequest::getString('description'); $comment = JRequest::getString('comment'); jpimport('core.cube'); JoomlapackCUBE::reset(); $cube =& JoomlapackCUBE::getInstance(); $cube->start($description, $comment); $cube->save(); parent::display(); }
/** * Runs the CUBE tick * * @param integer $forceStart When set to 1 it forces a new instance of the CUBE to be created * * @return array Status information from the CUBE */ function _do($forceStart = 0) { global $CUBE; if ($forceStart > 0) { $this->_checkCollision(); // Collision detection $CUBE =& JoomlapackCUBE::getInstance(true, false); } else { $CUBE =& JoomlapackCUBE::getInstance(false); } $ret = $CUBE->tick(); $CUBE->save(); return $ret; }
/** * Transforms a JPA archive (containing an installer) to the native archive format * of the class. It actually extracts the source JPA in memory and instructs the * class to include each extracted file. * * @param int $offset The source JPA archive's offset to use * @return boolean False if an error occured, true otherwise * @access protected */ function transformJPA($offset) { // Do we have to open the file? if (!$this->_xform_fp) { // 2.3: Try to use sane default if the indicated installer doesn't exist if (!file_exists($this->_xform_source) && basename($this->_xform_source) != 'jpi4.jpa') { $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning(__CLASS__ . ":: Selected embedded installer not found, using JPI4 instead"); $this->_xform_source = dirname($this->_xform_source) . DS . 'jpi4.jpa'; } // Try opening the file if (file_exists($this->_xform_source)) { $this->_xform_fp = @fopen($this->_xform_source, 'r'); if ($this->_xform_fp === false) { //JoomlapackLogger::WriteLog(_JP_LOG_ERROR , __CLASS__ . ":: Can't seed archive with installer package ".$this->_xform_source); $this->setError(__CLASS__ . ":: Can't seed archive with installer package " . $this->_xform_source); return false; } } else { //JoomlapackLogger::WriteLog(_JP_LOG_ERROR , __CLASS__ . ":: Installer package ".$this->_xform_source." does not exist!"); $this->setError(__CLASS__ . ":: Installer package " . $this->_xform_source . " does not exist!"); return false; } } if (!$offset) { // First run detected! JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, 'Initializing with JPA package '); $offset = 0; // Skip over the header and check no problem exists $offset = $this->_xformReadHeader(); if ($offset === false) { $this->setError('JPA package file was not read'); return false; // Oops! The package file doesn't exist or is corrupt } } $ret =& $this->_xformExtract($offset); if (is_array($ret)) { $offset = $ret['offset']; if (!$ret['skip'] && !$ret['done']) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, ' Adding ' . $ret['filename'] . '; Next offset:' . $offset); $this->addVirtualFile($ret['filename'], '', $ret['data']); if ($this->getError()) { return false; } } else { $reason = $ret['done'] ? 'Done' : ' Skipping ' . $ret['filename']; JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, $reason); } } else { $this->setError('JPA extraction returned FALSE'); return false; } if ($ret['done']) { // We are finished! Close the file fclose($this->_xform_fp); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, 'Initializing with JPA package has finished'); } return $ret; }
function &getFolders($folder) { // Was the breakflag set BEFORE starting? -- This workaround is required due to PHP5 defaulting to assigning variables by reference $breakflag_before_process = $this->BREAKFLAG ? true : false; // Reset break flag before continuing $this->BREAKFLAG = false; // Initialize variables $arr = array(); $false = false; if (!is_dir($folder)) { return $false; } $counter = 0; $registry =& JoomlapackModelRegistry::getInstance(); $maxCounter = $registry->get('mnMaxFragmentFiles', 50) * 2; $cube =& JoomlapackCUBE::getInstance(); $allowBreakflag = $cube->operationCounter != 0 && !$breakflag_before_process; $handle = @opendir($folder); // If directory is not accessible, just return FALSE if ($handle === FALSE) { $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning('Unreadable directory ' . $folder); return $false; } while (($file = @readdir($handle)) !== false && !$this->BREAKFLAG) { if ($file != '.' && $file != '..') { // # Fix 2.4: Do not add DS if we are on the site's root and it's an empty string $ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DS ? '' : DS; $dir = $folder . $ds . $file; $isDir = is_dir($dir); if ($isDir) { $data = JPISWINDOWS ? JoomlapackHelperUtils::TranslateWinPath($dir) : $dir; if ($data) { $arr[] = $data; } } } $counter++; if ($counter >= $maxCounter) { $this->BREAKFLAG = $allowBreakflag; } } @closedir($handle); return $arr; }
/** * Populates _databaseList with the list of databases in the settings * */ function _getDatabaseList() { /* * Logic: * Add an entry for the Joomla! database * If we are in DB Only mode, return * Otherwise, itterate the configured databases and add them if and only if all settings are populated */ // Cleanup the _databaseList array $this->_databaseList = array(); // Add a new record for the core Joomla! database $entry = array('isJoomla' => true, 'useFilters' => true, 'host' => '', 'port' => '', 'username' => '', 'password' => '', 'database' => '', 'dumpFile' => ''); $this->_databaseList[] = $entry; $cube =& JoomlapackCUBE::getInstance(); if ($cube->_OnlyDBMode) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDomainDBBackup :: Skipping extra databases definitions"); return; } $extraDefs = JoomlapackHelperFiltertable::getInclusionList('multidb'); if (count($extraDefs) > 0) { foreach ($extraDefs as $def) { $entry = array('isJoomla' => false, 'useFilters' => false, 'host' => $def['host'], 'port' => $def['port'], 'username' => $def['username'], 'password' => $def['password'], 'database' => $def['database'], 'dumpFile' => $def['id'] . '-' . $def['database'] . '.sql'); $this->_databaseList[] = $entry; } } }
function _getDirContents_opendir($dirName, $shellFilter = null) { $handle = @opendir($dirName); // If directory is not accessible, just return FALSE if ($handle === FALSE) { $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning('Unreadable directory ' . $dirName); $false = false; return $false; } // Initialize return array $retArray = array(); // FIX 1.2.1 -- Remove trailing slash -- Rolled back as of 2.4.b2 # if( (substr($dirName,-1,1) == '/') || (substr($dirName,-1,1) == '\\')) $dirName = substr($dirName,0,strlen($dirName)-1); // Fix 2.4.b2: Do not add double slash $ds = $dirName == '' || $dirName == '/' || @substr($dirName, -1) == '/' || @substr($dirName, -1) == DS ? '' : '/'; while (!(($filename = readdir($handle)) === false)) { $match = is_null($shellFilter); $match = !$match ? fnmatch($shellFilter, $filename) : true; if ($match) { $retArray[] = JPISWINDOWS ? JoomlapackHelperUtils::TranslateWinPath($dirName . $ds . $filename) : $dirName . $ds . $filename; } } @closedir($handle); return $retArray; }
/** * Post work clean-up of files & database * @access private */ function cleanup() { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE Cleanup started"); // 1. Cleanup leftover temporary files, if present JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Removing leftover temporary files"); JoomlapackCUBE::deleteTempFiles(); // 2. Remove leftover packvars JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Removing locks and leftover database variables"); JoomlapackTables::DeleteMultipleVars('%'); // Removes all packvars }
/** * Find where to store the backup files */ function _getBackupFilePaths() { $configuration =& JoomlapackModelRegistry::getInstance(); switch ($configuration->get('BackupType')) { case 'dbonly': // On DB Only backups we use different naming, no matter what's the setting JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Only dump database mode detected"); // Fix 2.0: Backup file name MUST be taken from the statitics record! $cube =& JoomlapackCUBE::getInstance(); $statID = $cube->_statID; $statModel = new JoomlapackModelStatistics($statID); $statModel->setId($statID); $statRecord =& $statModel->getStatistic(); $this->_tempFile = $statRecord->absolute_path; $this->_saveAsName = ''; break; case 'full': if ($this->_dumpFile != '') { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Forced filename using dumpFile found."); // If the dumpFile was set, forcibly use this value $this->_tempFile = JoomlapackCUBETempfiles::registerTempFile(dechex(crc32(microtime() . $this->_dumpFile))); $this->_saveAsName = 'installation/sql/' . $this->_dumpFile; } else { if ($this->_isJoomla) { // Joomla! Core Database, use the JoomlaPack way of figuring out the filenames JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Core database"); $this->_tempFile = JoomlapackCUBETempfiles::registerTempFile(dechex(crc32(microtime() . 'joomla.sql'))); $this->_saveAsName = 'installation/sql/joomla.sql'; } else { // External databases, we use the database's name JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: External database"); $this->_tempFile = JoomlapackCUBETempfiles::registerTempFile(dechex(crc32(microtime() . $this->_database . '.sql'))); $this->_saveAsName = 'installation/sql/' . $this->_database . '.sql'; } } break; case 'extradbonly': if ($this->_dumpFile != '') { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Forced filename using dumpFile found."); // If the dumpFile was set, forcibly use this value $this->_tempFile = JoomlapackCUBETempfiles::registerTempFile(dechex(crc32(microtime() . $this->_dumpFile))); $this->_saveAsName = $this->_dumpFile; } else { if ($this->_isJoomla) { // Joomla! Core Database, use the JoomlaPack way of figuring out the filenames JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Core database"); $this->_tempFile = JoomlapackCUBETempfiles::registerTempFile(dechex(crc32(microtime() . 'joomla.sql'))); $this->_saveAsName = 'joomla.sql'; } else { // External databases, we use the database's name JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: External database"); $this->_tempFile = JoomlapackCUBETempfiles::registerTempFile(dechex(crc32(microtime() . $this->_database . '.sql'))); $this->_saveAsName = $this->_database . '.sql'; } } break; } JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDomainDBBackup :: SQL temp file is " . $this->_tempFile); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDomainDBBackup :: SQL file location in archive is " . $this->_saveAsName); }
/** * Implements the _finalize() abstract method * */ function _finalize() { $this->setState('finished'); // If we are in db backup mode, don't create a databases.ini $configuration =& JoomlapackModelRegistry::getInstance(); $onlydb = $configuration->get('BackupType') == 'dbonly'; if ($onlydb) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBEDomainDBBackup :: Skipping databases.ini"); return; } JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBEDomainDBBackup :: Creating databases.ini"); // Create a new string $databasesINI = ''; // Loop through databases list foreach ($this->_databaseList as $definition) { // Joomla! core database comes with no parameters; we must retrieve them if ($definition['isJoomla']) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBEDomainDBBackup :: Adding Joomla definition"); $conf =& JFactory::getConfig(); $definition['host'] = $conf->getValue('config.host'); $definition['username'] = $conf->getValue('config.user'); $definition['password'] = $conf->getValue('config.password'); $definition['database'] = $conf->getValue('config.db'); $definition['prefix'] = $conf->getValue('config.dbprefix'); $definition['dbtype'] = $conf->getValue('config.dbtype'); $definition['dumpFile'] = 'joomla.sql'; } else { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBEDomainDBBackup :: Adding extra database definition"); $definition['prefix'] = ''; } $section = basename($definition['dumpFile']); $databasesINI .= <<<ENDDEF [{$section}] dbname = "{$definition['database']}" sqlfile = "{$definition['dumpFile']}" dbhost = "{$definition['host']}" dbuser = "******" dbpass = "******" prefix = "{$definition['prefix']}" ENDDEF; } // BEGIN FIX 1.2 Stable -- databases.ini isn't written on disk JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackCUBEDomainDBBackup :: Writing databases.ini contents"); $cube =& JoomlapackCUBE::getInstance(); $provisioning =& $cube->getProvisioning(); $archiver =& $provisioning->getArchiverEngine(); $virtualLocation = $configuration->get('BackupType') == 'extradbonly' ? '' : 'installation/sql'; $archiver->addVirtualFile('databases.ini', $virtualLocation, $databasesINI); // On extradbonly mode, we have to finalize the archive as well if ($configuration->get('BackupType') == 'extradbonly') { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Finalizing database dump archive"); $archiver->finalize(); } // Error propagation if ($archiver->getError()) { $this->setError($archiver->getError()); return false; } }
/** * There used to be a workaround for large files under PHP4. However, it never * really worked, so it is removed and a warning is posted instead. * * @param string $filename * @param integer $JoomlapackPackerZIP_CHUNK_SIZE * @return integer */ function crc32_file_php4($filename, $JoomlapackPackerZIP_CHUNK_SIZE) { $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning("Function hash_file not detected processing the 'large'' file {$filename}; it will appear as seemingly corrupt in the archive. Only the CRC32 is invalid, though. Please read our forum announcement for explanation of this message."); return 0; }
/** * Steps the CUBE, performing yet another small chunk of backup work necessary * */ function tick() { $this->_enforce_minexectime(true); if (!$this->_initialised) { $this->setError(JText::_('CUBE_NOTINIT')); } elseif (!$this->getError() && !$this->_isFinished) { // Initialize operation counter $this->operationCounter = 0; // Advance step counter $this->stepCounter++; // Log step start number JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, '====== Starting Step number ' . $this->stepCounter . ' ======'); $algorithmRunner =& JoomlapackCUBEAlgorunner::getInstance(); $algo = $algorithmRunner->selectAlgorithm($this->_activeDomain); switch ($this->_activeDomain) { case 'init': case 'finale': $ret = 1; break; default: if (!is_object($this->_object)) { $algorithmRunner->setError('Current object is not an object on ' . $this->_activeDomain); $ret = 2; } else { $ret = $algorithmRunner->runAlgorithm($algo, $this->_object); $this->_currentStep = $algorithmRunner->currentStep; $this->_currentSubstep = $algorithmRunner->currentSubstep; } break; } switch ($ret) { case 0: // more work to do, return OK JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: More work required in domain '" . $this->_activeDomain); break; case 1: // Engine part finished JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: Domain '" . $this->_activeDomain . "' has finished"); $this->_getNextObject(); if ($this->_activeDomain == "finale") { // We have finished the whole process. JoomlapackCUBE::_finalise(); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: Just finished"); } break; case 2: // An error occured... JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: Error occured in domain '" . $this->_activeDomain); $this->setError($algorithmRunner->getError()); $this->reset(); //$this->_isFinished = true; break; } } // Log step end JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, '====== Finished Step number ' . $this->stepCounter . ' ======'); $this->_enforce_minexectime(false); return $this->_makeCUBEArray(); }
/** * Try to pack some files in the $_fileList, restraining ourselves not to reach the max * number of files or max fragment size while doing so. If this process is over and we are * left without any more files, reset $_doneScanning to false in order to instruct the class * to scan for more files. * * @return bool True if there were files packed, false otherwise (empty filelist) */ function _packSomeFiles() { if (count($this->_fileList) == 0) { // No files left to pack -- This should never happen! We catch this condition at the end of this method! $this->_doneScanning = false; return false; } else { $packedSize = 0; $numberOfFiles = 0; $cube =& JoomlapackCUBE::getInstance(); $provisioning =& $cube->getProvisioning(); $archiver =& $provisioning->getArchiverEngine(); $algoRunner =& JoomlapackCUBEAlgorunner::getInstance(); list($usec, $sec) = explode(" ", microtime()); $opStartTime = (double) $usec + (double) $sec; while (count($this->_fileList) > 0 && $packedSize <= JPMaxFragmentSize && $numberOfFiles <= JPMaxFragmentFiles) { $file = @array_shift($this->_fileList); $size = @filesize($file); // JoomlaPack 2.2: Anticipatory fragment size algorithm if ($packedSize + $size > JPMaxFragmentSize && $numberOfFiles > 0) { // Adding this file exceeds the fragment's capacity. Furthermore, it's NOT // the first file we tried to pack. Therefore, push it back to the list. array_unshift($this->_fileList, $file); // If the file is bigger than a whole fragment's allowed size, break the step // to avoid potential timeouts if ($size > JPMaxFragmentSize) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Breaking step _before_ large file: " . $file . " - size: " . $size); $this->setBreakFlag(); } // Mark that we are not done packing files $this->_doneScanning = true; return true; } // JoomlaPack 2.2: Proactive potential timeout detection // Rough estimation of packing speed in bytes per second list($usec, $sec) = explode(" ", microtime()); $opEndTime = (double) $usec + (double) $sec; if ($opEndTime - $opStartTime == 0) { $_packSpeed = 0; } else { $_packSpeed = $packedSize / ($opEndTime - $opStartTime); } // Estimate required time to pack next file. If it's the first file of this operation, // do not impose any limitations. $_reqTime = $_packSpeed - 0.01 <= 0 ? 0 : $size / $_packSpeed; // Do we have enough time? if ($algoRunner->getTimeLeft() < $_reqTime) { array_unshift($this->_fileList, $file); JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Proactive step break - file: " . $file . " - size: " . $size); $this->setBreakFlag(); $this->_doneScanning = true; return true; } $packedSize += $size; $numberOfFiles++; $archiver->addFile($file, $this->_removePath, $this->_addPath); // Error propagation if ($archiver->getError()) { $this->setError($archiver->getError()); return false; } // If this was the first file of the fragment and it exceeded the fragment's capacity, // break the step. Continuing with more operations after packing such a big file is // increasing the risk to hit a timeout. if ($packedSize > JPMaxFragmentSize && $numberOfFiles == 1) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Breaking step *after* large file: " . $file . " - size: " . $size); $this->setBreakFlag(); return true; } } $this->_doneScanning = count($this->_fileList) > 0; return true; } }
/** * Steps the CUBE, performing yet another small chunk of backup work necessary * */ function tick() { if (!$this->_initialised) { $this->setError(JText::_('CUBE_NOTINIT')); } elseif (!$this->getError() && !$this->_isFinished) { $algorithmRunner = new JoomlapackCUBEAlgorunner(); $algo = $algorithmRunner->selectAlgorithm($this->_activeDomain); switch ($this->_activeDomain) { case 'init': case 'finale': $ret = 1; break; default: if (!is_object($this->_object)) { $algorithmRunner->setError('Current object is not an object on ' . $this->_activeDomain); $ret = 2; } else { $ret = $algorithmRunner->runAlgorithm($algo, $this->_object); $this->_currentStep = $algorithmRunner->currentStep; $this->_currentSubstep = $algorithmRunner->currentSubstep; } break; } switch ($ret) { case 0: // more work to do, return OK JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: More work required in domain '" . $this->_activeDomain); break; case 1: // Engine part finished JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: Domain '" . $this->_activeDomain . "' has finished"); $this->_getNextObject(); if ($this->_activeDomain == "finale") { // We have finished the whole process. JoomlapackCUBE::_finalise(); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: Just finished"); } break; case 2: // An error occured... JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "CUBE :: Error occured in domain '" . $this->_activeDomain); $this->setError($algorithmRunner->getError()); $this->reset(); //$this->_isFinished = true; break; } } return $this->_makeCUBEArray(); }
function _warning($p_message) { // ----- To be completed //$this->raiseError($p_message); $cube =& JoomlapackCUBE::getInstance(); $cube->addWarning($p_message); }
return json_encode($var); } else { $encoder = new Services_JSON(); return $encoder->encode($var); } } $task = JRequest::getCmd('task', ''); switch ($task) { case 'getdirectory': // Return the output directory in JSON format $registry =& JoomlapackModelRegistry::getInstance(); $outdir = $registry->get('OutputDirectory'); // # Fix 2.4: Drop the output buffer if (function_exists('ob_clean')) { @ob_clean(); } echo to_json($outdir); break; default: // Return the CUBE array in JSON format $cube =& JoomlapackCUBE::getInstance(); $array = $cube->getCUBEArray(); // # Fix 2.4: Drop the output buffer if (function_exists('ob_clean')) { @ob_clean(); } echo to_json($array); break; } # Fix 2.4: Die the script in order to avoid misbehaving modules from ruining the output die;
/** * Find where to store the backup files */ function _getBackupFilePaths() { $configuration = JoomlapackConfiguration::getInstance(); if ($this->_DBOnly) { // On DB Only backups we use different naming, no matter what's the setting JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Only dump database mode detected"); $this->_tempFile = JoomlapackAbstraction::getExpandedTarName('.sql'); $this->_saveAsName = ''; } else { if ($this->_dumpFile != '') { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Forced filename using dumpFile found."); // If the dumpFile was set, forcibly use this value $this->_tempFile = JoomlapackCUBE::registerTempFile(dechex(crc32(microtime() . $this->_dumpFile))); $this->_saveAsName = 'installation/sql/' . $this->_dumpFile; } else { if ($this->_isJoomla) { // Joomla! Core Database, use the JoomlaPack way of figuring out the filenames JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: Core database"); $this->_tempFile = JoomlapackCUBE::registerTempFile(dechex(crc32(microtime() . $configuration->AltInstaller->BaseDump))); $this->_saveAsName = 'installation/sql/' . $configuration->AltInstaller->BaseDump; } else { // External databases, we use the database's name JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDumperDefault :: External database"); $this->_tempFile = JoomlapackCUBE::registerTempFile(dechex(crc32(microtime() . $this->_database . '.sql'))); $this->_saveAsName = 'installation/sql/' . $this->_database . '.sql'; } } } JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDomainDBBackup :: SQL temp file is " . $this->_tempFile); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackDomainDBBackup :: SQL file location in archive is " . $this->_saveAsName); }
/** * Implements the _finalize() abstract method * */ function _finalize() { $cube =& JoomlapackCUBE::getInstance(); $provisioning =& $cube->getProvisioning(); // Add Extension Filter SQL statements (if any), only for the MAIN DATABASE!!! if ($this->_isJoomla) { jpimport('models.extfilter', true); $extModel = new JoomlapackModelExtfilter(); $extraSQL =& $extModel->getExtraSQL(); $this->_writeline($extraSQL); unset($extraSQL); unset($extModel); } // If we are not just doing a db only backup, add the SQL file to the archive if (!$this->_DBOnly) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Adding the SQL dump to the archive"); $archiver =& $provisioning->getArchiverEngine(); $archiver->addFileRenamed($this->_tempFile, $this->_saveAsName); if ($archiver->getError()) { $this->setError($archiver->getError()); return; } unset($archiver); if ($this->getError()) { return; } JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Removing temporary files"); JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFile, true); JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempMSDfile, true); if ($this->getError()) { return; } } else { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "Removing temporary file"); JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempMSDfile, true); } $this->setState('finished'); }
/** * Try to pack some files in the $_fileList, restraining ourselves not to reach the max * number of files or max fragment size while doing so. If this process is over and we are * left without any more files, reset $_doneScanning to false in order to instruct the class * to scan for more files. * * @return bool True if there were files packed, false otherwise (empty filelist) */ function _packSomeFiles() { if (count($this->_fileList) == 0) { // No files left to pack -- This should never happen! We catch this condition at the end of this method! $this->_doneScanning = false; return false; } else { $packedSize = 0; $numberOfFiles = 0; $cube =& JoomlapackCUBE::getInstance(); $archiver =& $cube->getArchiverEngine(); while (count($this->_fileList) > 0 && $packedSize <= JPMaxFragmentSize && $numberOfFiles <= JPMaxFragmentFiles) { $file = @array_shift($this->_fileList); $size = @filesize($file); $packedSize += $size; $numberOfFiles++; $archiver->addFile($file, JPATH_SITE); // Error propagation if ($archiver->hasError()) { $this->setError($archiver->getError(), true); return false; } // Warning propagation if ($archiver->hasWarning()) { foreach ($archiver->getWarning() as $warning) { $this->setWarning($warning, true); } } } $this->_doneScanning = count($this->_fileList) > 0; return true; } }