Exemple #1
0
 /**
  * Backup system
  *
  * This function is used to backup the system. There are 2 types of backup, database only and full.
  * In the first case (the default), only the database is backed up, while in the second case, files
  * are backed up as well.
  * <br/>Example:
  * <code>
  * $backupFile = EfrontSystem :: backup('13_3_2007');			//Backup database only
  * </code>
  *
  * @param string $backupName The name of the backup
  * @param int $backupType Can be either 0 or 1, where 0 siginifies database only backup and 1 is for including backup files as well
  * @return EfrontFile The compressed file of the backup
  * @since 3.5.0
  * @access public
  * @static
  */
 public static function backup($backupName, $backupType = 0)
 {
     $tempDir = G_BACKUPPATH . 'temp/';
     if (is_dir($tempDir)) {
         $dir = new EfrontDirectory($tempDir);
         $dir->delete();
     }
     mkdir($tempDir, 0755);
     mkdir($tempDir . 'db_backup', 0755);
     $directory = new EfrontDirectory($tempDir);
     $tables = $GLOBALS['db']->GetCol("show tables");
     //Get the database tables
     foreach ($tables as $table) {
         if (!preg_match("/^\\w+_view\$/", $table)) {
             $data = eF_getTableData($table, "count(*)");
             $unfold = 1000;
             $limit = ceil($data[0]['count(*)'] / $unfold);
             for ($i = 0; $i < $limit; $i++) {
                 $data = eF_getTableData($table, "*", "", "'' limit {$unfold} offset " . $i * $unfold);
                 file_put_contents($tempDir . 'db_backup/' . $table . '.' . $i, serialize($data), FILE_APPEND);
             }
             $result = eF_ExecuteNew("show create table {$table}");
             $temp = $result->GetAll();
             $definition[] = "drop table " . $temp[0]['Table'];
             $definition[] = $temp[0]['Create Table'];
         }
     }
     /*
     		 foreach ($tables as $table) {
     $data = eF_getTableData($table);
     file_put_contents($tempDir.'db_backup/'.$table, serialize($data));
     $result       = eF_ExecuteNew("show create table $table");
     $temp         = $result -> GetAll();
     $definition[] = "drop table ".$temp[0]['Table'];
     $definition[] = $temp[0]['Create Table'];
     }
     */
     file_put_contents($tempDir . 'db_backup/sql.txt', implode(";\n", $definition));
     file_put_contents($tempDir . 'db_backup/version.txt', G_VERSION_NUM);
     if ($backupType == 3 && checkFunction('system') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
         system('mkdir ' . $tempDir . 'lessons');
         system('cp -R ' . G_LESSONSPATH . '* ' . $tempDir . 'lessons');
         system('mkdir -p ' . $tempDir . 'upload');
         system('cp -R ' . G_UPLOADPATH . '* ' . $tempDir . 'upload');
         system('mkdir -p ' . $tempDir . 'certificate_templates');
         system('cp -R ' . G_ROOTPATH . "www/certificate_templates/" . '* ' . $tempDir . 'certificate_templates');
         system('mkdir -p ' . $tempDir . 'editor_templates');
         system('cp -R ' . G_ROOTPATH . "www/content/editor_templates/" . '* ' . $tempDir . 'editor_templates');
     } else {
         if ($backupType == 1 || $backupType == 3) {
             $lessonsDir = new EfrontDirectory(G_LESSONSPATH);
             $lessonsDir->copy($tempDir . 'lessons');
             $uploadsDir = new EfrontDirectory(G_UPLOADPATH);
             $uploadsDir->copy($tempDir . 'upload');
             $certificatesDir = new EfrontDirectory(G_ROOTPATH . "www/certificate_templates/");
             $certificatesDir->copy($tempDir . 'certificate_templates');
             $editorTemplatesDir = new EfrontDirectory(G_ROOTPATH . "www/content/editor_templates/");
             $editorTemplatesDir->copy($tempDir . 'editor_templates');
         } else {
             if ($backupType == 2) {
                 $rootDir = new EfrontDirectory(G_ROOTPATH);
                 $rootDir->copy($tempDir . 'efront_root');
             }
         }
     }
     if ($backupType == 3 && checkFunction('system') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
         $compressedFile = $directory->compress($backupName, false, false, true);
     } else {
         $compressedFile = $directory->compress($backupName, false);
     }
     $directory->delete();
     return $compressedFile;
 }
		
		td.failed
		{
			color: red;
		}
		
		td.passed
		{
			color: green;
		}
	</style>
</head>

<?php 
echo '<h2>Server check</h2>';
function checkFunction($sMessage, $sFunction)
{
    echo '<tr>';
    echo '<td class="message">' . $sMessage . '</td>';
    if (function_exists($sFunction)) {
        echo '<td class="status passed">passed</td>';
    } else {
        echo '<td class="status failed">failed</td>';
    }
    echo '</tr>';
}
echo '<table>';
checkFunction('Checking cURL extension', 'curl_init');
checkFunction('Checking image processing and GD', 'imagecreate');
checkFunction('Checking json_encode', 'json_encode');
echo '</table>';