Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
refreshVaultIndex.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Reinit vault files
4  *
5  * @author Anakeen
6  * @package FDL
7 */
8 
9 global $action;
10 
11 include_once ('FDL/Class.Doc.php');
12 include_once ('FDL/Class.DocFam.php');
13 include_once ('FDL/Class.DocVaultIndex.php');
14 include_once ('VAULT/Class.VaultFile.php');
15 /**
16  * Parse arguments
17  */
18 $usage = new ApiUsage();
19 $usage->setDefinitionText("Re-initialize docvaultindex table");
20 /* --dryrun=no|yes (default 'no') */
21 $check = ($usage->addEmptyParameter("dryrun", "Check consistency only (non-destructive mode)") !== false);
22 $csv = $usage->addOptionalParameter("csv", "Output details to CSV file (with comma delimiter [,], double-quote enclosure [\"], and backslash escape char [\\])", null, false);
23 $usage->verify();
24 
25 $vaultAnalyzer = new \Dcp\Vault\VaultAnalyzer();
26 $report = array();
27 $consistent = false;
28 if ($check) {
29  $consistent = $vaultAnalyzer->checkDocVaultIndex($report);
30 } else {
31  $consistent = $vaultAnalyzer->regenerateDocVaultIndex($report);
32 }
33 if ($csv !== false) {
35 } else {
37 }
38 if ($consistent) {
39  exit(0);
40 } else {
41  exit(1);
42 }
43 
45 {
46  printf("\n");
47  printf("[+] Summary:\n");
48  printf("New entries: %d\n", $report['new']['count']);
49  printf("Missing entries: %d\n", $report['missing']['count']);
50 }
51 
53 {
55  if (($fh = fopen($outfile, 'w')) === false) {
56  throw new \Dcp\Exception(sprintf("Error opening CSV output file '%s' for writing!", $outfile));
57  }
58  try {
59  xfputcsv($fh, array(
60  'new/missing',
61  'docid',
62  'vaultid'
63  ));
64  foreach ($report['new']['iterator'] as $row) {
65  xfputcsv($fh, array(
66  'new',
67  $row['docid'],
68  $row['vaultid']
69  ));
70  }
71  foreach ($report['missing']['iterator'] as $row) {
72  xfputcsv($fh, array(
73  'missing',
74  $row['docid'],
75  $row['vaultid']
76  ));
77  }
78  }
79  catch(\Dcp\Exception $e) {
80  fclose($fh);
81  throw $e;
82  }
83 }
84 
85 function xfputcsv($fh, $fields)
86 {
87  if (($ret = fputcsv($fh, $fields)) === false) {
88  throw new \Dcp\Exception(sprintf(""));
89  }
90  return $ret;
91 }
report2cli($report)
$ret
$vaultAnalyzer
global $action
$outfile
xfputcsv($fh, $fields)
switch($command) exit
Definition: checkVault.php:46
Verify arguments for wsh programs.
report2csv($report, $outfile)
← centre documentaire © anakeen