/** * Creates a randomly-named temporary file, registers it with the temporary * files management and returns its absolute path * @return string The temporary file name */ static function createRegisterTempFile() { // Create a randomly named file in the temp directory $registry = AEFactory::getConfiguration(); $tempFile = tempnam($registry->get('akeeba.basic.output_directory'), 'ak'); // Register it and return its absolute path $tempName = basename($tempFile); return AEUtilTempfiles::registerTempFile($tempName); }
/** * Find where to store the backup files * @param $partNumber int The SQL part number, default is 0 (.sql) */ protected function getBackupFilePaths($partNumber = 0) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Getting temporary file"); $this->tempFile = AEUtilTempfiles::registerTempFile(dechex(crc32(microtime())) . '.sql'); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Temporary file is {$this->tempFile}"); // Get the base name of the dump file $partNumber = intval($partNumber); $baseName = $this->dumpFile; if ($partNumber > 0) { // The file names are in the format dbname.sql, dbname.s01, dbname.s02, etc if (strtolower(substr($baseName, -4)) == '.sql') { $baseName = substr($baseName, 0, -4) . '.s' . sprintf('%02u', $partNumber); } else { $baseName = $baseName . '.s' . sprintf('%02u', $partNumber); } } if (empty($this->installerSettings)) { // Fetch the installer settings $this->installerSettings = (object) array('installerroot' => 'installation', 'sqlroot' => 'installation/sql', 'databasesini' => 1, 'readme' => 1, 'extrainfo' => 1); $config = AEFactory::getConfiguration(); $installerKey = $config->get('akeeba.advanced.embedded_installer'); $installerDescriptors = AEUtilInihelper::getInstallerList(); if (array_key_exists($installerKey, $installerDescriptors)) { // The selected installer exists, use it $this->installerSettings = (object) $installerDescriptors[$installerKey]; } elseif (array_key_exists('abi', $installerDescriptors)) { // The selected installer doesn't exist, but ABI exists; use that instead $this->installerSettings = (object) $installerDescriptors['abi']; } } switch (AEUtilScripting::getScriptingParameter('db.saveasname', 'normal')) { case 'output': // The SQL file will be stored uncompressed in the output directory $statistics = AEFactory::getStatistics(); $statRecord = $statistics->getRecord(); $this->saveAsName = $statRecord['absolute_path']; break; case 'normal': // The SQL file will be stored in the SQL root of the archive, as // specified by the particular embedded installer's settings $this->saveAsName = $this->installerSettings->sqlroot . '/' . $baseName; break; case 'short': // The SQL file will be stored on archive's root $this->saveAsName = $baseName; break; } if ($partNumber > 0) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AkeebaDomainDBBackup :: Creating new SQL dump part #{$partNumber}"); } AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AkeebaDomainDBBackup :: SQL temp file is " . $this->tempFile); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AkeebaDomainDBBackup :: SQL file location in archive is " . $this->saveAsName); }
/** * Find where to store the backup files * @param $partNumber int The SQL part number, default is 0 (.sql) */ protected function getBackupFilePaths( $partNumber = 0 ) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'XXX '.__CLASS__." :: Getting temporary file"); $this->tempFile = AEUtilTempfiles::registerTempFile( dechex(crc32(microtime())).'.sql' ); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'XXX '.__CLASS__." :: Temporary file is {$this->tempFile}"); // Get the base name of the dump file $partNumber = intval($partNumber); $baseName = $this->dumpFile; if($partNumber > 0) { // The file names are in the format dbname.sql, dbname.s01, dbname.s02, etc if( strtolower(substr($baseName, -4)) == '.sql' ) { $baseName = substr($baseName, 0, -4).'.s'.sprintf('%02u', $partNumber); } else { $baseName = $baseName.'.s'.sprintf('%02u', $partNumber); } } switch(AEUtilScripting::getScriptingParameter('db.saveasname','normal')) { case 'output': // The SQL file will be stored uncompressed in the output directory $statistics =& AEFactory::getStatistics(); $statRecord = $statistics->getRecord(); $this->saveAsName = $statRecord['absolute_path']; break; case 'normal': // The SQL file will be stored in the SQL root of the archive, as // specified by the particular embedded installer's settings $this->saveAsName = $this->installerSettings->sqlroot.'/'.$baseName; break; case 'short': // The SQL file will be stored on archive's root $this->saveAsName = $baseName; break; } if($partNumber > 0) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AkeebaDomainDBBackup :: Creating new SQL dump part #$partNumber"); } AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AkeebaDomainDBBackup :: SQL temp file is " . $this->tempFile); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AkeebaDomainDBBackup :: 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 */ public function initialize($targetArchivePath, $options = array()) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AEArchiverZip :: initialize - archive {$targetArchivePath}"); // Get names of temporary files $configuration = AEFactory::getConfiguration(); $this->_ctrlDirFileName = tempnam($configuration->get('akeeba.basic.output_directory'), 'akzcd'); $this->_dataFileName = $targetArchivePath; // If we use splitting, initialize if ($this->_useSplitZIP) { AEUtilLogger::WriteLog(_AE_LOG_INFO, "AEArchiverZip :: Split ZIP creation enabled"); $this->_dataFileNameBase = dirname($targetArchivePath) . '/' . basename($targetArchivePath, '.zip'); $this->_dataFileName = $this->_dataFileNameBase . '.z01'; } $this->_ctrlDirFileName = basename($this->_ctrlDirFileName); $pos = strrpos($this->_ctrlDirFileName, '/'); if ($pos !== false) { $this->_ctrlDirFileName = substr($this->_ctrlDirFileName, $pos + 1); } $pos = strrpos($this->_ctrlDirFileName, '\\'); if ($pos !== false) { $this->_ctrlDirFileName = substr($this->_ctrlDirFileName, $pos + 1); } $this->_ctrlDirFileName = AEUtilTempfiles::registerTempFile($this->_ctrlDirFileName); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AEArchiverZip :: CntDir Tempfile = " . $this->_ctrlDirFileName); // Create temporary file if (!@touch($this->_ctrlDirFileName)) { $this->setError("Could not open temporary file for ZIP archiver. Please check your temporary directory's permissions!"); return false; } if (function_exists('chmod')) { chmod($this->_ctrlDirFileName, 0666); } // Try to kill the archive if it exists AEUtilLogger::WriteLog(_AE_LOG_DEBUG, "AEArchiverZip :: 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("Could not open archive file for ZIP archiver. Please check your output directory's permissions!"); return false; } if (function_exists('chmod')) { chmod($this->_dataFileName, 0666); } // 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... $statistics = AEFactory::getStatistics(); $statistics->updateMultipart(1); } }