示例#1
0
 public static function export(\Rebond\Core\ModelInterface $module)
 {
     $exportPath = \Rebond\Config::path('export');
     $tempPath = \Rebond\Config::path('temp');
     // TODO add XML model node
     // generate data script
     $dataScriptPath = $tempPath . 'data.sql';
     $table = 'app_' . strtolower($module->getTitle());
     $db = new Util\Data();
     $result = $db->select('SELECT * FROM ' . $table);
     $script = $db->backupData($table, $result);
     $result = $db->select('SELECT * FROM cms_content WHERE module_id = ?', [$module->getId()]);
     $script .= $db->backupData('cms_content', $result);
     File::save($dataScriptPath, 'w', $script);
     // create zip
     $zipFile = $module->getTitle() . '.zip';
     $zip = new \ZipArchive();
     $res = $zip->open($exportPath . $zipFile, \ZIPARCHIVE::OVERWRITE);
     if (!$res) {
         return $res;
     }
     $modulePath = FULL_PATH . 'Rebond/App/' . $module->getTitle() . '/';
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($modulePath));
     foreach ($iterator as $file) {
         $filename = str_replace($modulePath, '', str_replace('\\', '/', $file));
         if (file_exists($file) && substr($filename, -1) != '.') {
             $zip->addFile($file, $filename);
         }
     }
     $zip->addFile($dataScriptPath, 'data.sql');
     $zip->close();
     return $zipFile;
 }