-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathexportAuthorityRecordsTask.class.php
More file actions
83 lines (69 loc) · 2.59 KB
/
exportAuthorityRecordsTask.class.php
File metadata and controls
83 lines (69 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* This file is part of the Access to Memory (AtoM) software.
*
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Access to Memory (AtoM) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Export authority records to a CSV file.
*
* @author Mike Cantelon <mike@artefactual.com>
*/
class exportAuthorityRecordsTask extends exportBulkBaseTask
{
protected $namespace = 'csv';
protected $name = 'authority-export';
protected $briefDescription = 'Export authority record data as CSV file(s)';
protected $detailedDescription = <<<'EOF'
Export authority record data as CSV file(s).
EOF;
/**
* @see sfTask
*
* @param mixed $arguments
* @param mixed $options
*/
public function execute($arguments = [], $options = [])
{
$this->checkPathIsWritable($arguments['path']);
$configuration = ProjectConfiguration::getApplicationConfiguration('qubit', 'cli', false);
$this->context = sfContext::createInstance($configuration);
// Prepare CSV exporter
$writer = new csvActorExport($arguments['path']);
$writer->setOptions(['relations' => true]);
// Export actors and, optionally, related data
$itemsExported = 0;
foreach ($this->getActors() as $row) {
$actor = QubitActor::getById($row['id']);
$this->context->getUser()->setCulture($row['culture']);
$writer->exportResource($actor);
$this->indicateProgress(++$itemsExported);
}
$this->log('');
$this->logSection('csv', "Export complete ({$itemsExported} authority records exported).");
}
/**
* @see sfBaseTask
*/
protected function configure()
{
$this->addCoreArgumentsAndOptions();
}
private function getActors()
{
$sql = "SELECT ai.id, ai.culture FROM actor_i18n ai INNER JOIN object o ON ai.id=o.id
WHERE o.class_name='QubitActor' AND ai.id <> ?";
return QubitPdo::fetchAll($sql, [QubitActor::ROOT_ID], ['fetchMode' => PDO::FETCH_ASSOC]);
}
}