コード例 #1
0
 /**
  * Display import form 
  */
 protected function displayImportForm()
 {
     $Fieldset = new FormularFieldset(__('Import file'));
     $Formular = new Formular($_SERVER['SCRIPT_NAME'] . '?id=' . $this->id());
     $Formular->setId('import-json-form');
     $Formular->addCSSclass('ajax');
     $Formular->addCSSclass('no-automatic-reload');
     $Formular->addHiddenValue('file', $_GET['file']);
     if (substr($_GET['file'], -8) != '.json.gz') {
         $Fieldset->addError(__('You can only import *.json.gz-files.'));
         Filesystem::deleteFile('../data/DbBackup/import/' . $_GET['file']);
     } else {
         require_once __DIR__ . '/class.RunalyzeJsonAnalyzer.php';
         $Analyzer = new RunalyzeJsonAnalyzer('../data/DbBackup/import/' . $_GET['file']);
         if ($Analyzer->fileIsOkay()) {
             $Fieldset->addField(new FormularCheckbox('overwrite_config', __('Overwrite general configuration'), true));
             $Fieldset->addField(new FormularCheckbox('overwrite_dataset', __('Overwrite dataset configuration'), true));
             $Fieldset->addField(new FormularCheckbox('overwrite_plugin', __('Overwrite plugins'), true));
             $Fieldset->addField(new FormularCheckbox('delete_trainings', __('Delete all old activities'), false));
             $Fieldset->addField(new FormularCheckbox('delete_user_data', __('Delete all old body values'), false));
             $Fieldset->addFileBlock(sprintf(__('There are <strong>%s</strong> activities in this file.'), $Analyzer->count('runalyze_training')));
             $Fieldset->addFileBlock(sprintf(__('There are <strong>%s</strong> body values in this file.'), $Analyzer->count('runalyze_user')));
             $Fieldset->setLayoutForFields(FormularFieldset::$LAYOUT_FIELD_W100);
             $Formular->addSubmitButton(__('Import'));
         } elseif (!$Analyzer->versionIsOkay()) {
             $Fieldset->addError(sprintf(__('Versions do not match! The backup is from %s but you are using %s.'), $Analyzer->fileVersion(), 'v' . RUNALYZE_VERSION));
         } else {
             $Fieldset->addError(__('The file seems to be corrupted.'));
             foreach ($Analyzer->errors() as $Error) {
                 $Fieldset->addError($Error);
             }
         }
     }
     $Formular->addFieldset($Fieldset);
     $Formular->display();
 }
コード例 #2
0
 public function testVersionExtractionForWithEquipment()
 {
     $Analyzer = new RunalyzeJsonAnalyzer('../tests/testfiles/backup/with-equipment.json.gz');
     $this->assertTrue($Analyzer->fileIsOkay());
     $this->assertTrue($Analyzer->versionIsOkay());
 }