/** * Seed the licenses * * @return void */ private function seedLicenses() { // Fetch the licenses from the json file $this->command->info('---- DCAT Licenses ----'); $this->command->info('Trying to fetch the licenses from a local json file.'); $licenses = json_decode(file_get_contents(app_path() . '/database/seeds/data/licenses.json')); if (!empty($licenses)) { $this->command->info('Licenses have been found, deleting the current ones, and replacing them with the new ones.'); // Empty the licenses table $this->command->info('Emptying the current licenses table.'); \License::truncate(); foreach ($licenses as $license) { \License::create(array('domain_content' => $license->domain_content, 'domain_data' => $license->domain_data, 'domain_software' => $license->domain_software, 'family' => $license->family, 'license_id' => $license->license_id, 'is_generic' => @$license->is_generic, 'is_okd_compliant' => $license->is_okd_compliant, 'is_osi_compliant' => $license->is_osi_compliant, 'maintainer' => $license->maintainer, 'status' => $license->status, 'title' => $license->title, 'url' => $license->url)); } $this->command->info('Added the licenses from a local json file.'); } else { $this->command->info('The licenses from the json file were empty, the old ones will not be replaced.'); } }
/** * Seed the themes * * @return @void */ private function seedLicenses() { $this->info('---- Seeding new licenses ----'); $license_name = $this->argument('name'); $license_uri = $this->licenses_uri . $license_name; if (substr($license_uri, -5) != '.json') { $license_uri .= '.json'; } // Try to get the themes from the ns.thedatatank.com (semantic data) try { $this->info('Trying to fetch triples from the uri: ' . $license_uri); try { $licenses_graph = \EasyRdf_Graph::newAndLoad($license_uri, 'jsonld'); } catch (\EasyRdf_Http_Exception $ex) { $this->info('We could not fetch licenses from the URL ' . $license_uri . ', defaulting to ' . $this->DEFAULT_LICENSE . '.'); $licenses_graph = $this->fetchDefaultGraph(); } if ($licenses_graph->isEmpty()) { $this->info('We could not fetch licenses from the URL ' . $license_uri . ', defaulting to ' . $this->DEFAULT_LICENSE . '.'); $licenses_graph = $this->fetchDefaultGraph(); } else { $this->info('Fetched new licenses, removing the old ones.'); // Empty the licenses table \License::truncate(); } // Fetch the resources with a skos:conceptScheme relationship $licenses = $licenses_graph->allOfType('cc:License'); $taxonomy_uris = array(); foreach ($licenses as $license) { $url = ''; $title = ''; $identifier = ''; $title_resource = $license->getLiteral('dc:title'); $identifier_resource = $license->getLiteral('dc:identifier'); if (!empty($title_resource)) { $title = $title_resource->getValue(); } if (!empty($identifier_resource)) { $identifier = $identifier_resource->getValue(); } if (!$license->isBNode()) { $url = $license->getUri(); } \License::create(['url' => $url, 'title' => $title, 'license_id' => $identifier]); $this->info('Added license "' . $identifier . '" with title "' . $title . '" and URI ' . $url); } } catch (EasyRdf_Exception $ex) { $this->info('An error occurred when we tried to fetch online themes.'); } }