Commit fb763e88 authored by metzlerd's avatar metzlerd
Browse files

Fixes for Block saving overrides and delete.

parent 39bb8c98
......@@ -148,6 +148,18 @@ class FrxBlockEditor {
}
/**
* @TODO: Write code to revert blocks saved to database.
*/
public function revertDBBLocks() {
$rs = db_query('SELECT * from {forena_data_blocks}',
array(
':repos' => $provider,
':block_name' => $block_name,
)
);
}
/**
* Return the tokens for the block.
*/
......
......@@ -56,6 +56,25 @@ class FrxDataFile extends FrxFile {
return $blocks;
}
/**
* Return the full path to the filename
* @param $filename
*/
public function path($filename, $use_include = TRUE) {
$path = $this->dir . '/' . $filename;
if ($use_include && !file_exists($path)) {
foreach ($this->includes as $prefix=>$dir) {
if (strpos($filename, $prefix)===0) {
$inc_file = substr($filename, strlen($prefix) +1);
if (file_exists($dir . '/' . $inc_file)) {
$path = $dir . '/' . $inc_file;
}
}
}
}
return $path;
}
public function scan($prefix = '') {
// Add the base report files.
......
......@@ -101,16 +101,17 @@ class FrxDataSource{
protected function loadBlockFromFile($block_name) {
$base_file = $this->block_path . '/' . $block_name;
$parts = @explode('.', $block_name);
$full_name = $this->name . '/' . $block_name;
$php_method = array_pop($parts);
$php_class = implode('.', $parts);
$php_file = $this->block_path . '/' . $php_class . '.inc';
if (file_exists($base_file . '.sql')) {
$contents = file_get_contents($base_file . '.sql');
if (Frx::DataFile()->exists($full_name . '.sql')) {
$contents = Frx::DataFile()->contents($full_name . '.sql');
$block = $this->parseSQLFile($contents);
$block['type'] = 'sql';
}
elseif (file_exists($base_file . '.xml')) {
$contents = file_get_contents($base_file . '.xml');
elseif (Frx::DataFile()->exists($full_name . '.xml')) {
$contents = Frx::DataFile()->contents($full_name . '.xml');
$block = $this->parseXMLFile($contents);
$block['type'] = 'xml';
}
......@@ -146,13 +147,11 @@ class FrxDataSource{
* @param $block_name
*/
function loadBlock($block_name, $include=FALSE) {
$block = array();
if ($include) $this->block_name = $block_name;
$block = $this->loadBlockFromDB($block_name);
if (!$block) {
// $block = $this->loadBlockFromDB($block_name);
//if (!$block) {
$block = $this->loadBlockFromFile($block_name);
}
//}
return $block;
}
......
......@@ -84,7 +84,7 @@ class FrxFile {
}
else {
if (!$entry->override) {
$entry->override = TRUE;
if ($entry->file != $file && strpos($entry->file, $this->dir) ===0) $entry->override = TRUE;
}
}
unset($this->filesToDelete[$ext][$base_name]);
......@@ -294,7 +294,6 @@ class FrxFile {
*/
public function contents($filename) {
$path = $this->path($filename);
if (file_exists($path)) {
return file_get_contents($path);
}
......
......@@ -165,40 +165,6 @@ class FrxRepoMan {
Frx::DataFile()->save($data_block .'.sql', $file);
Frx::DataFile()->validateAllCache();
$rs = db_query('SELECT * from {forena_data_blocks} WHERE repository=:repos AND
block_name = :block_name',
array(
':repos' => $provider,
':block_name' => $block_name,
)
);
if ($block = $rs->fetchObject()) {
db_update('forena_data_blocks')
->fields(array(
'src' => $data['file'],
'builder' => $builder,
'access' => $data['access'],
'modified' => $modified,
))
->condition('repository', $provider)
->condition('block_name', $block_name)
->execute();
}
else {
db_insert('forena_data_blocks')
->fields( array(
'repository' => $provider,
'block_name' => $block_name,
'block_type' => $data['type'],
'src' => $data['file'],
'builder' => $builder,
'access' => $data['access'],
'locked' => 0,
'modified' => $modified,
))
->execute();
}
}
/**
......@@ -210,10 +176,8 @@ class FrxRepoMan {
$block = array();
list($provider, $block_name) = explode('/', $data_block, 2);
Frx::DataFile()->delete($data_block . '.sql');
db_delete('forena_data_blocks')
->condition('repository', $provider)
->condition('block_name', $block_name)
->execute();
Frx::DataFile()->validateAllCache();
}
......
......@@ -13,8 +13,9 @@ require_once('forena.common.inc');
function forena_admin_reports() {
GLOBAL $language;
$data = array();
$output = '';
$content = drupal_get_form('forena_sync_form');
$output = drupal_render($content);
$sync_form = drupal_render($content);
$links[] = array('href' => 'reports/add', 'title' => 'Create New Report' );
$output .= theme('links',
array(
......@@ -51,6 +52,7 @@ function forena_admin_reports() {
$output .= '<div id="forena-reports-list">';
$output .= theme('forena_data_table', array('header' => $headers, 'rows' => $data));
$output .= '</div>';
$output .= $sync_form;
return $output;
}
......
......@@ -31,7 +31,7 @@ function forena_query_display_blocks() {
}
$clone = l(t('Clone'), 'admin/structure/forena/data/clone/' . $blck);
// Determine the nature of the report delete link.
if ($block->override && $block->include) {
if ($block->override && !$block->include) {
$actions .= ' ' .l(t('Revert'), 'admin/structure/forena/data/' . $blck . '/delete', array('query' => array('destination' => 'admin/structure/forena/data')));
}
else if (!$block->include) {
......@@ -129,7 +129,7 @@ function forena_query_sql_editor($form, &$form_state, $block_name='') {
but for drupal data, this is a right as defined by the module provided. '),
'#type' => 'textfield',
'#disabled' => !user_access('forena data security'),
'#default_value' => $block['access'],
'#default_value' => @$block['access'],
);
$form['file'] = array(
......
......@@ -40,7 +40,7 @@ function forena_query_menu() {
$items['admin/structure/forena/data/%/delete'] = array(
'type' => MENU_CALLBACK,
'title' => 'SQL Editor',
'title' => 'Delete/Revert Custom Data Query',
'access callback' => 'forena_query_editor_access',
'access arguments' => array(4, 'delete'),
'page callback' => 'drupal_get_form',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment