echo PHP_EOL . 'datasets from json_backup: ' . sizeof($json_backup_epa) . PHP_EOL . PHP_EOL; } else { $json_backup_epa = json_decode(file_get_contents($results_dir . '/json_backup.json')); echo PHP_EOL . 'datasets from json_backup: ' . sizeof($json_backup_epa) . PHP_EOL . PHP_EOL; } $json_backup_tags = []; $json_datasets = json_decode(file_get_contents(CKANMNGR_DATA_DIR . '/epa-gov.json'), true); //assoc foreach ($json_datasets as $dataset_array) { $dataset = new Dataset($dataset_array); $groups_tags = $dataset->get_groups_and_tags(); if (!$groups_tags) { unset($dataset); continue; } $title_simple = Dataset::simplifyTitle($dataset_array['title']); if (!isset($json_backup_tags[$title_simple])) { $json_backup_tags[$title_simple] = []; } foreach ($groups_tags as $group => $tags) { if (isset($json_backup_tags[$title_simple][$group])) { $json_backup_tags[$title_simple][$group] = array_merge($json_backup_tags[$title_simple][$group], $tags); } else { $json_backup_tags[$title_simple][$group] = $tags; } } unset($dataset); } $json_backup_epa_by_title = $json_backup_epa_by_guid = []; foreach ($json_backup_epa as $name => $dataset) { $title = $dataset['title_simple'];
$ProdCkanManager->resultsDir = $results_dir; $prod = $ProdCkanManager->exportFiltered('organization:' . $organization . ' AND dataset_type:dataset', '', ['title', 'title_simple', 'name', 'url', 'identifier', 'guid', 'metadata_created', 'metadata_modified', 'extras_modified', 'topics', 'categories', 'tagging']); file_put_contents($results_dir . '/' . $organization . '_export.json', json_encode($prod, JSON_PRETTY_PRINT)); $prod_csv = new Writer($results_dir . '/' . $organization . '_export.csv'); $headers = array_keys($prod[array_keys($prod)[0]]); $prod_csv->writeRow($headers); $prod_csv->writeFromArray($prod); echo PHP_EOL . 'datasets from prod: ' . sizeof($prod) . PHP_EOL . PHP_EOL; } else { $prod = json_decode(file_get_contents($results_dir . '/' . $organization . '_export.json'), true); echo PHP_EOL . 'datasets from prod: ' . sizeof($prod) . PHP_EOL . PHP_EOL; } if (!is_file($results_dir . '/' . $organization . '_export_sorted.json')) { $prod_sorted = []; foreach ($prod as $dataset_array) { $index = Dataset::simplifyTitle($dataset_array['title_simple'] . '_' . $dataset_array['identifier']); if (!isset($prod_sorted[$index])) { $prod_sorted[$index] = []; } $prod_sorted[$index][] = $dataset_array; } file_put_contents($results_dir . '/' . $organization . '_export_sorted.json', json_encode($prod_sorted, JSON_PRETTY_PRINT)); } else { $prod_sorted = json_decode(file_get_contents($results_dir . '/' . $organization . '_export_sorted.json'), true); echo PHP_EOL . 'datasets sorted from prod: ' . sizeof($prod) . PHP_EOL . PHP_EOL; } if (!is_file($results_dir . '/' . $organization . '_tagging.csv')) { $empty_tags = serialize([]); $tagging_csv = new Writer($results_dir . '/' . $organization . '_tagging.csv'); $tagging_csv->writeRow(['url', 'topic', 'tags']); foreach ($prod_sorted as $title_simple => $brothers) {