12 require_once
'WHAT/Lib.Common.php';
43 $res = $this->
sqlQuery(
'SELECT count(id_file) AS count, sum(size) AS size, pg_size_pretty(sum(size)) AS size_pretty FROM vaultdiskstorage');
44 $t = pg_fetch_array($res, NULL, PGSQL_ASSOC);
50 $res = $this->
sqlQuery(
'SELECT count(id_file) AS count, sum(size) AS size, pg_size_pretty(sum(size)) AS size_pretty FROM vaultdiskstorage WHERE NOT EXISTS (SELECT 1 FROM docvaultindex WHERE vaultid = id_file)');
51 $t = pg_fetch_array($res, NULL, PGSQL_ASSOC);
57 $res = $this->
sqlQuery(
'SELECT count(id_file) AS count, sum(size) AS size, pg_size_pretty(sum(size)) AS size_pretty FROM vaultdiskstorage WHERE EXISTS (SELECT 1 FROM docvaultindex WHERE vaultid = id_file)');
58 $t = pg_fetch_array($res, NULL, PGSQL_ASSOC);
73 SELECT id_file, vdfs.r_path AS vault_root, l_path ||
'/' || vds.id_file ||
74 CASE WHEN
name ~ E
'\\.[^.]+$' THEN regexp_replace(
name, E
'.*(\\.[^.]+)$', E
'\\1')
77 FROM vaultdiskfsstorage AS vdfs, vaultdiskdirstorage AS vdds, vaultdiskstorage AS vds
79 vds.id_fs = vdfs.id_fs
80 AND vds.id_dir = vdds.id_dir
81 AND vdds.id_fs = vds.id_fs
83 SELECT files.*, dvi.* FROM files LEFT OUTER JOIN docvaultindex AS dvi ON vaultid = id_file
84 ORDER BY id_file,
docid
89 $count = pg_num_rows($res);
100 protected function getFamilies()
103 $s = new \SearchDoc(
'', -1);
104 $s->setObjectReturn(
true);
110 foreach ($iterator as $fam) {
113 foreach ($fam->getAttributes() as $attr) {
114 if (!$attr || ($attr->type !=
'file' && $attr->type !=
'image')) {
117 if ($attr->usefor !=
'Q') {
121 $set[$fam->id] = array(
123 'name' => $fam->name,
124 'title' => $fam->title,
126 'vid' => \Dcp\Core\vidExtractor\vidExtractor::getVidsFromDocFam($fam)
136 throw new \Dcp\SearchDoc\Exception(
$err);
153 $mode = (
$check ?
'Checking' :
'Re-indexing');
158 $this->
verbose(
"[+] Locking tables...\n");
159 $this->
sqlQuery(
"LOCK TABLE docvaultindex, doc * IN ACCESS EXCLUSIVE MODE");
160 $this->
sqlQuery(
"CREATE TEMPORARY TABLE tmp_docvaultindex (LIKE docvaultindex) ON COMMIT DROP");
161 $this->
sqlQuery(
"CREATE TEMPORARY TABLE tmp2_docvaultindex (LIKE docvaultindex) ON COMMIT DROP");
162 $this->
sqlPrepare(self::STMT_INSERT_TMP,
"INSERT INTO tmp_docvaultindex(docid, vaultid) VALUES ($1, $2)");
165 $this->
verbose(
"[+] Analyzing dead entries in docvaultindex...\n");
166 $this->
sqlQuery(
"DELETE FROM docvaultindex WHERE NOT EXISTS (SELECT 1 FROM doc WHERE id = docid)");
169 $this->
verbose(
"[+] Analyzing families...\n");
170 $families = $this->getFamilies();
174 foreach ($families as
$famid => & $fam) {
176 $this->
verbose(
"[+] (%d/%d) %s family '%s'...\n", $famIndex, count($families) , $mode, $fam[
'name']);
177 foreach ($fam[
'vid'] as $vid) {
178 $this->
sqlExec(self::STMT_INSERT_TMP, array(
185 $relname = sprintf(
"doc%d",
$famid);
186 $res = $this->
sqlQuery(sprintf(
"SELECT count(id) FROM ONLY %s", pg_escape_identifier($relname)));
187 $row = pg_fetch_row($res, 0);
191 if (count($fam[
'file_attributes']) > 0) {
192 $addColumns = array();
193 foreach ($fam[
'file_attributes'] as $attrid) {
194 $addColumns[] = pg_escape_identifier($attrid);
196 $addColumns =
", " . join(
", ", $addColumns);
201 $this->
verbose(
"[+] %s '%d' documents from family '%s'...\n", $mode, $count, $fam[
'name']);
208 foreach (
$rows as $row) {
211 foreach ($vidList as $vid) {
212 $this->
sqlExec(self::STMT_INSERT_TMP, array(
218 $pom->progress($rowIndex);
230 $this->
sqlQuery(
"INSERT INTO tmp2_docvaultindex (docid, vaultid) SELECT DISTINCT ON (docid, vaultid) docid, vaultid FROM tmp_docvaultindex");
232 $this->
sqlQuery(
"DROP TABLE tmp_docvaultindex");
233 $this->
sqlQuery(
"ALTER TABLE tmp2_docvaultindex RENAME TO tmp_docvaultindex");
235 $res = $this->
sqlQuery(
"SELECT * FROM tmp_docvaultindex AS d1 WHERE NOT EXISTS (SELECT 1 FROM docvaultindex AS d2 WHERE d2.docid = d1.docid AND d2.vaultid = d1.vaultid) ORDER BY docid, vaultid");
237 'count' => pg_num_rows($res) ,
241 $res = $this->
sqlQuery(
"SELECT * FROM docvaultindex AS d1 WHERE NOT EXISTS (SELECT 1 FROM tmp_docvaultindex AS d2 WHERE d2.docid = d1.docid AND d2.vaultid = d1.vaultid) ORDER BY docid, vaultid");
243 'count' => pg_num_rows($res) ,
249 'missing' => $missing
254 return (
$report[
'new'][
'count'] == 0 &&
$report[
'missing'][
'count'] == 0);
257 $this->
verbose(
"[+] Committing docvaultindex...\n");
258 $this->
sqlQuery(
"DELETE FROM docvaultindex");
259 $this->
sqlQuery(
"INSERT INTO docvaultindex (docid, vaultid) SELECT docid, vaultid FROM tmp_docvaultindex");
260 $this->
sqlQuery(
"DROP TABLE tmp_docvaultindex");
270 call_user_func_array(
"printf", func_get_args());
278 $res = $this->
sqlQuery(
"DELETE FROM docvaultindex WHERE NOT EXISTS (SELECT 1 FROM doc WHERE id = docid) RETURNING *");
279 $count = pg_num_rows($res);
291 $res = $this->
sqlExec(self::STMT_DELETE_ID_FILE, array(
294 $count = pg_num_rows($res);
308 id_file, vdfs.r_path AS vault_root, l_path ||
'/' || vds.id_file ||
309 CASE WHEN
name ~ E
'\\.[^.]+$' THEN regexp_replace(
name, E
'.*(\\.[^.]+)$', E
'\\1')
312 FROM vaultdiskfsstorage AS vdfs, vaultdiskdirstorage AS vdds, vaultdiskstorage AS vds
314 vds.id_fs = vdfs.id_fs
315 AND vds.id_dir = vdds.id_dir
316 AND vdds.id_fs = vds.id_fs
317 AND NOT EXISTS (SELECT 1 FROM docvaultindex WHERE vaultid = id_file)
322 $count = pg_num_rows($res);
335 pg_close($this->_conn);
340 $this->_conn = getDbId(
'');
341 $this->
sqlPrepare(self::STMT_DELETE_ID_FILE,
'DELETE FROM vaultdiskstorage WHERE id_file = $1 RETURNING *');
370 return sprintf(
"%s:%d", __CLASS__, self::$savePointSeq++);
375 $res = pg_query($this->_conn,
$query);
376 if ($res ===
false) {
384 $res = pg_query($this->_conn,
$query);
385 if ($res ===
false) {
388 $row = pg_fetch_row($res);
389 if ($row ===
false) {
397 $res = pg_execute($this->_conn, $stmt, $argv);
398 if ($res ===
false) {
406 $res = pg_prepare($this->_conn, $stmt,
$query);
407 if ($res ===
false) {
searchErrors(\SearchDoc $searchDoc)
print $fam getTitle() $fam name
Exception class use exceptionCode to identifiy correctly exception.
checkDocVaultIndex(&$report)
_regenerateDocVaultIndex($check=true, &$report)
if($updateExistingTable) $point
regenerateDocVaultIndex(&$report)
if(is_numeric($parms['famid'])) $attrList
const STMT_DELETE_ID_FILE
sqlPrepare($stmt, $query)
if(($docid!==0)&&(!is_numeric($docid))) $query
if($file) if($subject==""&&$file) if($subject=="") $err