Commits

Sidharth Kuruvila committed 3cc6461

First commit for new project format

  • Participants

Comments (0)

Files changed (2)

File updates/UpdateUtils.php

+<?php
+
+//Some code was copied from VTWorkflowUtils in the workflow modules.
+
+/**
+ * Utility class for updating a vtiger 5.1 instance.
+ */
+class UpdateUtils{
+  function __construct($webdir) {
+    $updateName = get_class($this);
+    $this->webdir = $webdir;
+    $this->updateDir = getcwd()."/".$updateName;
+    
+    chdir($webdir);
+    set_include_path(get_include_path() . ":" . $webdir);
+    global $adb;
+    global $dbconfig, $dbconfigoption;
+    global $logsqltm;
+    global $default_language, $current_language;
+    require_once 'include/logging.php';
+    require_once 'include/utils/utils.php';
+    require_once 'include/utils/CommonUtils.php';
+
+    $this->db = $adb;
+    
+    $this->dbname = $dbconfig['db_name'];
+    
+    global $current_user;
+    $this->userStack = array();
+    
+    global $log;
+    $log =& LoggerManager::getLogger('index');
+  }
+
+  function update(){
+    $this->applyPatch();
+    $this->script();
+  }
+  
+  function installModule($moduleName) {
+    $location = $this->updateDir.'/'.$moduleName;
+    $webDir = $this->webdir;
+    
+    chdir($location);
+    system("zip -r $moduleName.zip *");
+    echo "Created Zip \n";
+    $moduleZip="$location/$moduleName.zip";
+    
+    include_once("vtlib/Vtiger/PackageImport.php");
+    echo "Included Dependencies \n";
+    chdir($webDir);
+    $importer = new Vtiger_PackageImport();
+    echo "importing zip $moduleZip \n";
+    $importer->import($moduleZip);
+    echo "Done importing \n";
+  }
+  
+  
+  
+  /**
+   * Push the admin user on to the user stack
+   * and make it the $current_user
+   *
+   */
+  function adminUser() {
+    $user = new Users();
+    $user->retrieveCurrentUserInfoFromFile(1);
+    global $current_user;
+    array_push($this->userStack, $current_user);
+    $current_user = $user;
+    return $user;
+  }
+  
+  /**
+   * Revert to the previous use on the user stack
+   */
+  function revertUser() {
+    global $current_user;
+    if(count($this->userStack)!=0) {
+      $current_user = array_pop($this->userStack);
+    }else {
+      $current_user = null;
+    }
+    return $current_user;
+  }
+  
+  /**
+   * Get the current user
+   */
+  function currentUser() {
+    global $current_user;
+    return $current_user;
+  }
+  
+  function initWebservices() {
+    require_once 'include/Webservices/Utils.php';
+    require_once 'include/Webservices/VtigerCRMObject.php';
+    require_once 'include/Webservices/VtigerCRMObjectMeta.php';
+    require_once 'include/Webservices/DataTransform.php';
+    require_once 'include/Webservices/WebServiceError.php';
+    require_once 'include/Webservices/ModuleTypes.php';
+    require_once 'include/Webservices/Create.php';
+    require_once 'include/Webservices/DescribeObject.php';
+    require_once 'include/Webservices/WebserviceField.php';
+    require_once 'include/Webservices/EntityMeta.php';
+    require_once 'include/Webservices/Query.php';
+    require_once 'include/Webservices/VtigerWebserviceObject.php';
+  }
+ 
+  function initVtlib(){
+    include_once 'vtlib/Vtiger/Module.php';
+  }
+
+
+  /** 
+   * Insert language strings for a module into multiple existing modules
+   *
+   * Example:
+   * array('Accounts' =>
+   *      array('NewField' => 'New Field Label'))
+   *
+   * @param $parent The name of the module
+   * @param $parent An associative array mapping Module names to the fields to be inserted.
+   */
+  function insertLanguageStrings($parent, $languageStrings) {
+    $basePath = $this->webdir;
+    foreach($languageStrings as $moduleName => $strings) {
+      $fn = "modules/$moduleName/language/en_us.lang.php";
+      $s = file_get_contents($fn, FILE_USE_INCLUDE_PATH);
+      $arr = array();
+      foreach($strings as $label => $string) {
+        $arr[]="'".$this->escape($label)."' => '".$this->escape($string)."',";
+      }
+      $str = "
+//Start Inditta $parent strings
+				".implode("\n	", $arr)."
+//End Inditta $parent strings
+				";
+      $out =  preg_replace('/([)];\s*[?]>)/', $str."$1", $s);
+      file_put_contents($fn, $out, FILE_USE_INCLUDE_PATH);
+    }
+  }
+
+
+  /**
+   * Reorder the items in a picklist.
+   * @param picklistName The name of the picklist to reorder
+   * @param picklistItems The items in the new order
+   */
+  function reorderPicklistItems($picklistName, $picklistItems){
+    $db = $this->db;
+    $result = $db->query("select * from vtiger_$picklistName order by picklist_valueid");
+    $it = new SqlResultIterator($db, $result);
+    $ids = array();
+    foreach($it as $row){
+      $ids[] = $row->picklist_valueid;
+    }
+    $arr = array_map(null, $picklistItems, $ids);
+    $query = "update vtiger_$picklistName set $picklistName = ? where picklist_valueid=?";
+    foreach($arr as $item){
+      $db->pquery($query, array($item[0], $item[1]));
+    }   
+  }
+
+  private function escape($string) {
+	return $string;
+  }
+
+  private function applyPatch(){
+    $patchFileName = get_class($this) . ".patch";
+    $patchPath = __DIR__ . "/" . $patchFileName;
+    if(file_exists($patchPath)){
+      $webdir = $this->webdir;
+      system("patch -p1 -i $patchPath -d $webdir");
+    }
+  }	
+	
+}
+
+?>

File updates/updateyyyymmdd.php

+require_once "UpdateUtils.php";
+require_once "updateconfig.php";
+
+/**
+ * Please update the class name to reflect the name of the file
+ * 
+ */
+class updateyyyymmdd extends UpdateUtils{
+  function script(){
+    //Update scripts come here.
+  }
+}
+
+if(!$notScript){
+  $updateClass = basename(__FILE__, '.php');
+  (new $updateClass()).update();
+}
+
+if(!$notScript){
+  $updateClass = basename(__FILE__, '.php');
+  $updater = new $updateClass($webdir);
+  $updater->update();
+}