/** * Creates a randomly-named temporary file, registers it with the temporary * files management and returns its absolute path * @return string The temporary file name */ function createRegisterTempFile() { // Create a randomly named file in the temp directory $registry =& JoomlapackModelRegistry::getInstance(); $tempFile = tempnam($registry->getTemporaryDirectory(), 'jp'); // Register it and return its absolute path $tempName = basename($tempFile); return JoomlapackCUBETempfiles::registerTempFile($tempName); }
/** * Finalises the archive by compressing it. Overrides parent's method * @return boolean TRUE on success, FALSE on failure */ function finalize() { // Get gzip's binary location $registry = JoomlapackModelRegistry::getInstance(); $gzip = escapeshellcmd($registry->get('gzipbinary')); // Construct and run command line $command = "{$gzip} " . escapeshellcmd($this->_tempFilename); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerTARGZ :: Calling gzip. The command line is:"); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, $command); $result = shell_exec($command); // Normally, gzip should be silent as a fish. If anything was sput out, // there must have been an error. if (strlen(trim($result)) > 0) { $errorMessage = "Error calling gzip: " . $result . " \n Command line was: \n " . $command . " \n Please check file permissions and examine the result message for any hints regarding the problem tar faced archiving your files."; $this->setError($errorMessage); return false; } // Now, unregister the temp file (which no longer exists), register the gzipped file as // a new temp file and try to move it JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFilename); $this->_tempFilename = JoomlapackCUBETempfiles::registerTempFile(basename($this->_archiveFilename)); copy($this->_tempFilename, $this->_archiveFilename); JoomlapackCUBETempfiles::unregisterAndDeleteTempFile($this->_tempFilename); // If no errors occured, return true return true; }
/** * Initialises the archiver class, creating the archive from an existent * installer's JPA archive. * * @param string $sourceJPAPath Absolute path to an installer's JPA archive * @param string $targetArchivePath Absolute path to the generated archive * @param array $options A named key array of options (optional). This is currently not supported * @access public */ function initialize($sourceJPAPath, $targetArchivePath, $options = array()) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerZIP :: initialize - archive {$targetArchivePath}"); // Get names of temporary files $configuration =& JoomlapackModelRegistry::getInstance(); $this->_ctrlDirFileName = tempnam($configuration->getTemporaryDirectory(), 'jpzcd'); $this->_dataFileName = $targetArchivePath; // If we use splitting, initialize if ($this->_useSplitZIP) { JoomlapackLogger::WriteLog(_JP_LOG_INFO, "JoomlapackPackerZIP :: Split ZIP creation enabled"); $this->_dataFileNameBase = dirname($targetArchivePath) . DS . basename($targetArchivePath, '.zip'); $this->_dataFileName = $this->_dataFileNameBase . '.z01'; } jimport('joomla.filesystem.file'); $tempname = JFile::getName($this->_ctrlDirFileName); JoomlapackCUBETempfiles::registerTempFile($tempname); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerZIP :: CntDir Tempfile = " . $this->_ctrlDirFileName); // Create temporary file if (!@touch($this->_ctrlDirFileName)) { $this->setError(JText::_('CUBE_ZIPARCHIVER_CANTWRITETEMP')); return false; } // Try to kill the archive if it exists JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerZIP :: Killing old archive"); $fp = fopen($this->_dataFileName, "wb"); if (!($fp === false)) { ftruncate($fp, 0); fclose($fp); } else { @unlink($this->_dataFileName); } if (!@touch($this->_dataFileName)) { $this->setError(JText::_('CUBE_ZIPARCHIVER_CANTWRITEZIP')); return false; } // On split archives, include the "Split ZIP" header, for PKZIP 2.50+ compatibility if ($this->_useSplitZIP) { file_put_contents($this->_dataFileName, "PK"); // Also update the statistics table that we are a multipart archive... $cube =& JoomlapackCUBE::getInstance(); $cube->updateMultipart(1); } parent::initialize($sourceJPAPath, $targetArchivePath, $options); }
/** * The most basic file transaction: add a single entry (file or directory) to * the archive. * * @param bool $isVirtual If true, the next parameter contains file data instead of a file name * @param string $sourceNameOrData Absolute file name to read data from or the file data itself is $isVirtual is true * @param string $targetName The (relative) file name under which to store the file in the archive * @return True on success, false otherwise * @since 2.1 * @access protected * @abstract */ function _addFile($isVirtual, &$sourceNameOrData, $targetName) { if ($isVirtual) { // VIRTUAL FILES // Create and register temp file with the virtual contents $tempFileName = JoomlapackCUBETempfiles::registerTempFile(basename($targetName)); if (function_exists('file_put_contents')) { file_put_contents($tempFileName, $sourceNameOrData); } else { $tempHandler = fopen($tempFileName, 'wb'); $this->_fwrite($tempHandler, $sourceNameOrData); fclose($tempHandler); } // Calculate add / remove paths $removePath = dirname($tempFileName); $addPath = dirname($targetName); // Add the file $this->_tarObject->addModify($tempFileName, $addPath, $removePath, $tempFileName); // Remove the temporary file JoomlapackCUBETempfiles::unregisterAndDeleteTempFile(basename($targetName)); } else { // REGULAR FILES if ($targetName == '') { $targetName = $sourceNameOrData; } $this->_tarObject->addModify($sourceNameOrData, '', JPATH_SITE, $targetName); } }
/** * 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); }
/** * Initialises the archiver class, creating the archive from an existent * installer's JPA archive. * * @param string $sourceJPAPath Absolute path to an installer's JPA archive * @param string $targetArchivePath Absolute path to the generated archive * @param array $options A named key array of options (optional). This is currently not supported * @access public */ function initialize($sourceJPAPath, $targetArchivePath, $options = array()) { JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerZIP :: initialize - archive {$targetArchivePath}"); // Get names of temporary files $configuration =& JoomlapackModelRegistry::getInstance(); $this->_ctrlDirFileName = tempnam($configuration->getTemporaryDirectory(), 'jpzcd'); $this->_dataFileName = $targetArchivePath; jimport('joomla.filesystem.file'); $tempname = JFile::getName($this->_ctrlDirFileName); JoomlapackCUBETempfiles::registerTempFile($tempname); JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerZIP :: CntDir Tempfile = " . $this->_ctrlDirFileName); // Create temporary file if (!@touch($this->_ctrlDirFileName)) { $this->setError(JText::_('CUBE_ZIPARCHIVER_CANTWRITETEMP')); return false; } // Try to kill the archive if it exists JoomlapackLogger::WriteLog(_JP_LOG_DEBUG, "JoomlapackPackerZIP :: Killing old archive"); $fp = fopen($this->_dataFileName, "wb"); if (!($fp === false)) { ftruncate($fp, 0); fclose($fp); } else { @unlink($this->_dataFileName); } if (!@touch($this->_dataFileName)) { $this->setError(JText::_('CUBE_ZIPARCHIVER_CANTWRITEZIP')); return false; } parent::initialize($sourceJPAPath, $targetArchivePath, $options); }