/**
  * Export site
  *
  * @return StorageFile
  */
 public function export()
 {
     $storage = StorageArea::getInstance();
     // Enable maintenance mode
     Ai1wm_Maintenance::enable();
     // Create export file
     $export_file = $storage->makeFile();
     // Make archive file
     try {
         $zip = ZipFactory::makeZipArchiver($export_file->getName(), !class_exists('ZipArchive'), true);
     } catch (Exception $e) {
         $zip = ZipFactory::makeZipArchiver($export_file->getName(), true, true);
     }
     // Package
     if ($this->should_export_package()) {
         $service = new Ai1wm_Service_Package($this->options);
         $zip->addFromString(AI1WM_PACKAGE_NAME, $service->export());
     }
     // Database
     if ($this->should_export_database()) {
         $service = new Ai1wm_Service_Database($this->options);
         // Add database to archive
         $zip->addFile($service->export(), AI1WM_DATABASE_NAME);
     }
     // Media
     if ($this->should_export_media()) {
         $service = new Ai1wm_Service_Media($this->options);
         // Add media to archive
         $zip->addDir($service->export(), AI1WM_MEDIA_NAME);
         // Sites (Network mode)
         $service = new Ai1wm_Service_Sites($this->options);
         if ($sites = $service->export()) {
             // Add sites to archive
             $zip->addDir($sites, AI1WM_SITES_NAME);
         }
     }
     // Themes
     if ($this->should_export_themes()) {
         $service = new Ai1wm_Service_Themes($this->options);
         // Add themes to archive
         $zip->addDir($service->export(), AI1WM_THEMES_NAME);
     }
     // Plugins
     if ($this->should_export_plugins()) {
         $service = new Ai1wm_Service_Plugins($this->options);
         // Add plugins to archive
         if ($plugins = $service->get_installed_plugins()) {
             $zip->addDir($service->export(), AI1WM_PLUGINS_NAME, $plugins);
         }
     }
     // Disable maintenance mode
     Ai1wm_Maintenance::disable();
     return $export_file;
 }
 /**
  * Add database
  *
  * @return void
  */
 public function database()
 {
     // Set exclude database
     if ($this->should_exclude_database()) {
         // Disable maintenance mode
         Ai1wm_Maintenance::disable();
         // Redirect
         return $this->route_to('export');
     }
     // Set progress
     Ai1wm_Status::set(array('message' => __('Exporting database...', AI1WM_PLUGIN_NAME)));
     // Get databsae file
     $service = new Ai1wm_Service_Database($this->args);
     $service->export();
     // Get archive file
     $archive = new Ai1wm_Compressor($this->storage()->archive());
     // Add database to archive
     $archive->add_file($this->storage()->database(), AI1WM_DATABASE_NAME);
     $archive->close();
     // Set progress
     Ai1wm_Status::set(array('message' => __('Done exporting database.', AI1WM_PLUGIN_NAME)));
     // Disable maintenance mode
     Ai1wm_Maintenance::disable();
     // Redirect
     $this->route_to('export');
 }