public function test_deleteok()
 {
     $this->loadSchemaJSON('schema1');
     $schema = new Schema('schema1');
     $this->assertEquals(1, $schema->getId());
     $schema->delete();
     $this->assertEquals(0, $schema->getId());
     $schema = new Schema('schema1');
     $this->assertEquals(0, $schema->getId());
 }
Exemplo n.º 2
0
 /**
  * Should carry out any processing required by the plugin.
  */
 public function handle()
 {
     global $INPUT;
     global $ID;
     global $config_cascade;
     $config_file_path = end($config_cascade['main']['local']);
     // form submit
     $table = Schema::cleanTableName($INPUT->str('table'));
     if ($table && $INPUT->bool('save') && checkSecurityToken()) {
         $builder = new SchemaBuilder($table, $INPUT->arr('schema'));
         if (!$builder->build()) {
             msg('something went wrong while saving', -1);
         }
         touch($config_file_path);
     }
     // export
     if ($table && $INPUT->bool('export')) {
         $builder = new Schema($table);
         header('Content-Type: application/json');
         header("Content-Disposition: attachment; filename={$table}.struct.json");
         echo $builder->toJSON();
         exit;
     }
     // import
     if ($table && $INPUT->bool('import')) {
         if (isset($_FILES['schemafile']['tmp_name'])) {
             $json = io_readFile($_FILES['schemafile']['tmp_name'], false);
             if (!$json) {
                 msg('Something went wrong with the upload', -1);
             } else {
                 $builder = new SchemaImporter($table, $json, $INPUT->bool('lookup'));
                 if (!$builder->build()) {
                     msg('something went wrong while saving', -1);
                 }
                 touch($config_file_path);
             }
         }
     }
     // delete
     if ($table && $INPUT->bool('delete')) {
         if ($table != $INPUT->str('confirm')) {
             msg($this->getLang('del_fail'), -1);
         } else {
             try {
                 $schema = new Schema($table);
                 $schema->delete();
                 msg($this->getLang('del_ok'), 1);
                 touch($config_file_path);
                 send_redirect(wl($ID, array('do' => 'admin', 'page' => 'struct_schemas'), true, '&'));
             } catch (StructException $e) {
                 msg(hsc($e->getMessage()), -1);
             }
         }
     }
 }