Exemple #1
0
 function deleteTempFiles()
 {
     $configuration =& JoomlapackModelRegistry::getInstance();
     $tempFiles = JoomlapackCUBETables::UnserializeVar('CUBETempFiles', array());
     foreach ($tempFiles as $fileName) {
         $file = $configuration->getTemporaryDirectory() . DS . $fileName;
         if (file_exists($file)) {
             @unlink($file);
         }
     }
     JoomlapackCUBETables::DeleteVar('CUBETempFiles');
 }
Exemple #2
0
 /**
  * Writes a variable to the database (#__jp_temp)
  *
  * @param string $varName The name of the variable (must be unique; if it exists it gets overwritten)
  * @param string $value The value to store
  * @static
  */
 function WriteVar($varName, $value)
 {
     $db =& JFactory::getDBO();
     // Hopefully fixes the 'MySQL server has gone away' errors by testing MySQL
     // connection status and reconnecting if necessary.
     //$db->connected();
     // Kill exisiting variable (if any)
     JoomlapackCUBETables::DeleteVar($varName);
     // Base64-encode the value
     $value2 = JoomlapackCUBETables::_getBase64() ? base64_encode($value) : $value;
     // Create variable
     // OMG! $db-Quote DOES NOT encode 'key' into `key`, thus causing havoc. I have
     // to use backticks manually. BUMMER! AAARGH!
     $sql = 'INSERT INTO #__jp_temp (`key`,`value`)' . ' VALUES (' . $db->Quote($varName) . ', ' . $db->Quote($value2) . ')';
     $db->setQuery($sql);
     if ($db->query() === false) {
         JoomlapackLogger::WriteLog(_JP_LOG_ERROR, JText::sprintf('CUBE_TABLES_FAILEDSTORE', $varName));
         JoomlapackLogger::WriteLog(_JP_LOG_ERROR, 'Error: ' . $db->getErrorMsg());
         JoomlapackLogger::WriteLog(_JP_LOG_ERROR, 'Value: ' . $value);
         return false;
     }
     return true;
 }
 function _deleteCUBEObject()
 {
     $tmpfile = JoomlapackCUBETables::_cubeTmpFile(1);
     if (!empty($tmpfile)) {
         JoomlapackLogger::WriteLog(_JP_LOG_INFO, "Removing CUBE temporary file: " . $tmpfile);
         @unlink($tmpfile);
     }
     JoomlapackCUBETables::DeleteVar('cubetmpfile');
 }
 /**
  * Static function to reset older backups, removing their temporary files
  * and marking them as failed.
  * 
  * @static
  */
 function reset()
 {
     // 1. Detect failed backups
     if (!class_exists('JoomlapackModelStatistics')) {
         jpimport('models.statistics', true);
     }
     $model =& JoomlapackModelStatistics::getInstance();
     $runningList = $model->getRunningStatisticsList();
     if (is_array($runningList)) {
         if (!empty($runningList)) {
             jimport('joomla.filesystem.file');
             // Mark running backups as failed
             foreach ($runningList as $running) {
                 // Delete the failed backup's archive, if exists
                 $failedArchive = $running->absolute_path;
                 if (JFile::exists($failedArchive)) {
                     if (!JFile::delete($failedArchive)) {
                         // fallback; if Joomla! used FTP to unlink the file and it failed, let's try the old-fashioned way
                         @unlink($failedArchive);
                     }
                 }
                 // Mark the backup failed
                 $running->status = 'fail';
                 $model->save($running);
             }
             unset($model);
         }
     }
     // 2. Delete any stale CUBE db entry / file
     JoomlapackCUBETables::DeleteVar('CUBEObject');
     // 3. Remove temporary files
     JoomlapackCUBETempfiles::deleteTempFiles();
     // 4. Remove temporary data from #__jp_temp
     JoomlapackCUBETables::DeleteMultipleVars('%CUBE%');
 }
Exemple #5
0
 /**
  * Static function to reset older backups, removing their temporary files
  * and marking them as failed.
  *
  * @static
  */
 function reset($do_not_log = false)
 {
     // Pause logging if so desired
     if ($do_not_log) {
         JoomlapackLogger::WriteLog(false, '');
     }
     // 1. Detect failed backups
     if (!class_exists('JoomlapackModelStatistics')) {
         jpimport('models.statistics', true);
     }
     $model =& JoomlapackModelStatistics::getInstance();
     $runningList = $model->getRunningStatisticsList();
     if (is_array($runningList)) {
         if (!empty($runningList)) {
             jimport('joomla.filesystem.file');
             // Mark running backups as failed
             foreach ($runningList as $running) {
                 $filenames = $model->getAllFilenames($running->id, false);
                 // Process if there are files to delete...
                 if (!is_null($filenames)) {
                     // Delete the failed backup's archive, if exists
                     foreach ($filenames as $failedArchive) {
                         if (JFile::exists($failedArchive)) {
                             if (!JFile::delete($failedArchive)) {
                                 // fallback; if Joomla! used FTP to unlink the file and it failed, let's try the old-fashioned way
                                 @unlink($failedArchive);
                             }
                         }
                     }
                 }
                 // Mark the backup failed
                 $running->status = 'fail';
                 $model->save($running);
             }
             unset($model);
         }
     }
     // 2. Delete any stale CUBE db entry / file
     JoomlapackCUBETables::DeleteVar('CUBEObject');
     // 3. Remove temporary files
     JoomlapackCUBETempfiles::deleteTempFiles();
     // 4. Remove temporary data from #__jp_temp
     JoomlapackCUBETables::DeleteMultipleVars('%CUBE%');
     // Unpause logging if it was previously paused
     if ($do_not_log) {
         JoomlapackLogger::WriteLog(true, '');
     }
 }