Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit f7f9cb9

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents ad755bc + 6ca6359 commit f7f9cb9

File tree

4 files changed

+71
-54
lines changed

4 files changed

+71
-54
lines changed

core/src/plugins/access.fs/class.fsAccessDriver.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,17 +1863,23 @@ public function delete($selectedFiles, &$logMessages)
18631863
return $mess[120];
18641864
}
18651865
$fileToDelete=$this->urlBase.$selectedFile;
1866+
18661867
if (!file_exists($fileToDelete)) {
18671868
$logMessages[]=$mess[100]." ".SystemTextEncoding::toUTF8($selectedFile);
18681869
continue;
18691870
}
1871+
1872+
$node = new AJXP_Node($fileToDelete);
1873+
$node->setLeaf(!is_dir($fileToDelete));
1874+
18701875
$this->deldir($fileToDelete, $repoData);
1871-
if (is_dir($fileToDelete)) {
1876+
1877+
if ($node->isLeaf()) {
18721878
$logMessages[]="$mess[38] ".SystemTextEncoding::toUTF8($selectedFile)." $mess[44].";
18731879
} else {
18741880
$logMessages[]="$mess[34] ".SystemTextEncoding::toUTF8($selectedFile)." $mess[44].";
18751881
}
1876-
AJXP_Controller::applyHook("node.change", array(new AJXP_Node($fileToDelete)));
1882+
AJXP_Controller::applyHook("node.change", [$node]);
18771883
}
18781884
return null;
18791885
}

