function forena_db_sync in Forena Reports 7
Same name and namespace in other branches
- 6.2 forena.admin.inc \forena_db_sync()
- 6 forena.admin.inc \forena_db_sync()
- 7.2 forena.admin.inc \forena_db_sync()
- 7.3 forena.module \forena_db_sync()
Syncronize the data
1 call to forena_db_sync()
- forena_settings_submit in ./
forena.admin.inc - Added submit handler to create directories and clear menu cache
File
- ./
forena.admin.inc, line 201
Code
function forena_db_sync($subdir = '') {
static $prefix = '';
if (!$subdir) {
$prefix = '';
db_delete('forena_reports')
->execute();
}
$path = forena_report_path() . '/' . $subdir;
$d = dir($path);
if ($d) {
while (false !== ($rpt_file = $d
->read())) {
$src_file = trim($d->path, '/') . '/' . trim($rpt_file, '/');
$dest_file = $path . '/' . trim($rpt_file, '/');
if (is_file($src_file)) {
list($report_name, $ext) = explode('.', $rpt_file, 2);
if ($ext == 'frx') {
$report_name = trim($prefix . '/' . $report_name, '/');
try {
$r_xml = file_get_contents($src_file);
} catch (Exception $e) {
$s = t('unable to load Report %s', $r_xml);
forena_error($s, $s . $e
->getMessage());
}
// Load the report
$r = new FrxReport($r_xml);
$save_count = forena_save_report($report_name, $r_xml, FALSE);
}
}
elseif (is_dir($src_file)) {
if (strpos($rpt_file, '.') !== 0) {
$save_prefix = $prefix;
$prefix .= '/' . $rpt_file;
$prefix = trim($prefix, '/');
forena_db_sync($prefix);
$prefix = $save_prefix;
}
}
}
}
if ($d) {
$d
->close();
}
return $save_count;
}