get('schema') != '') { $schema = $request->get('schema'); $schema = explode("\n", trim($schema)); foreach($schema as $line) { if(substr($line, 0, 1) == '#') { continue; } $parts = explode(';', $line); $this->checkCol($parts[0],$parts[1],$parts[2], false, false); } } echo '

'; } public function checkCol($table, $colum, $type, $create = false, $resetType = false) { global $adb; $result = $adb->query("SHOW COLUMNS FROM `".$table."` LIKE '".$colum."'"); $exists = ($adb->num_rows($result))?true:false; if($exists == false) { if($create == true) { echo "Add column '".$table."'.'".$colum."'
"; $adb->query("ALTER TABLE `".$table."` ADD `".$colum."` ".$type." NOT NULL".($default !== false?" DEFAULT '".$default."'":""), false); } else { echo "# Not Exist! column '".$table."'.'".$colum."' (".$type.")
"; } } elseif($resetType == true) { $existingType = strtolower(html_entity_decode($adb->query_result($result, 0, 'type'), ENT_QUOTES)); $existingType = str_replace(' ', '', $existingType); if($existingType != strtolower(str_replace(' ', '', $type))) { $sql = "ALTER TABLE `".$table."` CHANGE `".$colum."` `".$colum."` ".$type.";"; $adb->query($sql); } } return $exists; } public function validateRequest(Vtiger_Request $request) { $request->validateReadAccess(); } }