Exemplo n.º 1
0
 public static function load_configuration_from_export($file)
 {
     // Make sure the file if valid.
     if (!is_file($file)) {
         return false;
     }
     $config = (require $file);
     $config = json_decode($config, TRUE);
     // Load database.
     self::setup_database();
     // Make sure the database is built first.
     if (!self::is_table('CMS_Buckets')) {
         return false;
     }
     // Get the current state of the export.
     if ($stmt = Cloudmanic\Database\DB::query("SELECT * FROM CMS_State WHERE CMS_StateName = 'import-hash'")) {
         $entry = $stmt->fetch(PDO::FETCH_ASSOC);
     } else {
         $entry = false;
     }
     // Match the config state up with the current state to see if we have to do anything.
     if ($entry) {
         if ($config['hash'] == $entry['CMS_StateValue']) {
             return false;
         }
     } else {
         // Build the state entry.
         $q = array('CMS_StateName' => 'import-hash', 'CMS_StateValue' => '', 'CMS_StateUpdatedAt' => date('Y-m-d G:i:s'), 'CMS_StateCreatedAt' => date('Y-m-d G:i:s'));
         Cloudmanic\Database\DB::set_table('CMS_State')->insert($q);
     }
     // Loop through the data, delete the old data and insert the new.
     foreach ($config['tables'] as $key => $row) {
         Cloudmanic\Database\DB::query("TRUNCATE TABLE {$key}");
         foreach ($row as $key2 => $row2) {
             Cloudmanic\Database\DB::set_table($key)->insert($row2);
         }
     }
     // Update the hash in the state table.
     $q = Cloudmanic\Database\DB::get_connection()->prepare("UPDATE CMS_State SET CMS_StateValue=? WHERE CMS_StateName = 'import-hash'");
     $q->execute(array($config['hash']));
     return true;
 }