1
0
Fork 0
mirror of https://github.com/sbrl/Pepperminty-Wiki.git synced 2024-12-22 13:45:02 +00:00

Make sure that all files are stored in the data directories.

Fixes #89.
This commit is contained in:
Starbeamrainbowlabs 2016-08-19 10:00:03 +01:00
parent 3a7b9412ac
commit 27acc2420b
5 changed files with 22 additions and 18 deletions

View file

@ -526,10 +526,10 @@ function check_subpage_parents($pagename)
$parent_pagename = substr($pagename, 0, strrpos($pagename, "/"));
$parent_page_filename = "$parent_pagename.md";
if(!file_exists($parent_page_filename))
if(!file_exists($env->storage_prefix . $parent_page_filename))
{
// This parent page doesn't exist! Create it and add it to the page index.
touch($parent_page_filename, 0);
touch($env->storage_prefix . $parent_page_filename, 0);
$newentry = new stdClass();
$newentry->filename = $parent_page_filename;
@ -2340,7 +2340,7 @@ class search
self::merge_into_invindex($invindex, ids::getid($pagename), $index);
}
error_log("Saving inverted index to $paths->searchindex");
self::save_invindex($paths->searchindex, $invindex);
}
@ -3734,14 +3734,16 @@ DIFFSCRIPT;
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
}
// -----~~~==~~~-----
// Update the inverted search index
// Construct an index for the old and new page content
$oldindex = [];
$oldpagedata = ""; // We need the old page data in order to pass it to the preprocessor
if(file_exists("$env->page.md"))
if(file_exists("$env->storage_prefix$env->page.md"))
{
$oldpagedata = file_get_contents("$env->page.md");
$oldpagedata = file_get_contents("$env->storage_prefix$env->page.md");
$oldindex = search::index($oldpagedata);
}
$newindex = search::index($pagedata);
@ -3751,13 +3753,13 @@ DIFFSCRIPT;
$removals = [];
search::compare_indexes($oldindex, $newindex, $additions, $removals);
// Load in the inverted index
$invindex = search::load_invindex("./invindex.json");
$invindex = search::load_invindex($env->storage_prefix . "invindex.json");
// Merge the changes into the inverted index
search::merge_into_invindex($invindex, ids::getid($env->page), $additions, $removals);
// Save the inverted index back to disk
search::save_invindex("invindex.json", $invindex);
search::save_invindex($env->storage_prefix . "invindex.json", $invindex);
// -----~~~==~~~-----
if(file_put_contents("$env->storage_prefix$env->page.md", $pagedata) !== false)
{

View file

@ -227,10 +227,10 @@ function check_subpage_parents($pagename)
$parent_pagename = substr($pagename, 0, strrpos($pagename, "/"));
$parent_page_filename = "$parent_pagename.md";
if(!file_exists($parent_page_filename))
if(!file_exists($env->storage_prefix . $parent_page_filename))
{
// This parent page doesn't exist! Create it and add it to the page index.
touch($parent_page_filename, 0);
touch($env->storage_prefix . $parent_page_filename, 0);
$newentry = new stdClass();
$newentry->filename = $parent_page_filename;

View file

@ -68,7 +68,7 @@
"author": "Starbeamrainbowlabs",
"description": "Adds proper search functionality to Pepperminty Wiki using an inverted index to provide a full text search engine. If pages don't show up, then you might have hit a stop word. If not, try requesting the `invindex-rebuild` action to rebuild the inverted index from scratch.",
"id": "feature-search",
"lastupdate": 1465757892,
"lastupdate": 1471592829,
"optional": false
},
{
@ -113,7 +113,7 @@
"author": "Starbeamrainbowlabs",
"description": "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id": "page-edit",
"lastupdate": 1471549914,
"lastupdate": 1471596690,
"optional": false
},
{

View file

@ -267,7 +267,7 @@ class search
self::merge_into_invindex($invindex, ids::getid($pagename), $index);
}
error_log("Saving inverted index to $paths->searchindex");
self::save_invindex($paths->searchindex, $invindex);
}

View file

@ -233,14 +233,16 @@ DIFFSCRIPT;
exit(page_renderer::render_main("Edit Conflict - $env->page - $settings->sitename", $content));
}
// -----~~~==~~~-----
// Update the inverted search index
// Construct an index for the old and new page content
$oldindex = [];
$oldpagedata = ""; // We need the old page data in order to pass it to the preprocessor
if(file_exists("$env->page.md"))
if(file_exists("$env->storage_prefix$env->page.md"))
{
$oldpagedata = file_get_contents("$env->page.md");
$oldpagedata = file_get_contents("$env->storage_prefix$env->page.md");
$oldindex = search::index($oldpagedata);
}
$newindex = search::index($pagedata);
@ -250,13 +252,13 @@ DIFFSCRIPT;
$removals = [];
search::compare_indexes($oldindex, $newindex, $additions, $removals);
// Load in the inverted index
$invindex = search::load_invindex("./invindex.json");
$invindex = search::load_invindex($env->storage_prefix . "invindex.json");
// Merge the changes into the inverted index
search::merge_into_invindex($invindex, ids::getid($env->page), $additions, $removals);
// Save the inverted index back to disk
search::save_invindex("invindex.json", $invindex);
search::save_invindex($env->storage_prefix . "invindex.json", $invindex);
// -----~~~==~~~-----
if(file_put_contents("$env->storage_prefix$env->page.md", $pagedata) !== false)
{