Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble creating a CBupdate that installs a field
#1
I have created a cbUpdate that installs a field. This all works fine, but I see a problem when trying to test reversing the update. The update is in 'pending' status. Not sure why, but I can't try the 'undoChange' now either. Not a serious problem, since the field installs correctly, but still, I'd like to know what I'm doing wrong here.

Here's the code:

PHP Code:
class installSoFieldInPo extends cbupdaterWorker {
    
    function 
applyChange() {
        if (
$this->hasError()) $this->sendError();
        if (
$this->isApplied()) {
            
$this->sendMsg('Changeset '.get_class($this).' already applied!');
        } else {
            global 
$adb;
            
// CODE
            
include_once 'include/utils/utils.php';
            include_once(
'vtlib/Vtiger/Module.php');
            
$module Vtiger_Module::getInstance('PurchaseOrder');
            
$block Vtiger_Block::getInstance('LBL_PO_INFORMATION'$module);
            
            
// Setup the field
            
$field                =    new Vtiger_Field();
            
$field->name        =    'po_related_soid';
            
$field->label        =    'Related SalesOrder';
            
$field->table        =    'vtiger_purchaseorder';
            
$field->column        =    'po_related_soid';
            
$field->columntype    =    'INT(11)';
            
$field->uitype        =    10;
            
$field->typeofdata    =    'V~O';

            
$block->addField($field);
            
$field->setRelatedModules(array('SalesOrder'));
        }
        
$this->finishExecution();
    }
    
    function 
undoChange() {
        if (
$this->hasError()) $this->sendError();
        if (
$this->isApplied()) {
            global 
$adb;
            
// CODE
            
include_once('vtlib/Vtiger/Module.php');

            
$module Vtiger_Module::getInstance('PurchaseOrder');
            
$field = new Vtiger_Field();
            
$field->getInstance('po_related_soid'$module);
            
$field->delete();

            
$adb->pquery("ALTER TABLE vtiger_purchaseorder DROP COLUMN ?", array('po_related_soid'));

        } else {
            
$this->sendMsg('Changeset '.get_class($this).' not applied, it cannot be undone!');
        }
        
$this->finishExecution();
    }
    
    function 
isApplied() {
        
$done parent::isApplied();
        if (!
$done) {
            global 
$adb;
            
// CODE: set $done
            
$r $adb->query("SHOW COLUMNS FROM `vtiger_purchaseorder` LIKE `po_related_soid`");
            if (
$adb->getAffectedRowCount($r) > 0) {
                
$done true;
            }
        }
        return 
$done;
    }
    

Reply
#2
Hi.

You forget to add $this->markApplied(); after $field->setRelatedModules(array('SalesOrder'));

This function change the status to Executed.
Reply
#3
Aaah, cool. Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)