/** * 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(); }
/** * 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() { $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(); }