[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Migration/views/ -> Index.php (source)

   1  <?php
   2  /*+**********************************************************************************

   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.1

   4   * ("License"); You may not use this file except in compliance with the License

   5   * The Original Code is:  vtiger CRM Open Source

   6   * The Initial Developer of the Original Code is vtiger.

   7   * Portions created by vtiger are Copyright (C) vtiger.

   8   * All Rights Reserved.

   9   ************************************************************************************/
  10  
  11  class Migration_Index_View extends Vtiger_Basic_View {
  12  
  13  	function __construct() {
  14          parent::__construct();
  15          $this->exposeMethod('step1');
  16          $this->exposeMethod('step2');
  17          $this->exposeMethod('applyDBChanges');
  18      }
  19  
  20  	public function checkPermission(Vtiger_Request $request){
  21          return true;
  22      }
  23  
  24  	public function process(Vtiger_Request $request) {
  25                  // Override error reporting to production mode

  26                  version_compare(PHP_VERSION, '5.5.0') <= 0 ? error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED) : error_reporting(E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT); 
  27              
  28          $mode = $request->getMode();
  29          if(!empty($mode)) {
  30              $this->invokeExposedMethod($mode, $request);
  31          }
  32      }
  33  
  34  	protected function step1(Vtiger_Request $request) {
  35          $moduleName = $request->getModule();
  36          $viewer = $this->getViewer($request);
  37  
  38          $viewer->assign('MODULENAME', $moduleName);
  39          $viewer->view('MigrationStep1.tpl', $moduleName);
  40      }
  41  
  42  	protected function step2(Vtiger_Request $request){
  43          $moduleName = $request->getModule();
  44          $viewer = $this->getViewer($request);
  45  
  46          $viewer->assign('MODULE', $moduleName);
  47          $viewer->view('MigrationStep2.tpl', $moduleName);
  48      }
  49  
  50  
  51  	public function preProcess(Vtiger_Request $request, $display = true) {
  52          parent::preProcess($request, false);
  53      }
  54  
  55  	public function getHeaderCss(Vtiger_Request $request) {
  56          $headerCssInstances = array();
  57          $cssFileNames = array(
  58              '~/layouts/vlayout/modules/Migration/css/style.css',
  59              '~/layouts/vlayout/modules/Migration/css/mkCheckbox.css',
  60              '~/libraries/bootstrap/css/bootstrap-responsive.css',
  61              '~/libraries/bootstrap/css/bootstrap.min.css',
  62          );
  63          $cssInstances = $this->checkAndConvertCssStyles($cssFileNames);
  64          $headerCssInstances = array_merge($headerCssInstances, $cssInstances);
  65          return $headerCssInstances;
  66      }
  67  
  68  	public function getHeaderScripts(Vtiger_Request $request) {
  69          $headerScriptInstances = array();
  70          $moduleName = $request->getModule();
  71  
  72          $jsFileNames = array(
  73              "modules.$moduleName.resources.Index"
  74              );
  75  
  76          $jsScriptInstances = $this->checkAndConvertJsScripts($jsFileNames);
  77          $headerScriptInstances = array_merge($headerScriptInstances, $jsScriptInstances);
  78          return $headerScriptInstances;
  79      }
  80  
  81  	public function applyDBChanges(){
  82          $migrationModuleModel = Migration_Module_Model::getInstance();
  83  
  84          $getAllowedMigrationVersions = $migrationModuleModel->getAllowedMigrationVersions();
  85          $getDBVersion = str_replace(array('.', ' '),'', $migrationModuleModel->getDBVersion());
  86          $getLatestSourceVersion = str_replace(array('.', ' '),'', $migrationModuleModel->getLatestSourceVersion());
  87          $migrateVersions = array();
  88          foreach($getAllowedMigrationVersions as $getAllowedMigrationVersion) {
  89              foreach($getAllowedMigrationVersion as $version => $label) {
  90                  if(strcasecmp($version, $getDBVersion) == 0 || $reach == 1) {
  91                      $reach = 1;
  92                      $migrateVersions[] = $version;
  93                  }
  94              }
  95          }
  96          $migrateVersions[] = $getLatestSourceVersion;
  97  
  98          $patchCount  = count($migrateVersions);
  99  
 100          define('VTIGER_UPGRADE', true);
 101  
 102          for($i=0; $i<$patchCount; $i++){
 103              $filename =  "modules/Migration/schema/".$migrateVersions[$i]."_to_".$migrateVersions[$i+1].".php";
 104              if(is_file($filename)) {
 105                  if(!defined('INSTALLATION_MODE')) {
 106                      echo "<table class='config-table'><tr><th><span><b><font color='red'>".$migrateVersions[$i]." ==> ".$migrateVersions[$i+1]." Database changes -- Starts. </font></b></span></th></tr></table>";
 107                      echo "<table class='config-table'>";
 108                  }
 109                  $_i_statesaved = $i;
 110                  include($filename);
 111                  $i = $_i_statesaved;
 112                  if(!defined('INSTALLATION_MODE')) {
 113                      echo "<table class='config-table'><tr><th><span><b><font color='red'>".$migrateVersions[$i]." ==> ".$migrateVersions[$i+1]." Database changes -- Ends.</font></b></span></th></tr></table>";
 114                  }
 115              } else if(isset($migrateVersions[$patchCount+1])){
 116                  echo "<table class='config-table'><tr><th><span><b><font color='red'> There is no Database Changes from ".$migrateVersions[$i]." ==> ".$migrateVersions[$i+1]."</font></b></span></th></tr></table>";
 117              }
 118          }
 119  
 120          //update vtiger version in db

 121          $migrationModuleModel->updateVtigerVersion();
 122          // To carry out all the necessary actions after migration

 123          $migrationModuleModel->postMigrateActivities();
 124      }
 125  
 126  	public static function ExecuteQuery($query, $params){
 127          $adb = PearDatabase::getInstance();
 128          $status = $adb->pquery($query, $params);
 129          if(!defined('INSTALLATION_MODE')) {
 130              $query = $adb->convert2sql($query, $params);
 131              if(is_object($status)) {
 132                  echo '<tr><td width="80%"><span>'.$query.'</span></td><td style="color:green">Success</td></tr>';
 133              } else {
 134                  echo '<tr><td width="80%"><span>'.$query.'</span></td><td style="color:red">Failure</td></tr>';
 135              }
 136          }
 137          return $status;
 138      }
 139  
 140  	public static function insertSelectQuery() {
 141          global $adb;
 142          $genQueryId = $adb->getUniqueID("vtiger_selectquery");
 143          if ($genQueryId != "") {
 144              $iquerysql = "insert into vtiger_selectquery (QUERYID,STARTINDEX,NUMOFOBJECTS) values (?,?,?)";
 145              self::ExecuteQuery($iquerysql, array($genQueryId, 0, 0));
 146          }
 147          return $genQueryId;
 148      }
 149  
 150  	public static function insertSelectColumns($queryid, $columnname) {
 151          if ($queryid != "") {
 152              for ($i = 0; $i < count($columnname); $i++) {
 153                  $icolumnsql = "insert into vtiger_selectcolumn (QUERYID,COLUMNINDEX,COLUMNNAME) values (?,?,?)";
 154                  self::ExecuteQuery($icolumnsql, array($queryid, $i, $columnname[$i]));
 155              }
 156          }
 157      }
 158  
 159  	public static function insertReports($queryid, $folderid, $reportname, $description, $reporttype) {
 160          if ($queryid != "") {
 161              $ireportsql = "insert into vtiger_report (REPORTID,FOLDERID,REPORTNAME,DESCRIPTION,REPORTTYPE,QUERYID,STATE) values (?,?,?,?,?,?,?)";
 162              $ireportparams = array($queryid, $folderid, $reportname, $description, $reporttype, $queryid, 'SAVED');
 163              self::ExecuteQuery($ireportsql, $ireportparams);
 164          }
 165      }
 166  
 167  	public static function insertReportModules($queryid, $primarymodule, $secondarymodule) {
 168          if ($queryid != "") {
 169              $ireportmodulesql = "insert into vtiger_reportmodules (REPORTMODULESID,PRIMARYMODULE,SECONDARYMODULES) values (?,?,?)";
 170              self::ExecuteQuery($ireportmodulesql, array($queryid, $primarymodule, $secondarymodule));
 171          }
 172      }
 173  
 174  	public static function insertAdvFilter($queryid, $filters) {
 175          if ($queryid != "") {
 176              $columnIndexArray = array();
 177              foreach ($filters as $i => $filter) {
 178                  $irelcriteriasql = "insert into vtiger_relcriteria(QUERYID,COLUMNINDEX,COLUMNNAME,COMPARATOR,VALUE) values (?,?,?,?,?)";
 179                  self::ExecuteQuery($irelcriteriasql, array($queryid, $i, $filter['columnname'], $filter['comparator'], $filter['value']));
 180                  $columnIndexArray[] = $i;
 181              }
 182              $conditionExpression = implode(' and ', $columnIndexArray);
 183              self::ExecuteQuery('INSERT INTO vtiger_relcriteria_grouping VALUES(?,?,?,?)', array(1, $queryid, '', $conditionExpression));
 184          }
 185      }
 186      
 187          /**

 188       * Function to transform workflow filter of old look in to new look

 189       * @param <type> $conditions

 190       * @return <type>

 191       */
 192  	public static function transformAdvanceFilterToWorkFlowFilter($conditions) {
 193          $wfCondition = array();
 194  
 195          if(!empty($conditions)) {
 196              $previousConditionGroupId = 0;
 197              foreach($conditions as $condition) {
 198  
 199                  $fieldName = $condition['fieldname'];
 200                  $fieldNameContents = explode(' ', $fieldName);
 201                  if (count($fieldNameContents) > 1) {
 202                      $fieldName = '('. $fieldName .')';
 203                  }
 204  
 205                  $groupId = $condition['groupid'];
 206                  if (!$groupId) {
 207                      $groupId = 0;
 208                  }
 209  
 210                  $groupCondition = 'or';
 211                  if ($groupId === $previousConditionGroupId || count($conditions) === 1) {
 212                      $groupCondition = 'and';
 213                  }
 214  
 215                  $joinCondition = 'or';
 216                  if (isset ($condition['joincondition'])) {
 217                      $joinCondition = $condition['joincondition'];
 218                  } elseif($groupId === 0) {
 219                      $joinCondition = 'and';
 220                  }
 221  
 222                  $value = $condition['value'];
 223                  switch ($value) {
 224                      case 'false:boolean'    : $value = 0;    break;
 225                      case 'true:boolean'        : $value = 1;    break;
 226                      default                    : $value;        break;
 227                  }
 228  
 229                  $wfCondition[] = array(
 230                          'fieldname' => $fieldName,
 231                          'operation' => $condition['operation'],
 232                          'value' => $value,
 233                          'valuetype' => 'rawtext',
 234                          'joincondition' => $joinCondition,
 235                          'groupjoin' => $groupCondition,
 236                          'groupid' => $groupId
 237                  );
 238                  $previousConditionGroupId = $groupId;
 239              }
 240          }
 241          return $wfCondition;
 242      }
 243  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1