/**
  * put your comment there...
  * 
  */
 public function upgrade()
 {
     // Block vars!
     $key = $this->key();
     $id = $this->id();
     $block =& $this[$key];
     // Give a name to the block!
     $block['name'] = "Block #{$id}";
     $block['state'] = 'active';
     // Defautt to active!
     $block['location'] = 'header';
     // Output in header!
     // Fix links as it saved with /n/r as line end and it got splitted using only /n!
     // This is  a Bug in version 0.2! Only the last link is correct but the others carry /r at the end!
     $block['links'] = str_replace("\r\n", "\n", $block['links']);
     // Block referdnce has not effect with ArrayIterator update it internally!
     $this[$key] = $block;
     // Upgrade block (save into db, etc...)
     return parent::upgrade();
 }
 /**
  * put your comment there...
  * 
  */
 public function upgrade()
 {
     /// Get current element.
     $id = $this->id();
     $key = $this->key();
     $block =& $this[$key];
     // Prepare block data!
     $block['name'] = $block['block_name'];
     $block['state'] = 'active';
     // Defautt to active!
     $block['location'] = $block['location'] == 'wp_head' ? 'header' : 'footer';
     // Re-map location name!
     // Cache other fields before clening up deprecated block data!
     $scripts = explode(',', $block['scripts']);
     // Remove deprecated field!
     $this[$key] = array_diff_key($block, array_flip(array('block_name', 'scripts', 'meta')));
     // Upgrade block (save into db, etc...)
     parent::upgrade();
     // Associate block templates!
     if (!empty($scripts)) {
         $blockTemplates = CJTxTable::getInstance('block-template')->set('blockId', $id);
         $template = CJTxTable::getInstance('template')->setTableKey(array('queueName'));
         // For every script/template name find the id of the template and associate it to the block!
         foreach ($scripts as $scriptName) {
             // Get template id from name!
             $templateId = $template->setData(array('queueName' => $scriptName))->load()->get('id');
             if ($templateId) {
                 // Template found!
                 // Add template!
                 $blockTemplates->set('templateId', $templateId)->save(true);
             }
         }
     }
     // Return parent::blocks() returned value!
     return $this;
 }