Created
January 25, 2017 04:45
-
-
Save kehh/c0b3d5b67a86c2d3e7d1e5546b6a2350 to your computer and use it in GitHub Desktop.
Export CollectiveAccess data importer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
require_once getenv('COLLECTIVEACCESS_HOME') . DIRECTORY_SEPARATOR . 'setup.php'; | |
require_once __CA_MODELS_DIR__ . DIRECTORY_SEPARATOR . 'ca_data_importers.php'; | |
$mapping = new ca_data_importers(); | |
$importers = []; | |
$mapping_dir = 'mappings'; | |
if (!is_dir($mapping_dir)) { | |
mkdir($mapping_dir); | |
} | |
$dm = Datamodel::load(); | |
foreach (ca_data_importers::find(['deleted' => false], ['returnAs' => 'ids']) as $id) { | |
$mapping->load($id); | |
$groups = $mapping->getGroups(); | |
$items = $mapping->getItems(); | |
$environment = $mapping->getEnvironment(); | |
$rules = $mapping->getRules(); | |
$resultGroups = []; | |
foreach ($items as $i => $item) { | |
/** @var ca_data_importer_groups $group */ | |
$group = $groups[$item['group_id']]; | |
$groupCode = $group['group_code']; | |
$groupSettings = $group->SETTINGS; | |
unset($item['item_id'], $item['importer_id'], $item['group_id']); | |
if (!isset($resultGroups[$groupCode]['settings'])) { | |
$resultGroups[$groupCode]['settings'][] = $groupSettings; | |
} | |
$resultGroups[$groupCode]['items'][] = $item; | |
} | |
$table = $dm->getTableName($mapping->get('table_num')); | |
$fileName = $mapping_dir . DIRECTORY_SEPARATOR . | |
$table . '.' . | |
$mapping->get('importer_code') . '.json'; | |
file_put_contents($fileName, | |
json_encode( | |
[ | |
'importer' => $mapping->getFieldValuesArray(), | |
'importer_code' => $mapping->get('importer_code'), | |
'importer_name' => $mapping->getPreferredLabels(null, false, ['forDisplay' => true]), | |
'table' => $table, | |
'settings' => $mapping->SETTINGS, | |
'groups' => $resultGroups | |
], | |
JSON_PRETTY_PRINT) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment