Commit 0b18d94d authored by metzlerd's avatar metzlerd
Browse files

Reimplemented block save logic. Now saves to filesystem.

parent 7c34acb3
......@@ -12,7 +12,7 @@ class FrxDataFile extends FrxFile {
// Load default directory from configuration.
$report_path = variable_get('forena_query_data_path', '');
if (!$report_path) {
$report_path = variable_get('file_private_path', conf_path() . '/data');
$report_path = variable_get('file_private_path' . '/data', conf_path() . '/data');
}
// Add directories for data repos.
......
......@@ -424,65 +424,6 @@ class FrxDataSource{
return $data;
}
/**
* Save a data block
* @param $block_name String name of block to save
* @param $data array fields of block to save.
*/
public function saveBlock($block_name, $data) {
$modified = time();
$builder = @$data['builder'];
if (is_array($builder)) {
$builder = serialize($builder);
}
$rs = db_query('SELECT * from {forena_data_blocks} WHERE repository=:repos AND
block_name = :block_name',
array(
':repos' => $this->name,
':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', $this->name)
->condition('block_name', $block_name)
->execute();
}
else {
db_insert('forena_data_blocks')
->fields( array(
'repository' => $this->name,
'block_name' => $block_name,
'block_type' => $data['type'],
'src' => $data['file'],
'builder' => $builder,
'access' => $data['access'],
'locked' => 0,
'modified' => $modified,
))
->execute();
}
}
/**
*
* Delete data block stored in database.
* @param $block_name Data block to delete
*/
public function deleteBlock($block_name) {
db_delete('forena_data_blocks')
->condition('repository', $this->name)
->condition('block_name', $block_name)
->execute();
}
/**
* Build the SQL clause based on builder data.
* @param $data
......
......@@ -215,7 +215,7 @@ class FrxFile {
$file_to_delete = $this->dir . '/' . $file;
if (file_exists($file_to_delete)) {
if (is_writeable(dirname($file_to_delete))) {
drupal_set_message(t('Removing customised report %s', array('%s' => $file_to_delete)));
drupal_set_message(t('Removing customization %s', array('%s' => $file_to_delete)));
unlink($file_to_delete);
$i++;
}
......@@ -299,7 +299,7 @@ class FrxFile {
if (!$recursive) {
$path = $this->dir;
if (!is_writable($path)) {
drupal_set_message(t('Report directory %s is not modifiable', array('%s' => $path)), 'error');
drupal_set_message(t('Directory %s is not modifiable', array('%s' => $path)), 'error');
return FALSE;
}
}
......@@ -310,7 +310,7 @@ class FrxFile {
// Path
if (!file_exists($path) && $file) {
@mkdir($path);
if (!@is_writable($path)) {
if (!is_writable($path)) {
drupal_set_message(t('Error creating directory %path', array('%path' => $path)), 'error');
return FALSE;
}
......@@ -330,6 +330,7 @@ class FrxFile {
*/
public function save($filename, $data) {
$path = $this->dir . '/' . $filename;
dpm($data, $path);
$this->verifyDirectory($filename);
if (is_writable($path) || (!file_exists($path) && is_writable(dirname($path)))) {
......
......@@ -156,12 +156,48 @@ class FrxRepoMan {
public function saveBlock($data_block, $data) {
$block = array();
list($provider, $block_name) = explode('/', $data_block, 2);
$repos = @$this->repositories[$provider];
$o = $this->repository($provider);
if ($o) {
$block = $o->saveBlock($block_name, $data);
$modified = time();
$builder = @$data['builder'];
if (is_array($builder)) {
$builder = serialize($builder);
}
Frx::DataFile()->save($data_block .'.sql', $data['source']);
Frx::DataFile()->validateAllCache('sql');
$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();
}
}
/**
......@@ -172,12 +208,11 @@ class FrxRepoMan {
public function deleteBlock($data_block) {
$block = array();
list($provider, $block_name) = explode('/', $data_block, 2);
$repos = @$this->repositories[$provider];
$o = $this->repository($provider);
if ($o) {
$block = $o->deleteBlock($block_name);
}
Frx::DataFile()->delete($data_block . '.sql');
db_delete('forena_data_blocks')
->condition('repository', $provider)
->condition('block_name', $block_name)
->execute();
}
......
......@@ -144,7 +144,7 @@ function forena_sync_form($formid, &$form_state) {
*
*/
function forena_settings() {
$skins = variable_get('forena_skins', array());
$skins = Frx::File()->skins();
$report_path = forena_report_path();
......@@ -163,6 +163,23 @@ function forena_settings() {
'#value' => forena_report_path(),
);
if (module_exists('forena_query')) {
$form['forena_query_data_path'] = array(
'#type' => 'textfield',
'#title' => t('Custom Data Block Repository'),
'#description' => t('Indicate the directory that you want to use to save custom created data blocks using
the forena query builder tool. These will override any module delivered data blocks. This needs to
be a directory that is writable by the web user but should not be browsable by the web. It defaults to
'),
'#default_value' => Frx::DataFile()->dir,
);
$form['forena_last_query_data_path'] = array(
'#type' => 'value',
'#value' => Frx::DataFile()->dir
);
}
$form['forena_input_format'] = forena_filter_element(variable_get('forena_input_format', filter_default_format()), 'forena_input_format');
$form['forena_default_form'] = array(
......@@ -175,24 +192,16 @@ function forena_settings() {
);
$form = system_settings_form($form);
$form['#submit'][] = 'forena_settings_submit';
return $form;
}
/**
* Added submit handler to create directories and clear menu cache
*
* @param unknown_type $form
* @param unknown_type $form_state
*/
function forena_settings_submit($form, &$form_state) {
function forena_settings_validate($form, &$form_state) {
$values = $form_state['values'];
$path = $values['forena_report_repos'];
$src_dir = drupal_get_path('module', 'forena') . '/repos/reports';
if ($path != $values['forena_last_report_path']) {
if (!file_exists($path)) {
try {
if (file_exists($path)) {
drupal_set_message(t('Created directory %s', array($path))) ;
}
......@@ -200,10 +209,45 @@ function forena_settings_submit($form, &$form_state) {
} catch (Exception $e) {
forena_error(t('Unable to create report directory'), $e->getMessage());
return;
}
}
}
if (!file_exists($path) || !is_writable($path)) {
form_set_error('forena_report_repos', 'Report Directory must be writable by the web user');
}
if ($values['forena_query_data_path']) {
$path = $values['forena_query_data_path'];
if ($path != $values['forena_last_query_data_path']) {
if (!file_exists($path)) {
try {
mkdir($path);
if (file_exists($path)) {
drupal_set_message(t('Created directory %s', array($path))) ;
}
} catch (Exception $e) {
forena_error(t('Unable to create data directory'), $e->getMessage());
}
}
}
if (!file_exists($path) || !is_writable($path)) {
dpm($path);
form_set_error('forena_query_data_path', 'Data Directory must be writable by the web user');
}
}
}
/**
* Added submit handler to create directories and clear menu cache
*
* @param unknown_type $form
* @param unknown_type $form_state
*/
function forena_settings_submit($form, &$form_state) {
}
function forena_settings_sync_submit($form, &$form_state) {
......
......@@ -349,13 +349,6 @@ function forena_query_validate_new_block($form, &$form_state) {
// Check to make sure a filename is specified.
if (isset($form_state['values']['save_as_name'])) {
$block_name = $form_state['storage']['provider'] . '/' . $form_state['values']['save_as_name'];
$block = Frx::RepoMan()->loadBlock($block_name);
if ($block) {
form_set_error('save_as_name', t('Block already exists'));
}
}
if (isset($form_state['values']['access'])) {
$r = Frx::RepoMan()->repository($form_state['storage']['provider']);
......@@ -364,6 +357,7 @@ function forena_query_validate_new_block($form, &$form_state) {
form_set_error('access', 'You must have access to use this right.');
}
}
}
function forena_query_save_block($form, &$form_state) {
......
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