You are here

public function FrxBlockEditor::revertDBBLocks in Forena Reports 7.4

Writes blocks from the old db structure to the new one.

File

./FrxBlockEditor.inc, line 158

Class

FrxBlockEditor

Code

public function revertDBBLocks() {
  $block = array();
  $fo = Frx::DataFile();
  if (db_table_exists('forena_data_blocks') && is_writable($fo->dir)) {

    // Get all blocks from the db.
    $sql = 'SELECT * FROM {forena_data_blocks} order by repository, block_name';
    $rs = db_query($sql);
    $empty_table = TRUE;
    foreach ($rs as $b) {
      $block = array(
        'repository' => $b->repository,
        'block_name' => $b->block_name,
        'type' => $b->block_type,
        'file' => $b->src,
        'builder' => $b->builder,
        'access' => $b->access,
        'title' => $b->title,
        'locked' => $b->locked,
        'modified' => $b->modified,
      );
      $d = Frx::RepoMan()
        ->repository($b->repository);
      $block = array_merge($block, $d
        ->parseSQLFile($block['file']));
      if ($block['builder']) {
        $block['builder'] = unserialize($block['builder']);
      }
      $path = $b->repository . '/' . $b->block_name;
      Frx::RepoMan()
        ->saveBlock($path, $block);
      if (Frx::DataFile()
        ->isCustom($path . '.sql')) {
        db_delete('forena_data_blocks')
          ->condition('repository', $b->repository)
          ->condition('block_name', $b->block_name)
          ->execute();
      }
      $empty_table = FALSE;
    }
    if ($empty_table) {
      db_drop_table('forena_data_blocks');
    }
    $fo
      ->validateAllCache();
  }
}