core/src/plugins/core.mailer/class.AjxpMailer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ public function mailConsumeQueue ($action, $httpVars, $fileVars) {
7676
$ajxpAction = $ajxpNotification->getAction();
7777
$ajxpAuthor = $ajxpNotification->getAuthor();
7878
$ajxpNode = new AJXP_Node($value['url']);
79+
7980
try{
8081
@$ajxpNode->loadNodeInfo();
81-
}catch(Exception $e){}
82+
} catch(Exception $e) {
83+
// do nothing
84+
}
85+
8286
if ($ajxpNode->isLeaf() && !$ajxpNode->isRoot()) {
8387
$ajxpContent = $ajxpNode->getParent()->getPath();
8488
} else {
@@ -87,20 +91,24 @@ public function mailConsumeQueue ($action, $httpVars, $fileVars) {
8791
$ajxpContent = '/';
8892
}
8993
}
90-
if($ajxpNode->getRepository() != null){
94+
if($ajxpNode->getRepository() != null) {
9195
$ajxpNodeWorkspace = $ajxpNode->getRepository()->getDisplay();
92-
}else{
96+
} else {
9397
$ajxpNodeWorkspace = "Deleted Workspace";
9498
}
99+
95100
$recipientFormats[$value['recipient']] = ($value["html"] == 1);
96101
$ajxpKey = $ajxpAction."|".$ajxpAuthor."|".$ajxpContent;
97102
$arrayResultsSQL[$value['recipient']][$ajxpNodeWorkspace][$ajxpKey][] = $ajxpNotification;
98103
}
99104
//this $body must be here because we need this css
100105
$digestTitle = ConfService::getMessages()["core.mailer.9"];
106+
101107
foreach ($arrayResultsSQL as $recipient => $arrayWorkspace) {
108+
102109
$useHtml = $recipientFormats[$recipient];
103110
$body = $useHtml ? "<div id='digest'>" : "";
111+
104112
foreach ($arrayWorkspace as $workspace => $arrayAjxpKey) {
105113
$key = key($arrayAjxpKey);
106114
$body = $body . '<h1>' . $arrayAjxpKey[$key][0]->getDescriptionLocation() . ', </h1><ul>';
@@ -120,6 +128,7 @@ public function mailConsumeQueue ($action, $httpVars, $fileVars) {
120128
}
121129
$body = $body . '</ul>';
122130
}
131+
123132
$body .= $useHtml ? "</div>" : "";
124133
try {
125134
$mailer->sendMail(array($recipient),
@@ -134,6 +143,7 @@ public function mailConsumeQueue ($action, $httpVars, $fileVars) {
134143
$output["error"][] = "Sending email to ".$recipient.": ".$e->getMessage();
135144
}
136145
}
146+
137147
try {
138148
dibi::query('DELETE FROM [ajxp_mail_queue] WHERE [date_event] <= %s', $time);
139149
} catch (DibiException $e) {

core/src/plugins/core.notifications/class.AJXP_Notification.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ public function getDescriptionLong($skipLink = false)
201201
$tpl .= "</ul>";
202202

203203
} else {
204-
205204
$tpl .= $this->replaceVars($mess["notification.tpl.long.".($this->getNode()->isLeaf()?"file":"folder").".".$this->action], $mess);
206205

207206
}

core/src/plugins/index.elasticsearch/class.AjxpElasticSearch.php

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,7 @@
2121

2222
defined('AJXP_EXEC') or die( 'Access not allowed');
2323

24-
25-
/**
26-
* Autoload function for Elastica classes
27-
* @param $class
28-
*/
29-
function __autoload_elastica ($class)
30-
{
31-
$path = AJXP_INSTALL_PATH."/plugins/index.elasticsearch/";
32-
$class = str_replace('\\', '/', $class);
33-
34-
if (file_exists($path . $class . '.php')) {
35-
require_once($path . $class . '.php');
36-
}
37-
}
38-
39-
spl_autoload_register('__autoload_elastica');
40-
24+
require_once (dirname(__FILE__)."/vendor/autoload.php");
4125

4226
/**
4327
* Encapsultion of the Elastica component as a plugin
@@ -55,7 +39,7 @@ class AjxpElasticSearch extends AbstractSearchEngineIndexer
5539
private $nextId;
5640
private $lastIdPath;
5741

58-
private $metaFields = array();
42+
private $metaFields = [];
5943
private $indexContent = false;
6044
private $specificId = "";
6145
private $verboseIndexation = false;
@@ -90,9 +74,9 @@ public function initMeta($accessDriver)
9074
$el = $this->getXPath()->query("/indexer")->item(0);
9175
if ($this->indexContent) {
9276
if($this->indexContent) $metaFields[] = "ajxp_document_content";
93-
$data = array("indexed_meta_fields" => $metaFields,
94-
"additionnal_meta_columns" => array("ajxp_document_content" => "Content")
95-
);
77+
$data = ["indexed_meta_fields" => $metaFields,
78+
"additionnal_meta_columns" => ["ajxp_document_content" => "Content"]
79+
];
9680
$el->setAttribute("indexed_meta_fields", json_encode($data));
9781
} else {
9882
$el->setAttribute("indexed_meta_fields", json_encode($metaFields));
@@ -154,15 +138,14 @@ public function applyAction($actionName, $httpVars, $fileVars)
154138
}
155139
}
156140

157-
158141
$this->currentIndex->open();
159142
$fieldQuery = new Elastica\Query\QueryString();
160-
$fieldQuery->setAllowLeadingWildcard(false);
143+
$fieldQuery->setAllowLeadingWildcard(true);
161144
$fieldQuery->setFuzzyMinSim(0.8);
162145

163146
if($textQuery == "*"){
164147

165-
$fields = array("ajxp_node");
148+
$fields = ["ajxp_node"];
166149
$fieldQuery->setQuery("yes");
167150
$fieldQuery->setFields($fields);
168151

@@ -175,7 +158,7 @@ public function applyAction($actionName, $httpVars, $fileVars)
175158

176159
} else{
177160

178-
$fields = array("basename","ajxp_meta_*", "node_*","body");
161+
$fields = ["basename","ajxp_meta_*", "body"];
179162
$fieldQuery->setQuery($textQuery);
180163
$fieldQuery->setFields($fields);
181164

@@ -214,25 +197,21 @@ public function applyAction($actionName, $httpVars, $fileVars)
214197
if(isSet($httpVars['limit'])){
215198
$maxResults = intval($httpVars['limit']);
216199
}
217-
$searchOptions = array(
200+
$searchOptions = [
218201
\Elastica\Search::OPTION_SEARCH_TYPE => \Elastica\Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH,
219-
\Elastica\Search::OPTION_SIZE => $maxResults);
202+
\Elastica\Search::OPTION_SIZE => $maxResults];
220203

221204
$this->logDebug(__FUNCTION__,"Executing query: ", $textQuery);
222205
$fullQuery = new Elastica\Query();
223206
$fullQuery->setQuery($fieldQuery);
224207

225208
$qb = new Elastica\QueryBuilder();
226209
$fullQuery = new Elastica\Query();
210+
$filter = $qb->query()->match("ajxp_scope", "shared");
227211
$fullQuery->setQuery(
228-
$qb->query()->filtered(
229-
$fieldQuery,
230-
$qb->filter()->bool()
231-
->addMust(new Elastica\Filter\Term(array("ajxp_scope" => "shared")))
232-
)
212+
$qb->query()->bool()->addMust($fieldQuery)->addFilter($filter)
233213
);
234214

235-
236215
$result = $search->search($fullQuery, $searchOptions);
237216
$this->logDebug(__FUNCTION__,"Search finished. ");
238217
$hits = $result->getResults();
@@ -268,9 +247,12 @@ public function applyAction($actionName, $httpVars, $fileVars)
268247
} catch (Exception $ex) {
269248
throw new Exception($messages["index.lucene.7"]);
270249
}
250+
251+
/*
271252
$sParts = array();
272253
$searchField = $httpVars["field"];
273254
255+
274256
if ($scope == "user") {
275257
if (AuthService::usersEnabled() && AuthService::getLoggedUser() == null) {
276258
throw new Exception("Cannot find current user");
@@ -281,8 +263,9 @@ public function applyAction($actionName, $httpVars, $fileVars)
281263
$sParts[] = "ajxp_scope:shared";
282264
}
283265
$query = implode(" AND ", $sParts);
284-
$this->logDebug("Query : $query");
266+
$this->logDebug("Query : $query");*/
285267

268+
$searchField = AJXP_Utils::sanitize($httpVars["field"], AJXP_SANITIZE_ALPHANUM);
286269

287270
$fieldQuery = new Elastica\Query\QueryString();
288271
$fields = array($searchField);
@@ -304,18 +287,17 @@ public function applyAction($actionName, $httpVars, $fileVars)
304287
\Elastica\Search::OPTION_SEARCH_TYPE => \Elastica\Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH,
305288
\Elastica\Search::OPTION_SIZE => $maxResults);
306289

307-
// ADD SCOPE FILTER
290+
/* ADD SCOPE FILTER
308291
$term = new Elastica\Filter\Term();
309-
$term->setTerm("ajxp_scope", "user");
292+
$term->setTerm("ajxp_scope", "user");*/
310293

311294
$qb = new Elastica\QueryBuilder();
312295
$fullQuery = new Elastica\Query();
313296
$fullQuery->setQuery(
314-
$qb->query()->filtered(
315-
$fieldQuery,
316-
$qb->filter()->bool()
317-
->addMust(new Elastica\Filter\Term(array("ajxp_scope" => "user")))
318-
->addMust(new Elastica\Filter\Term(array("user" => AuthService::getLoggedUser()->getId())))
297+
$qb->query()->bool()
298+
->addMust($fieldQuery)
299+
->addMust($qb->query()->match("ajxp_scope", "user"))
300+
->addMust($qb->query()->match("user", AuthService::getLoggedUser()->getId())
319301
)
320302
);
321303

@@ -324,6 +306,8 @@ public function applyAction($actionName, $httpVars, $fileVars)
324306
$hits = $result->getResults();
325307

326308
AJXP_XMLWriter::header();
309+
310+
$leafNodes = [];
327311
foreach ($hits as $hit) {
328312
if ($hit->serialized_metadata!=null) {
329313
$meta = unserialize(base64_decode($hit->serialized_metadata));
@@ -337,13 +321,26 @@ public function applyAction($actionName, $httpVars, $fileVars)
337321
continue;
338322
}
339323
$tmpNode->search_score = sprintf("%0.2f", $hit->score);
340-
AJXP_XMLWriter::renderAjxpNode($tmpNode);
324+
325+
if($tmpNode->isLeaf()){
326+
$leafNodes[]= $tmpNode;
327+
} else {
328+
AJXP_XMLWriter::renderAjxpNode($tmpNode);
329+
}
330+
331+
}
332+
foreach ($leafNodes as $leaf) {
333+
AJXP_XMLWriter::renderAjxpNode($leaf);
341334
}
335+
342336
AJXP_XMLWriter::close();
343337
}
344338

345339
}
346340

