Author: Jan Vansteenlandt (jan@okfn.be)
Inheritance: extends SourceType
Example #1
0
 /**
  * Seed the CSV definitions
  */
 private function seedCsv()
 {
     // The csv file names
     $csv_data = array('geo' => array('description' => 'Geographical data about Afghanistan concerning provinces and districts.', 'columns' => array(array('column_name' => 'lon', 'index' => 0, 'column_name_alias' => 'lon', 'is_pk' => 0), array('column_name' => 'lat', 'index' => 1, 'column_name_alias' => 'lat', 'is_pk' => 0), array('column_name' => 'Unit_Type', 'index' => 2, 'column_name_alias' => 'Unit_Type', 'is_pk' => 0), array('column_name' => 'Dist_Name', 'index' => 3, 'column_name_alias' => 'Dist_Name', 'is_pk' => 0), array('column_name' => 'Prov_Name', 'index' => 4, 'column_name_alias' => 'Prov_Name', 'is_pk' => 0), array('column_name' => 'Dist_ID', 'index' => 5, 'column_name_alias' => 'Dist_ID', 'is_pk' => 0), array('column_name' => 'Prov_ID', 'index' => 6, 'column_name_alias' => 'Prov_ID', 'is_pk' => 0))));
     // Provide a message when nothing has been added (doubles have been found)
     $added = false;
     foreach ($csv_data as $file => $definition_info) {
         // Don't create doubles
         $definition = Definition::where('collection_uri', '=', 'csv')->where('resource_name', '=', $file)->first();
         if (empty($definition)) {
             // Create a new CsvDefinition
             $csv_def = new CsvDefinition();
             $csv_def->description = $definition_info['description'];
             $csv_def->uri = 'file://' . app_path() . '/storage/data/csv/' . $file . '.csv';
             $csv_def->delimiter = ';';
             $csv_def->has_header_row = 1;
             $csv_def->start_row = 0;
             $csv_def->save();
             // Add the tabular columns
             foreach ($definition_info['columns'] as $column) {
                 $tab_column = new TabularColumns();
                 $tab_column->column_name = $column['column_name'];
                 $tab_column->index = $column['index'];
                 $tab_column->column_name_alias = $column['column_name_alias'];
                 $tab_column->is_pk = $column['is_pk'];
                 $tab_column->tabular_id = $csv_def->id;
                 $tab_column->tabular_type = 'CsvDefinition';
                 $tab_column->save();
             }
             // Add the CsvDefinition to a Definition
             $definition = new Definition();
             $definition->collection_uri = 'csv';
             $definition->resource_name = $file;
             $definition->source_id = $csv_def->id;
             $definition->source_type = 'CsvDefinition';
             $definition->draft = false;
             $definition->save();
             $this->command->info("Published a CSV file with name {$file} on uri (relative to the root) csv/{$file} .");
             $added = true;
         }
     }
     if (!$added) {
         $this->command->info("No CSV files have been published, all of the uri's that the CSV seeder wanted to use are already taken.");
     }
 }
Example #2
0
 public function testDeleteApi()
 {
     // Delete the published definition for each test csv file.
     foreach ($this->test_data as $file) {
         $this->updateRequest('DELETE');
         $controller = \App::make('Tdt\\Core\\Definitions\\DefinitionController');
         $response = $controller->handle("csv/{$file}");
         $this->assertEquals(200, $response->getStatusCode());
     }
     // Check if everything is deleted properly.
     $definitions_count = \Definition::all()->count();
     $csv_count = \CsvDefinition::all()->count();
     $this->assertTrue($csv_count == 0);
     $this->assertTrue($definitions_count == 0);
 }
Example #3
0
 /**
  * Delete everything out of our testing database.
  */
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     \Definition::truncate();
     \CsvDefinition::truncate();
     \InstalledDefinition::truncate();
     \JsonDefinition::truncate();
     \ShpDefinition::truncate();
     \SparqlDefinition::truncate();
     \XlsDefinition::truncate();
     \XmlDefinition::truncate();
     \GeoProperty::truncate();
     \TabularColumns::truncate();
     \Geoprojection::truncate();
 }