/**
  * Import site
  *
  * @return StorageFile
  */
 public function import()
 {
     global $wp_version;
     $storage = StorageArea::getInstance();
     // Create import file
     $import_file = $storage->makeFile($this->options['import']['file']);
     // Extract archive
     try {
         try {
             $zip = ZipFactory::makeZipArchiver($import_file->getName(), !class_exists('ZipArchive'));
             $zip->extractTo($storage->getRootPath());
             $zip->close();
         } catch (Exception $e) {
             $zip = ZipFactory::makeZipArchiver($import_file->getName(), true);
             $zip->extractTo($storage->getRootPath());
             $zip->close();
         }
     } catch (Exception $e) {
         throw new Ai1wm_Import_Exception(_('Site could not be imported!<br />' . 'Archive file is broken or is not compatible with the plugin! Please verify your archive file.'));
     }
     // Verify package
     if ($this->should_import_package()) {
         // Enable maintenance mode
         Ai1wm_Maintenance::enable();
         // Database
         if ($this->should_import_database()) {
             $service = new Ai1wm_Service_Database($this->options);
             $service->import();
         }
         // Media
         if ($this->should_import_media()) {
             $service = new Ai1wm_Service_Media($this->options);
             $service->import();
         }
         // Sites (Network mode)
         if ($this->should_import_sites()) {
             $service = new Ai1wm_Service_Sites($this->options);
             $service->import();
         }
         // Themes
         if ($this->should_import_themes()) {
             $service = new Ai1wm_Service_Themes($this->options);
             $service->import();
         }
         // Plugins
         if ($this->should_import_plugins()) {
             $service = new Ai1wm_Service_Plugins($this->options);
             $service->import();
         }
         // Disable maintenance mode
         Ai1wm_Maintenance::disable();
     } else {
         throw new Ai1wm_Import_Exception(_('Site could not be imported!<br />' . 'Archive file is not compatible with the plugin! Please verify your archive file.'));
     }
     return $import_file;
 }
 /**
  * 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;
 }