341+
/**
342+
* @param $url
343+
*/
347344
public function recursiveIndexation($url)
348345
{
349346
//print("Indexing $url \n");
@@ -501,7 +498,7 @@ public function createIndexedDocument($ajxpNode)
501498
$parseContent = false;
502499
}
503500

504-
$data = array();
501+
$data = [];
505502
$data["node_url"] = $ajxpNode->getUrl();
506503
$data["node_path"] = str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath());
507504
$data["basename"] = basename($ajxpNode->getPath());
@@ -575,22 +572,27 @@ public function createIndexedDocument($ajxpNode)
575572

576573
}
577574

575+
/**
576+
* Transform not data to ready to store mapping
577+
* @param $data
578+
* @return array
579+
*/
578580
protected function dataToMappingProperties($data){
579581

580-
$mapping_properties = array();
582+
$mapping_properties = [];
581583
foreach ($data as $key => $value) {
582584
if ($key == "node_url" || $key == "node_path") {
583-
$mapping_properties[$key] = array("type" => "string", "index" => "not_analyzed");
585+
$mapping_properties[$key] = ["type" => "string", "index" => "not_analyzed"];
584586
} else if($key == "serialized_metadata"){
585-
$mapping_properties[$key] = array("type" => "string" /*, "index" => "no" */);
587+
$mapping_properties[$key] = ["type" => "string" /*, "index" => "no" */];
586588
} else if ($key == "ajxp_bytesize"){
587-
$mapping_properties[$key] = array("type" => "long");
589+
$mapping_properties[$key] = ["type" => "long"];
588590
} else {
589591
$type = gettype($value);
590592
if ($type != "integer" && $type != "boolean" && $type != "double") {
591593
$type = "string";
592594
}
593-
$mapping_properties[$key] = array("type" => $type);
595+
$mapping_properties[$key] = ["type" => $type];
594596
}
595597
}
596598
return $mapping_properties;

0 commit comments

Comments
 (0)