Skip to content

Commit

Permalink
Introduce metadata write wrapper p_save_metadata
Browse files Browse the repository at this point in the history
p_purge_metadata now updates the metadata cache and the INFO array like the other metadata writing functions
  • Loading branch information
adrianheine committed Nov 13, 2010
1 parent 8079aa0 commit 1172f8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
40 changes: 24 additions & 16 deletions inc/parserutils.php
Expand Up @@ -223,7 +223,7 @@ function p_get_instructions($text){
* @author Esther Brunner <esther@kaffeehaus.ch>
*/
function p_get_metadata($id, $key='', $render=false){
global $ID, $INFO, $cache_metadata;
global $ID;

// cache the current page
// Benchmarking shows the current page's metadata is generally the only page metadata
Expand All @@ -234,11 +234,7 @@ function p_get_metadata($id, $key='', $render=false){
// metadata has never been rendered before - do it! (but not for non-existent pages)
if ($render && !isset($meta['current']['description']['abstract']) && page_exists($id)){
$meta = p_render_metadata($id, $meta);
io_saveFile(metaFN($id, '.meta'), serialize($meta));

// sync cached copies, including $INFO metadata
if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }
p_save_metadata($id, $meta);
}

$val = $meta['current'];
Expand Down Expand Up @@ -305,13 +301,7 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){
// save only if metadata changed
if ($meta == $orig) return true;

// sync cached copies, including $INFO metadata
global $cache_metadata, $INFO;

if (!empty($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }

return io_saveFile(metaFN($id, '.meta'), serialize($meta));
return p_save_metadata($id, $meta);
}

/**
Expand All @@ -321,16 +311,16 @@ function p_set_metadata($id, $data, $render=false, $persistent=true){
* @author Michael Klier <chi@chimeric.de>
*/
function p_purge_metadata($id) {
$metafn = metaFN('id', '.meta');
$meta = p_read_metadata($id);
$meta = p_read_metadata($id);
foreach($meta['current'] as $key => $value) {
if(is_array($meta[$key])) {
$meta['current'][$key] = array();
} else {
$meta['current'][$key] = '';
}

}
return io_saveFile(metaFN($id, '.meta'), serialize($meta));
return p_save_metadata($id, $meta);
}

/**
Expand Down Expand Up @@ -360,6 +350,24 @@ function p_read_metadata($id,$cache=false) {
return $meta;
}

/**
* This is the backend function to save a metadata array to a file
*
* @param string $id absolute wiki page id
* @param array $meta metadata
*
* @return bool success / fail
*/
function p_save_metadata($id, $meta) {
// sync cached copies, including $INFO metadata
global $cache_metadata, $INFO;

if (isset($cache_metadata[$id])) $cache_metadata[$id] = $meta;
if (!empty($INFO) && ($id == $INFO['id'])) { $INFO['meta'] = $meta['current']; }

return io_saveFile(metaFN($id, '.meta'), serialize($meta));
}

/**
* renders the metadata of a page
*
Expand Down
4 changes: 2 additions & 2 deletions lib/exe/indexer.php
Expand Up @@ -190,7 +190,7 @@ function metaUpdate(){

// rendering needed?
if (@file_exists($file)) return false;
if (!@file_exists(wikiFN($ID))) return false;
if (!page_exists($ID)) return false;

global $conf;

Expand All @@ -213,7 +213,7 @@ function metaUpdate(){
}

$meta = p_render_metadata($ID, $meta);
io_saveFile($file, serialize($meta));
p_save_metadata($ID, $meta);

echo "metaUpdate(): finished".NL;
return true;
Expand Down

0 comments on commit 1172f8d

Please sign in to comment.