@@ -97,389 +97,389 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | abstract class DBManager |
| 99 | 99 | { |
| 100 | - /** |
|
| 101 | - * Name of database |
|
| 102 | - * @var resource |
|
| 103 | - */ |
|
| 104 | - public $database = null; |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Indicates whether we should die when we get an error from the DB |
|
| 108 | - */ |
|
| 109 | - protected $dieOnError = false; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Indicates whether we should html encode the results from a query by default |
|
| 113 | - */ |
|
| 114 | - protected $encode = true; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Records the execution time of the last query |
|
| 118 | - */ |
|
| 119 | - protected $query_time = 0; |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Last error message from the DB backend |
|
| 123 | - */ |
|
| 124 | - protected $last_error = false; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Registry of available result sets |
|
| 128 | - */ |
|
| 129 | - protected $lastResult; |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Current query count |
|
| 133 | - */ |
|
| 134 | - private static $queryCount = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Query threshold limit |
|
| 138 | - */ |
|
| 139 | - private static $queryLimit = 0; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Array of prepared statements and their correspoding parsed tokens |
|
| 143 | - */ |
|
| 144 | - protected $preparedTokens = array(); |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * TimeDate instance |
|
| 148 | - * @var TimeDate |
|
| 149 | - */ |
|
| 150 | - protected $timedate; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * PHP Logger |
|
| 154 | - * @var Logger |
|
| 155 | - */ |
|
| 156 | - protected $log; |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Table descriptions |
|
| 160 | - * @var array |
|
| 161 | - */ |
|
| 162 | - protected static $table_descriptions = array(); |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Index descriptions |
|
| 166 | - * @var array |
|
| 167 | - */ |
|
| 168 | - protected static $index_descriptions = array(); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Maximum length of identifiers |
|
| 172 | - * @abstract |
|
| 173 | - * @var array |
|
| 174 | - */ |
|
| 175 | - protected $maxNameLengths = array( |
|
| 176 | - 'table' => 64, |
|
| 177 | - 'column' => 64, |
|
| 178 | - 'index' => 64, |
|
| 179 | - 'alias' => 64 |
|
| 180 | - ); |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * DB driver priority |
|
| 184 | - * Higher priority drivers override lower priority ones |
|
| 185 | - * @var int |
|
| 186 | - */ |
|
| 187 | - public $priority = 0; |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Driver name label, for install |
|
| 191 | - * @absrtact |
|
| 192 | - * @var string |
|
| 193 | - */ |
|
| 194 | - public $label = ''; |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Type names map |
|
| 198 | - * @abstract |
|
| 199 | - * @var array |
|
| 200 | - */ |
|
| 201 | - protected $type_map = array(); |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Type classification into: |
|
| 205 | - * - int |
|
| 206 | - * - bool |
|
| 207 | - * - float |
|
| 208 | - * - date |
|
| 209 | - * @abstract |
|
| 210 | - * @var array |
|
| 211 | - */ |
|
| 212 | - protected $type_class = array( |
|
| 213 | - 'int' => 'int', |
|
| 214 | - 'double' => 'float', |
|
| 215 | - 'float' => 'float', |
|
| 216 | - 'uint' => 'int', |
|
| 217 | - 'ulong' => 'bigint', |
|
| 218 | - 'long' => 'bigint', |
|
| 219 | - 'short' => 'int', |
|
| 220 | - 'date' => 'date', |
|
| 221 | - 'datetime' => 'date', |
|
| 222 | - 'datetimecombo' => 'date', |
|
| 223 | - 'time' => 'time', |
|
| 224 | - 'bool' => 'bool', |
|
| 225 | - 'tinyint' => 'int', |
|
| 226 | - 'currency' => 'float', |
|
| 227 | - 'decimal' => 'float', |
|
| 228 | - 'decimal2' => 'float', |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Capabilities this DB supports. Supported list: |
|
| 233 | - * affected_rows Can report query affected rows for UPDATE/DELETE |
|
| 234 | - * implement getAffectedRowCount() |
|
| 235 | - * select_rows Can report row count for SELECT |
|
| 236 | - * implement getRowCount() |
|
| 237 | - * case_sensitive Supports case-sensitive text columns |
|
| 238 | - * fulltext Supports fulltext search indexes |
|
| 239 | - * inline_keys Supports defining keys together with the table |
|
| 240 | - * auto_increment_sequence Autoincrement support implemented as sequence |
|
| 241 | - * limit_subquery Supports LIMIT clauses in subqueries |
|
| 242 | - * create_user Can create users for Sugar |
|
| 243 | - * create_db Can create databases |
|
| 244 | - * collation Supports setting collations |
|
| 245 | - * disable_keys Supports temporarily disabling keys (for upgrades, etc.) |
|
| 246 | - * |
|
| 247 | - * @abstract |
|
| 248 | - * Special cases: |
|
| 249 | - * fix:expandDatabase - needs expandDatabase fix, see expandDatabase.php |
|
| 250 | - * TODO: verify if we need these cases |
|
| 251 | - */ |
|
| 252 | - protected $capabilities = array(); |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Database options |
|
| 256 | - * @var array |
|
| 257 | - */ |
|
| 258 | - protected $options = array(); |
|
| 100 | + /** |
|
| 101 | + * Name of database |
|
| 102 | + * @var resource |
|
| 103 | + */ |
|
| 104 | + public $database = null; |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Indicates whether we should die when we get an error from the DB |
|
| 108 | + */ |
|
| 109 | + protected $dieOnError = false; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Indicates whether we should html encode the results from a query by default |
|
| 113 | + */ |
|
| 114 | + protected $encode = true; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Records the execution time of the last query |
|
| 118 | + */ |
|
| 119 | + protected $query_time = 0; |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Last error message from the DB backend |
|
| 123 | + */ |
|
| 124 | + protected $last_error = false; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Registry of available result sets |
|
| 128 | + */ |
|
| 129 | + protected $lastResult; |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Current query count |
|
| 133 | + */ |
|
| 134 | + private static $queryCount = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Query threshold limit |
|
| 138 | + */ |
|
| 139 | + private static $queryLimit = 0; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Array of prepared statements and their correspoding parsed tokens |
|
| 143 | + */ |
|
| 144 | + protected $preparedTokens = array(); |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * TimeDate instance |
|
| 148 | + * @var TimeDate |
|
| 149 | + */ |
|
| 150 | + protected $timedate; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * PHP Logger |
|
| 154 | + * @var Logger |
|
| 155 | + */ |
|
| 156 | + protected $log; |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Table descriptions |
|
| 160 | + * @var array |
|
| 161 | + */ |
|
| 162 | + protected static $table_descriptions = array(); |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Index descriptions |
|
| 166 | + * @var array |
|
| 167 | + */ |
|
| 168 | + protected static $index_descriptions = array(); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Maximum length of identifiers |
|
| 172 | + * @abstract |
|
| 173 | + * @var array |
|
| 174 | + */ |
|
| 175 | + protected $maxNameLengths = array( |
|
| 176 | + 'table' => 64, |
|
| 177 | + 'column' => 64, |
|
| 178 | + 'index' => 64, |
|
| 179 | + 'alias' => 64 |
|
| 180 | + ); |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * DB driver priority |
|
| 184 | + * Higher priority drivers override lower priority ones |
|
| 185 | + * @var int |
|
| 186 | + */ |
|
| 187 | + public $priority = 0; |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Driver name label, for install |
|
| 191 | + * @absrtact |
|
| 192 | + * @var string |
|
| 193 | + */ |
|
| 194 | + public $label = ''; |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Type names map |
|
| 198 | + * @abstract |
|
| 199 | + * @var array |
|
| 200 | + */ |
|
| 201 | + protected $type_map = array(); |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Type classification into: |
|
| 205 | + * - int |
|
| 206 | + * - bool |
|
| 207 | + * - float |
|
| 208 | + * - date |
|
| 209 | + * @abstract |
|
| 210 | + * @var array |
|
| 211 | + */ |
|
| 212 | + protected $type_class = array( |
|
| 213 | + 'int' => 'int', |
|
| 214 | + 'double' => 'float', |
|
| 215 | + 'float' => 'float', |
|
| 216 | + 'uint' => 'int', |
|
| 217 | + 'ulong' => 'bigint', |
|
| 218 | + 'long' => 'bigint', |
|
| 219 | + 'short' => 'int', |
|
| 220 | + 'date' => 'date', |
|
| 221 | + 'datetime' => 'date', |
|
| 222 | + 'datetimecombo' => 'date', |
|
| 223 | + 'time' => 'time', |
|
| 224 | + 'bool' => 'bool', |
|
| 225 | + 'tinyint' => 'int', |
|
| 226 | + 'currency' => 'float', |
|
| 227 | + 'decimal' => 'float', |
|
| 228 | + 'decimal2' => 'float', |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Capabilities this DB supports. Supported list: |
|
| 233 | + * affected_rows Can report query affected rows for UPDATE/DELETE |
|
| 234 | + * implement getAffectedRowCount() |
|
| 235 | + * select_rows Can report row count for SELECT |
|
| 236 | + * implement getRowCount() |
|
| 237 | + * case_sensitive Supports case-sensitive text columns |
|
| 238 | + * fulltext Supports fulltext search indexes |
|
| 239 | + * inline_keys Supports defining keys together with the table |
|
| 240 | + * auto_increment_sequence Autoincrement support implemented as sequence |
|
| 241 | + * limit_subquery Supports LIMIT clauses in subqueries |
|
| 242 | + * create_user Can create users for Sugar |
|
| 243 | + * create_db Can create databases |
|
| 244 | + * collation Supports setting collations |
|
| 245 | + * disable_keys Supports temporarily disabling keys (for upgrades, etc.) |
|
| 246 | + * |
|
| 247 | + * @abstract |
|
| 248 | + * Special cases: |
|
| 249 | + * fix:expandDatabase - needs expandDatabase fix, see expandDatabase.php |
|
| 250 | + * TODO: verify if we need these cases |
|
| 251 | + */ |
|
| 252 | + protected $capabilities = array(); |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Database options |
|
| 256 | + * @var array |
|
| 257 | + */ |
|
| 258 | + protected $options = array(); |
|
| 259 | 259 | |
| 260 | 260 | /** |
| 261 | 261 | * Create DB Driver |
| 262 | 262 | */ |
| 263 | - public function __construct() |
|
| 264 | - { |
|
| 265 | - $this->timedate = TimeDate::getInstance(); |
|
| 266 | - $this->log = isset($GLOBALS['log']) ? $GLOBALS['log'] : null; |
|
| 267 | - $this->helper = $this; // compatibility |
|
| 268 | - } |
|
| 263 | + public function __construct() |
|
| 264 | + { |
|
| 265 | + $this->timedate = TimeDate::getInstance(); |
|
| 266 | + $this->log = isset($GLOBALS['log']) ? $GLOBALS['log'] : null; |
|
| 267 | + $this->helper = $this; // compatibility |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | 270 | /** |
| 271 | 271 | * Wrapper for those trying to access the private and protected class members directly |
| 272 | 272 | * @param string $p var name |
| 273 | 273 | * @return mixed |
| 274 | 274 | */ |
| 275 | - public function __get($p) |
|
| 276 | - { |
|
| 277 | - $this->log->info('Call to DBManager::$'.$p.' is deprecated'); |
|
| 278 | - return $this->$p; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * Returns the current database handle |
|
| 283 | - * @return resource |
|
| 284 | - */ |
|
| 285 | - public function getDatabase() |
|
| 286 | - { |
|
| 287 | - $this->checkConnection(); |
|
| 288 | - return $this->database; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Returns this instance's DBHelper |
|
| 293 | - * Actually now returns $this |
|
| 294 | - * @deprecated |
|
| 295 | - * @return DBManager |
|
| 296 | - */ |
|
| 297 | - public function getHelper() |
|
| 298 | - { |
|
| 299 | - return $this; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Checks for error happening in the database |
|
| 304 | - * |
|
| 305 | - * @param string $msg message to prepend to the error message |
|
| 306 | - * @param bool $dieOnError true if we want to die immediately on error |
|
| 307 | - * @return bool True if there was an error |
|
| 308 | - */ |
|
| 309 | - public function checkError($msg = '', $dieOnError = false) |
|
| 310 | - { |
|
| 311 | - if (empty($this->database)) { |
|
| 312 | - $this->registerError($msg, "Database Is Not Connected", $dieOnError); |
|
| 313 | - return true; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $dberror = $this->lastDbError(); |
|
| 317 | - if($dberror === false) { |
|
| 318 | - $this->last_error = false; |
|
| 319 | - return false; |
|
| 320 | - } |
|
| 321 | - $this->registerError($msg, $dberror, $dieOnError); |
|
| 275 | + public function __get($p) |
|
| 276 | + { |
|
| 277 | + $this->log->info('Call to DBManager::$'.$p.' is deprecated'); |
|
| 278 | + return $this->$p; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * Returns the current database handle |
|
| 283 | + * @return resource |
|
| 284 | + */ |
|
| 285 | + public function getDatabase() |
|
| 286 | + { |
|
| 287 | + $this->checkConnection(); |
|
| 288 | + return $this->database; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Returns this instance's DBHelper |
|
| 293 | + * Actually now returns $this |
|
| 294 | + * @deprecated |
|
| 295 | + * @return DBManager |
|
| 296 | + */ |
|
| 297 | + public function getHelper() |
|
| 298 | + { |
|
| 299 | + return $this; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Checks for error happening in the database |
|
| 304 | + * |
|
| 305 | + * @param string $msg message to prepend to the error message |
|
| 306 | + * @param bool $dieOnError true if we want to die immediately on error |
|
| 307 | + * @return bool True if there was an error |
|
| 308 | + */ |
|
| 309 | + public function checkError($msg = '', $dieOnError = false) |
|
| 310 | + { |
|
| 311 | + if (empty($this->database)) { |
|
| 312 | + $this->registerError($msg, "Database Is Not Connected", $dieOnError); |
|
| 313 | + return true; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $dberror = $this->lastDbError(); |
|
| 317 | + if($dberror === false) { |
|
| 318 | + $this->last_error = false; |
|
| 319 | + return false; |
|
| 320 | + } |
|
| 321 | + $this->registerError($msg, $dberror, $dieOnError); |
|
| 322 | 322 | return true; |
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Register database error |
|
| 327 | - * If die-on-error flag is set, logs the message and dies, |
|
| 328 | - * otherwise sets last_error to the message |
|
| 329 | - * @param string $userMessage Message from function user |
|
| 330 | - * @param string $message Message from SQL driver |
|
| 331 | - * @param bool $dieOnError |
|
| 332 | - */ |
|
| 333 | - protected function registerError($userMessage, $message, $dieOnError = false) |
|
| 334 | - { |
|
| 335 | - if(!empty($message)) { |
|
| 336 | - if(!empty($userMessage)) { |
|
| 337 | - $message = "$userMessage: $message"; |
|
| 338 | - } |
|
| 339 | - if(empty($message)) { |
|
| 340 | - $message = "Database error"; |
|
| 341 | - } |
|
| 342 | - $this->log->fatal($message); |
|
| 343 | - if ($dieOnError || $this->dieOnError) { |
|
| 344 | - if(isset($GLOBALS['app_strings']['ERR_DB_FAIL'])) { |
|
| 345 | - sugar_die($GLOBALS['app_strings']['ERR_DB_FAIL']); |
|
| 346 | - } else { |
|
| 347 | - sugar_die("Database error. Please check suitecrm.log for details."); |
|
| 348 | - } |
|
| 349 | - } else { |
|
| 350 | - $this->last_error = $message; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Return DB error message for the last query executed |
|
| 357 | - * @return string Last error message |
|
| 358 | - */ |
|
| 359 | - public function lastError() |
|
| 360 | - { |
|
| 361 | - return $this->last_error; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * This method is called by every method that runs a query. |
|
| 366 | - * If slow query dumping is turned on and the query time is beyond |
|
| 367 | - * the time limit, we will log the query. This function may do |
|
| 368 | - * additional reporting or log in a different area in the future. |
|
| 369 | - * |
|
| 370 | - * @param string $query query to log |
|
| 371 | - * @return boolean true if the query was logged, false otherwise |
|
| 372 | - */ |
|
| 373 | - protected function dump_slow_queries($query) |
|
| 374 | - { |
|
| 375 | - global $sugar_config; |
|
| 376 | - |
|
| 377 | - $do_the_dump = isset($sugar_config['dump_slow_queries']) |
|
| 378 | - ? $sugar_config['dump_slow_queries'] : false; |
|
| 379 | - $slow_query_time_msec = isset($sugar_config['slow_query_time_msec']) |
|
| 380 | - ? $sugar_config['slow_query_time_msec'] : 5000; |
|
| 381 | - |
|
| 382 | - if($do_the_dump) { |
|
| 383 | - if($slow_query_time_msec < ($this->query_time * 1000)) { |
|
| 384 | - // Then log both the query and the query time |
|
| 385 | - $this->log->fatal('Slow Query (time:'.$this->query_time."\n".$query); |
|
| 386 | - return true; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - return false; |
|
| 390 | - } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Register database error |
|
| 327 | + * If die-on-error flag is set, logs the message and dies, |
|
| 328 | + * otherwise sets last_error to the message |
|
| 329 | + * @param string $userMessage Message from function user |
|
| 330 | + * @param string $message Message from SQL driver |
|
| 331 | + * @param bool $dieOnError |
|
| 332 | + */ |
|
| 333 | + protected function registerError($userMessage, $message, $dieOnError = false) |
|
| 334 | + { |
|
| 335 | + if(!empty($message)) { |
|
| 336 | + if(!empty($userMessage)) { |
|
| 337 | + $message = "$userMessage: $message"; |
|
| 338 | + } |
|
| 339 | + if(empty($message)) { |
|
| 340 | + $message = "Database error"; |
|
| 341 | + } |
|
| 342 | + $this->log->fatal($message); |
|
| 343 | + if ($dieOnError || $this->dieOnError) { |
|
| 344 | + if(isset($GLOBALS['app_strings']['ERR_DB_FAIL'])) { |
|
| 345 | + sugar_die($GLOBALS['app_strings']['ERR_DB_FAIL']); |
|
| 346 | + } else { |
|
| 347 | + sugar_die("Database error. Please check suitecrm.log for details."); |
|
| 348 | + } |
|
| 349 | + } else { |
|
| 350 | + $this->last_error = $message; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Return DB error message for the last query executed |
|
| 357 | + * @return string Last error message |
|
| 358 | + */ |
|
| 359 | + public function lastError() |
|
| 360 | + { |
|
| 361 | + return $this->last_error; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * This method is called by every method that runs a query. |
|
| 366 | + * If slow query dumping is turned on and the query time is beyond |
|
| 367 | + * the time limit, we will log the query. This function may do |
|
| 368 | + * additional reporting or log in a different area in the future. |
|
| 369 | + * |
|
| 370 | + * @param string $query query to log |
|
| 371 | + * @return boolean true if the query was logged, false otherwise |
|
| 372 | + */ |
|
| 373 | + protected function dump_slow_queries($query) |
|
| 374 | + { |
|
| 375 | + global $sugar_config; |
|
| 376 | + |
|
| 377 | + $do_the_dump = isset($sugar_config['dump_slow_queries']) |
|
| 378 | + ? $sugar_config['dump_slow_queries'] : false; |
|
| 379 | + $slow_query_time_msec = isset($sugar_config['slow_query_time_msec']) |
|
| 380 | + ? $sugar_config['slow_query_time_msec'] : 5000; |
|
| 381 | + |
|
| 382 | + if($do_the_dump) { |
|
| 383 | + if($slow_query_time_msec < ($this->query_time * 1000)) { |
|
| 384 | + // Then log both the query and the query time |
|
| 385 | + $this->log->fatal('Slow Query (time:'.$this->query_time."\n".$query); |
|
| 386 | + return true; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + return false; |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | 392 | /** |
| 393 | - * Scans order by to ensure that any field being ordered by is. |
|
| 394 | - * |
|
| 395 | - * It will throw a warning error to the log file - fatal if slow query logging is enabled |
|
| 396 | - * |
|
| 397 | - * @param string $sql query to be run |
|
| 398 | - * @param bool $object_name optional, object to look up indices in |
|
| 399 | - * @return bool true if an index is found false otherwise |
|
| 400 | - */ |
|
| 393 | + * Scans order by to ensure that any field being ordered by is. |
|
| 394 | + * |
|
| 395 | + * It will throw a warning error to the log file - fatal if slow query logging is enabled |
|
| 396 | + * |
|
| 397 | + * @param string $sql query to be run |
|
| 398 | + * @param bool $object_name optional, object to look up indices in |
|
| 399 | + * @return bool true if an index is found false otherwise |
|
| 400 | + */ |
|
| 401 | 401 | protected function checkQuery($sql, $object_name = false) |
| 402 | 402 | { |
| 403 | - $match = array(); |
|
| 404 | - preg_match_all("'.* FROM ([^ ]*).* ORDER BY (.*)'is", $sql, $match); |
|
| 405 | - $indices = false; |
|
| 406 | - if (!empty($match[1][0])) |
|
| 407 | - $table = $match[1][0]; |
|
| 408 | - else |
|
| 409 | - return false; |
|
| 410 | - |
|
| 411 | - if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) |
|
| 412 | - $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
|
| 413 | - |
|
| 414 | - if (empty($indices)) { |
|
| 415 | - foreach ( $GLOBALS['dictionary'] as $current ) { |
|
| 416 | - if ($current['table'] == $table){ |
|
| 417 | - $indices = $current['indices']; |
|
| 418 | - break; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - if (empty($indices)) { |
|
| 423 | - $this->log->warn('CHECK QUERY: Could not find index definitions for table ' . $table); |
|
| 424 | - return false; |
|
| 425 | - } |
|
| 426 | - if (!empty($match[2][0])) { |
|
| 427 | - $orderBys = explode(' ', $match[2][0]); |
|
| 428 | - foreach ($orderBys as $orderBy){ |
|
| 429 | - $orderBy = trim($orderBy); |
|
| 430 | - if (empty($orderBy)) |
|
| 431 | - continue; |
|
| 432 | - $orderBy = strtolower($orderBy); |
|
| 433 | - if ($orderBy == 'asc' || $orderBy == 'desc') |
|
| 434 | - continue; |
|
| 435 | - |
|
| 436 | - $orderBy = str_replace(array($table . '.', ','), '', $orderBy); |
|
| 437 | - |
|
| 438 | - foreach ($indices as $index) |
|
| 439 | - if (empty($index['db']) || $index['db'] == $this->dbType) |
|
| 440 | - foreach ($index['fields'] as $field) |
|
| 441 | - if ($field == $orderBy) |
|
| 442 | - return true; |
|
| 443 | - |
|
| 444 | - $warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy ; |
|
| 445 | - if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) |
|
| 446 | - $this->log->fatal('CHECK QUERY:' .$warning); |
|
| 447 | - else |
|
| 448 | - $this->log->warn('CHECK QUERY:' .$warning); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - return false; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Returns the time the last query took to execute |
|
| 456 | - * |
|
| 457 | - * @return int |
|
| 458 | - */ |
|
| 459 | - public function getQueryTime() |
|
| 460 | - { |
|
| 461 | - return $this->query_time; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Checks the current connection; if it is not connected then reconnect |
|
| 466 | - */ |
|
| 467 | - public function checkConnection() |
|
| 468 | - { |
|
| 469 | - $this->last_error = ''; |
|
| 470 | - if (!isset($this->database)) |
|
| 471 | - $this->connect(); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Sets the dieOnError value |
|
| 476 | - * |
|
| 477 | - * @param bool $value |
|
| 478 | - */ |
|
| 479 | - public function setDieOnError($value) |
|
| 480 | - { |
|
| 481 | - $this->dieOnError = $value; |
|
| 482 | - } |
|
| 403 | + $match = array(); |
|
| 404 | + preg_match_all("'.* FROM ([^ ]*).* ORDER BY (.*)'is", $sql, $match); |
|
| 405 | + $indices = false; |
|
| 406 | + if (!empty($match[1][0])) |
|
| 407 | + $table = $match[1][0]; |
|
| 408 | + else |
|
| 409 | + return false; |
|
| 410 | + |
|
| 411 | + if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) |
|
| 412 | + $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
|
| 413 | + |
|
| 414 | + if (empty($indices)) { |
|
| 415 | + foreach ( $GLOBALS['dictionary'] as $current ) { |
|
| 416 | + if ($current['table'] == $table){ |
|
| 417 | + $indices = $current['indices']; |
|
| 418 | + break; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + if (empty($indices)) { |
|
| 423 | + $this->log->warn('CHECK QUERY: Could not find index definitions for table ' . $table); |
|
| 424 | + return false; |
|
| 425 | + } |
|
| 426 | + if (!empty($match[2][0])) { |
|
| 427 | + $orderBys = explode(' ', $match[2][0]); |
|
| 428 | + foreach ($orderBys as $orderBy){ |
|
| 429 | + $orderBy = trim($orderBy); |
|
| 430 | + if (empty($orderBy)) |
|
| 431 | + continue; |
|
| 432 | + $orderBy = strtolower($orderBy); |
|
| 433 | + if ($orderBy == 'asc' || $orderBy == 'desc') |
|
| 434 | + continue; |
|
| 435 | + |
|
| 436 | + $orderBy = str_replace(array($table . '.', ','), '', $orderBy); |
|
| 437 | + |
|
| 438 | + foreach ($indices as $index) |
|
| 439 | + if (empty($index['db']) || $index['db'] == $this->dbType) |
|
| 440 | + foreach ($index['fields'] as $field) |
|
| 441 | + if ($field == $orderBy) |
|
| 442 | + return true; |
|
| 443 | + |
|
| 444 | + $warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy ; |
|
| 445 | + if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) |
|
| 446 | + $this->log->fatal('CHECK QUERY:' .$warning); |
|
| 447 | + else |
|
| 448 | + $this->log->warn('CHECK QUERY:' .$warning); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + return false; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Returns the time the last query took to execute |
|
| 456 | + * |
|
| 457 | + * @return int |
|
| 458 | + */ |
|
| 459 | + public function getQueryTime() |
|
| 460 | + { |
|
| 461 | + return $this->query_time; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Checks the current connection; if it is not connected then reconnect |
|
| 466 | + */ |
|
| 467 | + public function checkConnection() |
|
| 468 | + { |
|
| 469 | + $this->last_error = ''; |
|
| 470 | + if (!isset($this->database)) |
|
| 471 | + $this->connect(); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Sets the dieOnError value |
|
| 476 | + * |
|
| 477 | + * @param bool $value |
|
| 478 | + */ |
|
| 479 | + public function setDieOnError($value) |
|
| 480 | + { |
|
| 481 | + $this->dieOnError = $value; |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | 484 | /** |
| 485 | 485 | * Implements a generic insert for any bean. |
@@ -488,67 +488,67 @@ discard block |
||
| 488 | 488 | * @return bool query result |
| 489 | 489 | * |
| 490 | 490 | */ |
| 491 | - public function insert(SugarBean $bean) |
|
| 492 | - { |
|
| 493 | - $sql = $this->insertSQL($bean); |
|
| 494 | - $tablename = $bean->getTableName(); |
|
| 495 | - $msg = "Error inserting into table: $tablename:"; |
|
| 496 | - return $this->query($sql,true,$msg); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Insert data into table by parameter definition |
|
| 501 | - * @param string $table Table name |
|
| 502 | - * @param array $field_defs Definitions in vardef-like format |
|
| 503 | - * @param array $data Key/value to insert |
|
| 504 | - * @param array $field_map Fields map from SugarBean |
|
| 505 | - * @param bool $execute Execute or return query? |
|
| 491 | + public function insert(SugarBean $bean) |
|
| 492 | + { |
|
| 493 | + $sql = $this->insertSQL($bean); |
|
| 494 | + $tablename = $bean->getTableName(); |
|
| 495 | + $msg = "Error inserting into table: $tablename:"; |
|
| 496 | + return $this->query($sql,true,$msg); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Insert data into table by parameter definition |
|
| 501 | + * @param string $table Table name |
|
| 502 | + * @param array $field_defs Definitions in vardef-like format |
|
| 503 | + * @param array $data Key/value to insert |
|
| 504 | + * @param array $field_map Fields map from SugarBean |
|
| 505 | + * @param bool $execute Execute or return query? |
|
| 506 | 506 | * @return bool query result |
| 507 | 507 | */ |
| 508 | - public function insertParams($table, $field_defs, $data, $field_map = null, $execute = true) |
|
| 509 | - { |
|
| 510 | - $values = array(); |
|
| 511 | - foreach ($field_defs as $field => $fieldDef) |
|
| 512 | - { |
|
| 513 | - if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
| 514 | - //custom fields handle there save seperatley |
|
| 515 | - if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue; |
|
| 516 | - |
|
| 517 | - if(isset($data[$field])) { |
|
| 518 | - // clean the incoming value.. |
|
| 519 | - $val = from_html($data[$field]); |
|
| 520 | - } else { |
|
| 521 | - if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 522 | - $val = $fieldDef['default']; |
|
| 523 | - } else { |
|
| 524 | - $val = null; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - //handle auto increment values here - we may have to do something like nextval for oracle |
|
| 529 | - if (!empty($fieldDef['auto_increment'])) { |
|
| 530 | - $auto = $this->getAutoIncrementSQL($table, $fieldDef['name']); |
|
| 531 | - if(!empty($auto)) { |
|
| 532 | - $values[$field] = $auto; |
|
| 533 | - } |
|
| 534 | - } elseif ($fieldDef['name'] == 'deleted') { |
|
| 535 | - $values['deleted'] = (int)$val; |
|
| 536 | - } else { |
|
| 537 | - // need to do some thing about types of values |
|
| 538 | - if(!is_null($val) || !empty($fieldDef['required'])) { |
|
| 539 | - $values[$field] = $this->massageValue($val, $fieldDef); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if (empty($values)) |
|
| 545 | - return $execute?true:''; // no columns set |
|
| 546 | - |
|
| 547 | - // get the entire sql |
|
| 548 | - $query = "INSERT INTO $table (".implode(",", array_keys($values)).") |
|
| 508 | + public function insertParams($table, $field_defs, $data, $field_map = null, $execute = true) |
|
| 509 | + { |
|
| 510 | + $values = array(); |
|
| 511 | + foreach ($field_defs as $field => $fieldDef) |
|
| 512 | + { |
|
| 513 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
| 514 | + //custom fields handle there save seperatley |
|
| 515 | + if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue; |
|
| 516 | + |
|
| 517 | + if(isset($data[$field])) { |
|
| 518 | + // clean the incoming value.. |
|
| 519 | + $val = from_html($data[$field]); |
|
| 520 | + } else { |
|
| 521 | + if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 522 | + $val = $fieldDef['default']; |
|
| 523 | + } else { |
|
| 524 | + $val = null; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + //handle auto increment values here - we may have to do something like nextval for oracle |
|
| 529 | + if (!empty($fieldDef['auto_increment'])) { |
|
| 530 | + $auto = $this->getAutoIncrementSQL($table, $fieldDef['name']); |
|
| 531 | + if(!empty($auto)) { |
|
| 532 | + $values[$field] = $auto; |
|
| 533 | + } |
|
| 534 | + } elseif ($fieldDef['name'] == 'deleted') { |
|
| 535 | + $values['deleted'] = (int)$val; |
|
| 536 | + } else { |
|
| 537 | + // need to do some thing about types of values |
|
| 538 | + if(!is_null($val) || !empty($fieldDef['required'])) { |
|
| 539 | + $values[$field] = $this->massageValue($val, $fieldDef); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + if (empty($values)) |
|
| 545 | + return $execute?true:''; // no columns set |
|
| 546 | + |
|
| 547 | + // get the entire sql |
|
| 548 | + $query = "INSERT INTO $table (".implode(",", array_keys($values)).") |
|
| 549 | 549 | VALUES (".implode(",", $values).")"; |
| 550 | - return $execute?$this->query($query):$query; |
|
| 551 | - } |
|
| 550 | + return $execute?$this->query($query):$query; |
|
| 551 | + } |
|
| 552 | 552 | |
| 553 | 553 | /** |
| 554 | 554 | * Implements a generic update for any bean |
@@ -560,13 +560,13 @@ discard block |
||
| 560 | 560 | * @return bool query result |
| 561 | 561 | * |
| 562 | 562 | */ |
| 563 | - public function update(SugarBean $bean, array $where = array()) |
|
| 564 | - { |
|
| 565 | - $sql = $this->updateSQL($bean, $where); |
|
| 566 | - $tablename = $bean->getTableName(); |
|
| 567 | - $msg = "Error updating table: $tablename:"; |
|
| 568 | - return $this->query($sql,true,$msg); |
|
| 569 | - } |
|
| 563 | + public function update(SugarBean $bean, array $where = array()) |
|
| 564 | + { |
|
| 565 | + $sql = $this->updateSQL($bean, $where); |
|
| 566 | + $tablename = $bean->getTableName(); |
|
| 567 | + $msg = "Error updating table: $tablename:"; |
|
| 568 | + return $this->query($sql,true,$msg); |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | 571 | /** |
| 572 | 572 | * Implements a generic delete for any bean identified by id |
@@ -577,215 +577,215 @@ discard block |
||
| 577 | 577 | * If where is not passed, it defaults to id of table |
| 578 | 578 | * @return bool query result |
| 579 | 579 | */ |
| 580 | - public function delete(SugarBean $bean, array $where = array()) |
|
| 581 | - { |
|
| 582 | - $sql = $this->deleteSQL($bean, $where); |
|
| 583 | - $tableName = $bean->getTableName(); |
|
| 584 | - $msg = "Error deleting from table: ".$tableName. ":"; |
|
| 585 | - return $this->query($sql,true,$msg); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Implements a generic retrieve for any bean identified by id |
|
| 590 | - * |
|
| 591 | - * If we want to pass multiple values for a name, pass it as an array |
|
| 592 | - * If where is not passed, it defaults to id of table |
|
| 593 | - * |
|
| 594 | - * @param SugarBean $bean Sugarbean instance |
|
| 595 | - * @param array $where values with the keys as names of fields. |
|
| 596 | - * @return resource result from the query |
|
| 597 | - */ |
|
| 598 | - public function retrieve(SugarBean $bean, array $where = array()) |
|
| 599 | - { |
|
| 600 | - $sql = $this->retrieveSQL($bean, $where); |
|
| 601 | - $tableName = $bean->getTableName(); |
|
| 602 | - $msg = "Error retriving values from table:".$tableName. ":"; |
|
| 603 | - return $this->query($sql,true,$msg); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Implements a generic retrieve for a collection of beans. |
|
| 608 | - * |
|
| 609 | - * These beans will be joined in the sql by the key attribute of field defs. |
|
| 610 | - * Currently, this function does support outer joins. |
|
| 611 | - * |
|
| 612 | - * @param array $beans Sugarbean instance(s) |
|
| 613 | - * @param array $cols columns to be returned with the keys as names of bean as identified by |
|
| 614 | - * get_class of bean. Values of this array is the array of fieldDefs to be returned for a bean. |
|
| 615 | - * If an empty array is passed, all columns are selected. |
|
| 616 | - * @param array $where values with the keys as names of bean as identified by get_class of bean |
|
| 617 | - * Each value at the first level is an array of values for that bean identified by name of fields. |
|
| 618 | - * If we want to pass multiple values for a name, pass it as an array |
|
| 619 | - * If where is not passed, all the rows will be returned. |
|
| 620 | - * @return resource |
|
| 621 | - */ |
|
| 622 | - public function retrieveView(array $beans, array $cols = array(), array $where = array()) |
|
| 623 | - { |
|
| 624 | - $sql = $this->retrieveViewSQL($beans, $cols, $where); |
|
| 625 | - $msg = "Error retriving values from View Collection:"; |
|
| 626 | - return $this->query($sql,true,$msg); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Implements creation of a db table for a bean. |
|
| 632 | - * |
|
| 633 | - * NOTE: does not handle out-of-table constraints, use createConstraintSQL for that |
|
| 634 | - * @param SugarBean $bean Sugarbean instance |
|
| 635 | - */ |
|
| 636 | - public function createTable(SugarBean $bean) |
|
| 637 | - { |
|
| 638 | - $sql = $this->createTableSQL($bean); |
|
| 639 | - $tablename = $bean->getTableName(); |
|
| 640 | - $msg = "Error creating table: $tablename:"; |
|
| 641 | - $this->query($sql,true,$msg); |
|
| 642 | - if(!$this->supports("inline_keys")) { |
|
| 643 | - // handle constraints and indices |
|
| 644 | - $indicesArr = $this->createConstraintSql($bean); |
|
| 645 | - if (count($indicesArr) > 0) |
|
| 646 | - foreach ($indicesArr as $indexSql) |
|
| 647 | - $this->query($indexSql, true, $msg); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * returns SQL to create constraints or indices |
|
| 653 | - * |
|
| 654 | - * @param SugarBean $bean SugarBean instance |
|
| 655 | - * @return array list of SQL statements |
|
| 656 | - */ |
|
| 657 | - protected function createConstraintSql(SugarBean $bean) |
|
| 658 | - { |
|
| 659 | - return $this->getConstraintSql($bean->getIndices(), $bean->getTableName()); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - /** |
|
| 663 | - * Implements creation of a db table |
|
| 664 | - * |
|
| 665 | - * @param string $tablename |
|
| 666 | - * @param array $fieldDefs Field definitions, in vardef format |
|
| 667 | - * @param array $indices Index definitions, in vardef format |
|
| 668 | - * @param string $engine Engine parameter, used for MySQL engine so far |
|
| 580 | + public function delete(SugarBean $bean, array $where = array()) |
|
| 581 | + { |
|
| 582 | + $sql = $this->deleteSQL($bean, $where); |
|
| 583 | + $tableName = $bean->getTableName(); |
|
| 584 | + $msg = "Error deleting from table: ".$tableName. ":"; |
|
| 585 | + return $this->query($sql,true,$msg); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Implements a generic retrieve for any bean identified by id |
|
| 590 | + * |
|
| 591 | + * If we want to pass multiple values for a name, pass it as an array |
|
| 592 | + * If where is not passed, it defaults to id of table |
|
| 593 | + * |
|
| 594 | + * @param SugarBean $bean Sugarbean instance |
|
| 595 | + * @param array $where values with the keys as names of fields. |
|
| 596 | + * @return resource result from the query |
|
| 597 | + */ |
|
| 598 | + public function retrieve(SugarBean $bean, array $where = array()) |
|
| 599 | + { |
|
| 600 | + $sql = $this->retrieveSQL($bean, $where); |
|
| 601 | + $tableName = $bean->getTableName(); |
|
| 602 | + $msg = "Error retriving values from table:".$tableName. ":"; |
|
| 603 | + return $this->query($sql,true,$msg); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Implements a generic retrieve for a collection of beans. |
|
| 608 | + * |
|
| 609 | + * These beans will be joined in the sql by the key attribute of field defs. |
|
| 610 | + * Currently, this function does support outer joins. |
|
| 611 | + * |
|
| 612 | + * @param array $beans Sugarbean instance(s) |
|
| 613 | + * @param array $cols columns to be returned with the keys as names of bean as identified by |
|
| 614 | + * get_class of bean. Values of this array is the array of fieldDefs to be returned for a bean. |
|
| 615 | + * If an empty array is passed, all columns are selected. |
|
| 616 | + * @param array $where values with the keys as names of bean as identified by get_class of bean |
|
| 617 | + * Each value at the first level is an array of values for that bean identified by name of fields. |
|
| 618 | + * If we want to pass multiple values for a name, pass it as an array |
|
| 619 | + * If where is not passed, all the rows will be returned. |
|
| 620 | + * @return resource |
|
| 621 | + */ |
|
| 622 | + public function retrieveView(array $beans, array $cols = array(), array $where = array()) |
|
| 623 | + { |
|
| 624 | + $sql = $this->retrieveViewSQL($beans, $cols, $where); |
|
| 625 | + $msg = "Error retriving values from View Collection:"; |
|
| 626 | + return $this->query($sql,true,$msg); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Implements creation of a db table for a bean. |
|
| 632 | + * |
|
| 633 | + * NOTE: does not handle out-of-table constraints, use createConstraintSQL for that |
|
| 634 | + * @param SugarBean $bean Sugarbean instance |
|
| 635 | + */ |
|
| 636 | + public function createTable(SugarBean $bean) |
|
| 637 | + { |
|
| 638 | + $sql = $this->createTableSQL($bean); |
|
| 639 | + $tablename = $bean->getTableName(); |
|
| 640 | + $msg = "Error creating table: $tablename:"; |
|
| 641 | + $this->query($sql,true,$msg); |
|
| 642 | + if(!$this->supports("inline_keys")) { |
|
| 643 | + // handle constraints and indices |
|
| 644 | + $indicesArr = $this->createConstraintSql($bean); |
|
| 645 | + if (count($indicesArr) > 0) |
|
| 646 | + foreach ($indicesArr as $indexSql) |
|
| 647 | + $this->query($indexSql, true, $msg); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * returns SQL to create constraints or indices |
|
| 653 | + * |
|
| 654 | + * @param SugarBean $bean SugarBean instance |
|
| 655 | + * @return array list of SQL statements |
|
| 656 | + */ |
|
| 657 | + protected function createConstraintSql(SugarBean $bean) |
|
| 658 | + { |
|
| 659 | + return $this->getConstraintSql($bean->getIndices(), $bean->getTableName()); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + /** |
|
| 663 | + * Implements creation of a db table |
|
| 664 | + * |
|
| 665 | + * @param string $tablename |
|
| 666 | + * @param array $fieldDefs Field definitions, in vardef format |
|
| 667 | + * @param array $indices Index definitions, in vardef format |
|
| 668 | + * @param string $engine Engine parameter, used for MySQL engine so far |
|
| 669 | 669 | * @todo: refactor engine param to be more generic |
| 670 | 670 | * @return bool success value |
| 671 | 671 | */ |
| 672 | - public function createTableParams($tablename, $fieldDefs, $indices, $engine = null) |
|
| 673 | - { |
|
| 674 | - if (!empty($fieldDefs)) { |
|
| 675 | - $sql = $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
| 676 | - $res = true; |
|
| 677 | - if ($sql) { |
|
| 678 | - $msg = "Error creating table: $tablename"; |
|
| 679 | - $res = ($res and $this->query($sql,true,$msg)); |
|
| 680 | - } |
|
| 681 | - if(!$this->supports("inline_keys")) { |
|
| 682 | - // handle constraints and indices |
|
| 683 | - $indicesArr = $this->getConstraintSql($indices, $tablename); |
|
| 684 | - if (count($indicesArr) > 0) |
|
| 685 | - foreach ($indicesArr as $indexSql) |
|
| 686 | - $res = ($res and $this->query($indexSql, true, "Error creating indexes")); |
|
| 687 | - } |
|
| 688 | - return $res; |
|
| 689 | - } |
|
| 690 | - return false; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Implements repair of a db table for a bean. |
|
| 695 | - * |
|
| 696 | - * @param SugarBean $bean SugarBean instance |
|
| 697 | - * @param bool $execute true if we want the action to take place, false if we just want the sql returned |
|
| 698 | - * @return string SQL statement or empty string, depending upon $execute |
|
| 699 | - */ |
|
| 700 | - public function repairTable(SugarBean $bean, $execute = true) |
|
| 701 | - { |
|
| 702 | - $indices = $bean->getIndices(); |
|
| 703 | - $fielddefs = $bean->getFieldDefinitions(); |
|
| 704 | - $tablename = $bean->getTableName(); |
|
| 705 | - |
|
| 706 | - //Clean the indexes to prevent duplicate definitions |
|
| 707 | - $new_index = array(); |
|
| 708 | - foreach($indices as $ind_def){ |
|
| 709 | - $new_index[$ind_def['name']] = $ind_def; |
|
| 710 | - } |
|
| 711 | - //jc: added this for beans that do not actually have a table, namely |
|
| 712 | - //ForecastOpportunities |
|
| 713 | - if($tablename == 'does_not_exist' || $tablename == '') |
|
| 714 | - return ''; |
|
| 715 | - |
|
| 716 | - global $dictionary; |
|
| 717 | - $engine=null; |
|
| 718 | - if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) |
|
| 719 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 720 | - |
|
| 721 | - return $this->repairTableParams($tablename, $fielddefs,$new_index,$execute,$engine); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Can this field be null? |
|
| 726 | - * Auto-increment and ID fields can not be null |
|
| 727 | - * @param array $vardef |
|
| 672 | + public function createTableParams($tablename, $fieldDefs, $indices, $engine = null) |
|
| 673 | + { |
|
| 674 | + if (!empty($fieldDefs)) { |
|
| 675 | + $sql = $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
| 676 | + $res = true; |
|
| 677 | + if ($sql) { |
|
| 678 | + $msg = "Error creating table: $tablename"; |
|
| 679 | + $res = ($res and $this->query($sql,true,$msg)); |
|
| 680 | + } |
|
| 681 | + if(!$this->supports("inline_keys")) { |
|
| 682 | + // handle constraints and indices |
|
| 683 | + $indicesArr = $this->getConstraintSql($indices, $tablename); |
|
| 684 | + if (count($indicesArr) > 0) |
|
| 685 | + foreach ($indicesArr as $indexSql) |
|
| 686 | + $res = ($res and $this->query($indexSql, true, "Error creating indexes")); |
|
| 687 | + } |
|
| 688 | + return $res; |
|
| 689 | + } |
|
| 690 | + return false; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Implements repair of a db table for a bean. |
|
| 695 | + * |
|
| 696 | + * @param SugarBean $bean SugarBean instance |
|
| 697 | + * @param bool $execute true if we want the action to take place, false if we just want the sql returned |
|
| 698 | + * @return string SQL statement or empty string, depending upon $execute |
|
| 699 | + */ |
|
| 700 | + public function repairTable(SugarBean $bean, $execute = true) |
|
| 701 | + { |
|
| 702 | + $indices = $bean->getIndices(); |
|
| 703 | + $fielddefs = $bean->getFieldDefinitions(); |
|
| 704 | + $tablename = $bean->getTableName(); |
|
| 705 | + |
|
| 706 | + //Clean the indexes to prevent duplicate definitions |
|
| 707 | + $new_index = array(); |
|
| 708 | + foreach($indices as $ind_def){ |
|
| 709 | + $new_index[$ind_def['name']] = $ind_def; |
|
| 710 | + } |
|
| 711 | + //jc: added this for beans that do not actually have a table, namely |
|
| 712 | + //ForecastOpportunities |
|
| 713 | + if($tablename == 'does_not_exist' || $tablename == '') |
|
| 714 | + return ''; |
|
| 715 | + |
|
| 716 | + global $dictionary; |
|
| 717 | + $engine=null; |
|
| 718 | + if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) |
|
| 719 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 720 | + |
|
| 721 | + return $this->repairTableParams($tablename, $fielddefs,$new_index,$execute,$engine); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Can this field be null? |
|
| 726 | + * Auto-increment and ID fields can not be null |
|
| 727 | + * @param array $vardef |
|
| 728 | 728 | * @return bool |
| 729 | 729 | */ |
| 730 | - protected function isNullable($vardef) |
|
| 731 | - { |
|
| 732 | - |
|
| 733 | - if(isset($vardef['isnull']) && (strtolower($vardef['isnull']) == 'false' || $vardef['isnull'] === false) |
|
| 734 | - && !empty($vardef['required'])) { |
|
| 735 | - /* required + is_null=false => not null */ |
|
| 736 | - return false; |
|
| 737 | - } |
|
| 738 | - if(empty($vardef['auto_increment']) && (empty($vardef['type']) || $vardef['type'] != 'id') |
|
| 739 | - && (empty($vardef['dbType']) || $vardef['dbType'] != 'id') |
|
| 740 | - && (empty($vardef['name']) || ($vardef['name'] != 'id' && $vardef['name'] != 'deleted')) |
|
| 741 | - ) { |
|
| 742 | - return true; |
|
| 743 | - } |
|
| 744 | - return false; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Builds the SQL commands that repair a table structure |
|
| 750 | - * |
|
| 751 | - * @param string $tablename |
|
| 752 | - * @param array $fielddefs Field definitions, in vardef format |
|
| 753 | - * @param array $indices Index definitions, in vardef format |
|
| 754 | - * @param bool $execute optional, true if we want the queries executed instead of returned |
|
| 755 | - * @param string $engine optional, MySQL engine |
|
| 730 | + protected function isNullable($vardef) |
|
| 731 | + { |
|
| 732 | + |
|
| 733 | + if(isset($vardef['isnull']) && (strtolower($vardef['isnull']) == 'false' || $vardef['isnull'] === false) |
|
| 734 | + && !empty($vardef['required'])) { |
|
| 735 | + /* required + is_null=false => not null */ |
|
| 736 | + return false; |
|
| 737 | + } |
|
| 738 | + if(empty($vardef['auto_increment']) && (empty($vardef['type']) || $vardef['type'] != 'id') |
|
| 739 | + && (empty($vardef['dbType']) || $vardef['dbType'] != 'id') |
|
| 740 | + && (empty($vardef['name']) || ($vardef['name'] != 'id' && $vardef['name'] != 'deleted')) |
|
| 741 | + ) { |
|
| 742 | + return true; |
|
| 743 | + } |
|
| 744 | + return false; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Builds the SQL commands that repair a table structure |
|
| 750 | + * |
|
| 751 | + * @param string $tablename |
|
| 752 | + * @param array $fielddefs Field definitions, in vardef format |
|
| 753 | + * @param array $indices Index definitions, in vardef format |
|
| 754 | + * @param bool $execute optional, true if we want the queries executed instead of returned |
|
| 755 | + * @param string $engine optional, MySQL engine |
|
| 756 | 756 | * @todo: refactor engine param to be more generic |
| 757 | 757 | * @return string |
| 758 | 758 | */ |
| 759 | - public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 760 | - { |
|
| 761 | - //jc: had a bug when running the repair if the tablename is blank the repair will |
|
| 762 | - //fail when it tries to create a repair table |
|
| 763 | - if ($tablename == '' || empty($fielddefs)) |
|
| 764 | - return ''; |
|
| 765 | - |
|
| 766 | - //if the table does not exist create it and we are done |
|
| 767 | - $sql = "/* Table : $tablename */\n"; |
|
| 768 | - if (!$this->tableExists($tablename)) { |
|
| 769 | - $createtablesql = $this->createTableSQLParams($tablename,$fielddefs,$indices,$engine); |
|
| 770 | - if($execute && $createtablesql){ |
|
| 771 | - $this->createTableParams($tablename,$fielddefs,$indices,$engine); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - $sql .= "/* MISSING TABLE: {$tablename} */\n"; |
|
| 775 | - $sql .= $createtablesql . "\n"; |
|
| 776 | - return $sql; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - $compareFieldDefs = $this->get_columns($tablename); |
|
| 780 | - $compareIndices = $this->get_indices($tablename); |
|
| 781 | - |
|
| 782 | - $take_action = false; |
|
| 783 | - |
|
| 784 | - // do column comparisons |
|
| 785 | - $sql .= "/*COLUMNS*/\n"; |
|
| 786 | - foreach ($fielddefs as $name => $value) { |
|
| 787 | - if (isset($value['source']) && $value['source'] != 'db') |
|
| 788 | - continue; |
|
| 759 | + public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 760 | + { |
|
| 761 | + //jc: had a bug when running the repair if the tablename is blank the repair will |
|
| 762 | + //fail when it tries to create a repair table |
|
| 763 | + if ($tablename == '' || empty($fielddefs)) |
|
| 764 | + return ''; |
|
| 765 | + |
|
| 766 | + //if the table does not exist create it and we are done |
|
| 767 | + $sql = "/* Table : $tablename */\n"; |
|
| 768 | + if (!$this->tableExists($tablename)) { |
|
| 769 | + $createtablesql = $this->createTableSQLParams($tablename,$fielddefs,$indices,$engine); |
|
| 770 | + if($execute && $createtablesql){ |
|
| 771 | + $this->createTableParams($tablename,$fielddefs,$indices,$engine); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + $sql .= "/* MISSING TABLE: {$tablename} */\n"; |
|
| 775 | + $sql .= $createtablesql . "\n"; |
|
| 776 | + return $sql; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + $compareFieldDefs = $this->get_columns($tablename); |
|
| 780 | + $compareIndices = $this->get_indices($tablename); |
|
| 781 | + |
|
| 782 | + $take_action = false; |
|
| 783 | + |
|
| 784 | + // do column comparisons |
|
| 785 | + $sql .= "/*COLUMNS*/\n"; |
|
| 786 | + foreach ($fielddefs as $name => $value) { |
|
| 787 | + if (isset($value['source']) && $value['source'] != 'db') |
|
| 788 | + continue; |
|
| 789 | 789 | |
| 790 | 790 | // Bug #42406. Skipping breaked vardef without type or name |
| 791 | 791 | if (isset($value['name']) == false || $value['name'] == false) |
@@ -799,183 +799,183 @@ discard block |
||
| 799 | 799 | continue; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - $name = strtolower($value['name']); |
|
| 803 | - // add or fix the field defs per what the DB is expected to give us back |
|
| 804 | - $this->massageFieldDef($value,$tablename); |
|
| 805 | - |
|
| 806 | - $ignorerequired=false; |
|
| 807 | - |
|
| 808 | - //Do not track requiredness in the DB, auto_increment, ID, |
|
| 809 | - // and deleted fields are always required in the DB, so don't force those |
|
| 810 | - if ($this->isNullable($value)) { |
|
| 811 | - $value['required'] = false; |
|
| 812 | - } |
|
| 813 | - //Should match the conditions in DBManager::oneColumnSQLRep for DB required fields, type='id' fields will sometimes |
|
| 814 | - |
|
| 815 | - //come into this function as 'type' = 'char', 'dbType' = 'id' without required set in $value. Assume they are correct and leave them alone. |
|
| 816 | - else if (($name == 'id' || $value['type'] == 'id' || (isset($value['dbType']) && $value['dbType'] == 'id')) |
|
| 817 | - && (!isset($value['required']) && isset($compareFieldDefs[$name]['required']))) |
|
| 818 | - { |
|
| 819 | - $value['required'] = $compareFieldDefs[$name]['required']; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - if ( !isset($compareFieldDefs[$name]) ) { |
|
| 823 | - // ok we need this field lets create it |
|
| 824 | - $sql .= "/*MISSING IN DATABASE - $name - ROW*/\n"; |
|
| 825 | - $sql .= $this->addColumnSQL($tablename, $value) . "\n"; |
|
| 826 | - if ($execute) |
|
| 827 | - $this->addColumn($tablename, $value); |
|
| 828 | - $take_action = true; |
|
| 829 | - } elseif ( !$this->compareVarDefs($compareFieldDefs[$name],$value)) { |
|
| 830 | - //fields are different lets alter it |
|
| 831 | - $sql .= "/*MISMATCH WITH DATABASE - $name - ROW "; |
|
| 832 | - foreach($compareFieldDefs[$name] as $rKey => $rValue) { |
|
| 833 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 834 | - } |
|
| 835 | - $sql .= "*/\n"; |
|
| 836 | - $sql .= "/* VARDEF - $name - ROW"; |
|
| 837 | - foreach($value as $rKey => $rValue) { |
|
| 838 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 839 | - } |
|
| 840 | - $sql .= "*/\n"; |
|
| 841 | - |
|
| 842 | - //jc: oracle will complain if you try to execute a statement that sets a column to (not) null |
|
| 843 | - //when it is already (not) null |
|
| 844 | - if ( isset($value['isnull']) && isset($compareFieldDefs[$name]['isnull']) && |
|
| 845 | - $value['isnull'] === $compareFieldDefs[$name]['isnull']) { |
|
| 846 | - unset($value['required']); |
|
| 847 | - $ignorerequired=true; |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - //dwheeler: Once a column has been defined as null, we cannot try to force it back to !null |
|
| 851 | - if ((isset($value['required']) && ($value['required'] === true || $value['required'] == 'true' || $value['required'] === 1)) |
|
| 852 | - && (empty($compareFieldDefs[$name]['required']) || $compareFieldDefs[$name]['required'] != 'true')) |
|
| 853 | - { |
|
| 854 | - $ignorerequired = true; |
|
| 855 | - } |
|
| 856 | - $altersql = $this->alterColumnSQL($tablename, $value,$ignorerequired); |
|
| 857 | - if(is_array($altersql)) { |
|
| 858 | - $altersql = join("\n", $altersql); |
|
| 859 | - } |
|
| 860 | - $sql .= $altersql . "\n"; |
|
| 861 | - if($execute){ |
|
| 862 | - $this->alterColumn($tablename, $value, $ignorerequired); |
|
| 863 | - } |
|
| 864 | - $take_action = true; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - // do index comparisons |
|
| 869 | - $sql .= "/* INDEXES */\n"; |
|
| 870 | - $correctedIndexs = array(); |
|
| 802 | + $name = strtolower($value['name']); |
|
| 803 | + // add or fix the field defs per what the DB is expected to give us back |
|
| 804 | + $this->massageFieldDef($value,$tablename); |
|
| 871 | 805 | |
| 872 | - $compareIndices_case_insensitive = array(); |
|
| 806 | + $ignorerequired=false; |
|
| 873 | 807 | |
| 874 | - // do indices comparisons case-insensitive |
|
| 875 | - foreach($compareIndices as $k => $value){ |
|
| 876 | - $value['name'] = strtolower($value['name']); |
|
| 877 | - $compareIndices_case_insensitive[strtolower($k)] = $value; |
|
| 878 | - } |
|
| 879 | - $compareIndices = $compareIndices_case_insensitive; |
|
| 880 | - unset($compareIndices_case_insensitive); |
|
| 881 | - |
|
| 882 | - foreach ($indices as $value) { |
|
| 883 | - if (isset($value['source']) && $value['source'] != 'db') |
|
| 884 | - continue; |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - $validDBName = $this->getValidDBName($value['name'], true, 'index', true); |
|
| 888 | - if (isset($compareIndices[$validDBName])) { |
|
| 889 | - $value['name'] = $validDBName; |
|
| 890 | - } |
|
| 891 | - $name = strtolower($value['name']); |
|
| 892 | - |
|
| 893 | - //Don't attempt to fix the same index twice in one pass; |
|
| 894 | - if (isset($correctedIndexs[$name])) |
|
| 895 | - continue; |
|
| 896 | - |
|
| 897 | - //don't bother checking primary nothing we can do about them |
|
| 898 | - if (isset($value['type']) && $value['type'] == 'primary') |
|
| 899 | - continue; |
|
| 900 | - |
|
| 901 | - //database helpers do not know how to handle full text indices |
|
| 902 | - if ($value['type']=='fulltext') |
|
| 903 | - continue; |
|
| 904 | - |
|
| 905 | - if ( in_array($value['type'],array('alternate_key','foreign')) ) |
|
| 906 | - $value['type'] = 'index'; |
|
| 907 | - |
|
| 908 | - if ( !isset($compareIndices[$name]) ) { |
|
| 909 | - //First check if an index exists that doesn't match our name, if so, try to rename it |
|
| 910 | - $found = false; |
|
| 911 | - foreach ($compareIndices as $ex_name => $ex_value) { |
|
| 912 | - if($this->compareVarDefs($ex_value, $value, true)) { |
|
| 913 | - $found = $ex_name; |
|
| 914 | - break; |
|
| 915 | - } |
|
| 916 | - } |
|
| 917 | - if ($found) { |
|
| 918 | - $sql .= "/*MISSNAMED INDEX IN DATABASE - $name - $ex_name */\n"; |
|
| 919 | - $rename = $this->renameIndexDefs($ex_value, $value, $tablename); |
|
| 920 | - if($execute) { |
|
| 921 | - $this->query($rename, true, "Cannot rename index"); |
|
| 922 | - } |
|
| 923 | - $sql .= is_array($rename)?join("\n", $rename). "\n":$rename."\n"; |
|
| 924 | - |
|
| 925 | - } else { |
|
| 926 | - // ok we need this field lets create it |
|
| 927 | - $sql .= "/*MISSING INDEX IN DATABASE - $name -{$value['type']} ROW */\n"; |
|
| 928 | - $sql .= $this->addIndexes($tablename,array($value), $execute) . "\n"; |
|
| 929 | - } |
|
| 930 | - $take_action = true; |
|
| 931 | - $correctedIndexs[$name] = true; |
|
| 932 | - } elseif ( !$this->compareVarDefs($compareIndices[$name],$value) ) { |
|
| 933 | - // fields are different lets alter it |
|
| 934 | - $sql .= "/*INDEX MISMATCH WITH DATABASE - $name - ROW "; |
|
| 935 | - foreach ($compareIndices[$name] as $n1 => $t1) { |
|
| 936 | - $sql .= "<$n1>"; |
|
| 937 | - if ( $n1 == 'fields' ) |
|
| 938 | - foreach($t1 as $rKey => $rValue) |
|
| 939 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 940 | - else |
|
| 941 | - $sql .= " $t1 "; |
|
| 942 | - } |
|
| 943 | - $sql .= "*/\n"; |
|
| 944 | - $sql .= "/* VARDEF - $name - ROW"; |
|
| 945 | - foreach ($value as $n1 => $t1) { |
|
| 946 | - $sql .= "<$n1>"; |
|
| 947 | - if ( $n1 == 'fields' ) |
|
| 948 | - foreach ($t1 as $rKey => $rValue) |
|
| 949 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 950 | - else |
|
| 951 | - $sql .= " $t1 "; |
|
| 952 | - } |
|
| 953 | - $sql .= "*/\n"; |
|
| 954 | - $sql .= $this->modifyIndexes($tablename,array($value), $execute) . "\n"; |
|
| 955 | - $take_action = true; |
|
| 956 | - $correctedIndexs[$name] = true; |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - |
|
| 960 | - return ($take_action === true) ? $sql : ''; |
|
| 961 | - } |
|
| 808 | + //Do not track requiredness in the DB, auto_increment, ID, |
|
| 809 | + // and deleted fields are always required in the DB, so don't force those |
|
| 810 | + if ($this->isNullable($value)) { |
|
| 811 | + $value['required'] = false; |
|
| 812 | + } |
|
| 813 | + //Should match the conditions in DBManager::oneColumnSQLRep for DB required fields, type='id' fields will sometimes |
|
| 962 | 814 | |
| 963 | - /** |
|
| 964 | - * Compares two vardefs |
|
| 965 | - * |
|
| 966 | - * @param array $fielddef1 This is from the database |
|
| 967 | - * @param array $fielddef2 This is from the vardef |
|
| 968 | - * @param bool $ignoreName Ignore name-only differences? |
|
| 969 | - * @return bool true if they match, false if they don't |
|
| 970 | - */ |
|
| 971 | - public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
|
| 972 | - { |
|
| 973 | - foreach ( $fielddef1 as $key => $value ) { |
|
| 974 | - if ($key == 'name' && $ignoreName) |
|
| 975 | - continue; |
|
| 976 | - if (isset($fielddef2[$key])) |
|
| 815 | + //come into this function as 'type' = 'char', 'dbType' = 'id' without required set in $value. Assume they are correct and leave them alone. |
|
| 816 | + else if (($name == 'id' || $value['type'] == 'id' || (isset($value['dbType']) && $value['dbType'] == 'id')) |
|
| 817 | + && (!isset($value['required']) && isset($compareFieldDefs[$name]['required']))) |
|
| 977 | 818 | { |
| 978 | - if (!is_array($fielddef1[$key]) && !is_array($fielddef2[$key])) |
|
| 819 | + $value['required'] = $compareFieldDefs[$name]['required']; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + if ( !isset($compareFieldDefs[$name]) ) { |
|
| 823 | + // ok we need this field lets create it |
|
| 824 | + $sql .= "/*MISSING IN DATABASE - $name - ROW*/\n"; |
|
| 825 | + $sql .= $this->addColumnSQL($tablename, $value) . "\n"; |
|
| 826 | + if ($execute) |
|
| 827 | + $this->addColumn($tablename, $value); |
|
| 828 | + $take_action = true; |
|
| 829 | + } elseif ( !$this->compareVarDefs($compareFieldDefs[$name],$value)) { |
|
| 830 | + //fields are different lets alter it |
|
| 831 | + $sql .= "/*MISMATCH WITH DATABASE - $name - ROW "; |
|
| 832 | + foreach($compareFieldDefs[$name] as $rKey => $rValue) { |
|
| 833 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 834 | + } |
|
| 835 | + $sql .= "*/\n"; |
|
| 836 | + $sql .= "/* VARDEF - $name - ROW"; |
|
| 837 | + foreach($value as $rKey => $rValue) { |
|
| 838 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 839 | + } |
|
| 840 | + $sql .= "*/\n"; |
|
| 841 | + |
|
| 842 | + //jc: oracle will complain if you try to execute a statement that sets a column to (not) null |
|
| 843 | + //when it is already (not) null |
|
| 844 | + if ( isset($value['isnull']) && isset($compareFieldDefs[$name]['isnull']) && |
|
| 845 | + $value['isnull'] === $compareFieldDefs[$name]['isnull']) { |
|
| 846 | + unset($value['required']); |
|
| 847 | + $ignorerequired=true; |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + //dwheeler: Once a column has been defined as null, we cannot try to force it back to !null |
|
| 851 | + if ((isset($value['required']) && ($value['required'] === true || $value['required'] == 'true' || $value['required'] === 1)) |
|
| 852 | + && (empty($compareFieldDefs[$name]['required']) || $compareFieldDefs[$name]['required'] != 'true')) |
|
| 853 | + { |
|
| 854 | + $ignorerequired = true; |
|
| 855 | + } |
|
| 856 | + $altersql = $this->alterColumnSQL($tablename, $value,$ignorerequired); |
|
| 857 | + if(is_array($altersql)) { |
|
| 858 | + $altersql = join("\n", $altersql); |
|
| 859 | + } |
|
| 860 | + $sql .= $altersql . "\n"; |
|
| 861 | + if($execute){ |
|
| 862 | + $this->alterColumn($tablename, $value, $ignorerequired); |
|
| 863 | + } |
|
| 864 | + $take_action = true; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + // do index comparisons |
|
| 869 | + $sql .= "/* INDEXES */\n"; |
|
| 870 | + $correctedIndexs = array(); |
|
| 871 | + |
|
| 872 | + $compareIndices_case_insensitive = array(); |
|
| 873 | + |
|
| 874 | + // do indices comparisons case-insensitive |
|
| 875 | + foreach($compareIndices as $k => $value){ |
|
| 876 | + $value['name'] = strtolower($value['name']); |
|
| 877 | + $compareIndices_case_insensitive[strtolower($k)] = $value; |
|
| 878 | + } |
|
| 879 | + $compareIndices = $compareIndices_case_insensitive; |
|
| 880 | + unset($compareIndices_case_insensitive); |
|
| 881 | + |
|
| 882 | + foreach ($indices as $value) { |
|
| 883 | + if (isset($value['source']) && $value['source'] != 'db') |
|
| 884 | + continue; |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + $validDBName = $this->getValidDBName($value['name'], true, 'index', true); |
|
| 888 | + if (isset($compareIndices[$validDBName])) { |
|
| 889 | + $value['name'] = $validDBName; |
|
| 890 | + } |
|
| 891 | + $name = strtolower($value['name']); |
|
| 892 | + |
|
| 893 | + //Don't attempt to fix the same index twice in one pass; |
|
| 894 | + if (isset($correctedIndexs[$name])) |
|
| 895 | + continue; |
|
| 896 | + |
|
| 897 | + //don't bother checking primary nothing we can do about them |
|
| 898 | + if (isset($value['type']) && $value['type'] == 'primary') |
|
| 899 | + continue; |
|
| 900 | + |
|
| 901 | + //database helpers do not know how to handle full text indices |
|
| 902 | + if ($value['type']=='fulltext') |
|
| 903 | + continue; |
|
| 904 | + |
|
| 905 | + if ( in_array($value['type'],array('alternate_key','foreign')) ) |
|
| 906 | + $value['type'] = 'index'; |
|
| 907 | + |
|
| 908 | + if ( !isset($compareIndices[$name]) ) { |
|
| 909 | + //First check if an index exists that doesn't match our name, if so, try to rename it |
|
| 910 | + $found = false; |
|
| 911 | + foreach ($compareIndices as $ex_name => $ex_value) { |
|
| 912 | + if($this->compareVarDefs($ex_value, $value, true)) { |
|
| 913 | + $found = $ex_name; |
|
| 914 | + break; |
|
| 915 | + } |
|
| 916 | + } |
|
| 917 | + if ($found) { |
|
| 918 | + $sql .= "/*MISSNAMED INDEX IN DATABASE - $name - $ex_name */\n"; |
|
| 919 | + $rename = $this->renameIndexDefs($ex_value, $value, $tablename); |
|
| 920 | + if($execute) { |
|
| 921 | + $this->query($rename, true, "Cannot rename index"); |
|
| 922 | + } |
|
| 923 | + $sql .= is_array($rename)?join("\n", $rename). "\n":$rename."\n"; |
|
| 924 | + |
|
| 925 | + } else { |
|
| 926 | + // ok we need this field lets create it |
|
| 927 | + $sql .= "/*MISSING INDEX IN DATABASE - $name -{$value['type']} ROW */\n"; |
|
| 928 | + $sql .= $this->addIndexes($tablename,array($value), $execute) . "\n"; |
|
| 929 | + } |
|
| 930 | + $take_action = true; |
|
| 931 | + $correctedIndexs[$name] = true; |
|
| 932 | + } elseif ( !$this->compareVarDefs($compareIndices[$name],$value) ) { |
|
| 933 | + // fields are different lets alter it |
|
| 934 | + $sql .= "/*INDEX MISMATCH WITH DATABASE - $name - ROW "; |
|
| 935 | + foreach ($compareIndices[$name] as $n1 => $t1) { |
|
| 936 | + $sql .= "<$n1>"; |
|
| 937 | + if ( $n1 == 'fields' ) |
|
| 938 | + foreach($t1 as $rKey => $rValue) |
|
| 939 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 940 | + else |
|
| 941 | + $sql .= " $t1 "; |
|
| 942 | + } |
|
| 943 | + $sql .= "*/\n"; |
|
| 944 | + $sql .= "/* VARDEF - $name - ROW"; |
|
| 945 | + foreach ($value as $n1 => $t1) { |
|
| 946 | + $sql .= "<$n1>"; |
|
| 947 | + if ( $n1 == 'fields' ) |
|
| 948 | + foreach ($t1 as $rKey => $rValue) |
|
| 949 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 950 | + else |
|
| 951 | + $sql .= " $t1 "; |
|
| 952 | + } |
|
| 953 | + $sql .= "*/\n"; |
|
| 954 | + $sql .= $this->modifyIndexes($tablename,array($value), $execute) . "\n"; |
|
| 955 | + $take_action = true; |
|
| 956 | + $correctedIndexs[$name] = true; |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + |
|
| 960 | + return ($take_action === true) ? $sql : ''; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * Compares two vardefs |
|
| 965 | + * |
|
| 966 | + * @param array $fielddef1 This is from the database |
|
| 967 | + * @param array $fielddef2 This is from the vardef |
|
| 968 | + * @param bool $ignoreName Ignore name-only differences? |
|
| 969 | + * @return bool true if they match, false if they don't |
|
| 970 | + */ |
|
| 971 | + public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
|
| 972 | + { |
|
| 973 | + foreach ( $fielddef1 as $key => $value ) { |
|
| 974 | + if ($key == 'name' && $ignoreName) |
|
| 975 | + continue; |
|
| 976 | + if (isset($fielddef2[$key])) |
|
| 977 | + { |
|
| 978 | + if (!is_array($fielddef1[$key]) && !is_array($fielddef2[$key])) |
|
| 979 | 979 | { |
| 980 | 980 | if (strtolower($fielddef1[$key]) == strtolower($fielddef2[$key])) |
| 981 | 981 | { |
@@ -990,64 +990,64 @@ discard block |
||
| 990 | 990 | } |
| 991 | 991 | } |
| 992 | 992 | } |
| 993 | - //Ignore len if its not set in the vardef |
|
| 994 | - if ($key == 'len' && empty($fielddef2[$key])) |
|
| 995 | - continue; |
|
| 993 | + //Ignore len if its not set in the vardef |
|
| 994 | + if ($key == 'len' && empty($fielddef2[$key])) |
|
| 995 | + continue; |
|
| 996 | 996 | // if the length in db is greather than the vardef, ignore it |
| 997 | 997 | if ($key == 'len' && ($fielddef1[$key] >= $fielddef2[$key])) { |
| 998 | 998 | continue; |
| 999 | 999 | } |
| 1000 | - return false; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - return true; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - /** |
|
| 1007 | - * Compare a field in two tables |
|
| 1008 | - * @deprecated |
|
| 1009 | - * @param string $name field name |
|
| 1010 | - * @param string $table1 |
|
| 1011 | - * @param string $table2 |
|
| 1012 | - * @return array array with keys 'msg','table1','table2' |
|
| 1013 | - */ |
|
| 1014 | - public function compareFieldInTables($name, $table1, $table2) |
|
| 1015 | - { |
|
| 1016 | - $row1 = $this->describeField($name, $table1); |
|
| 1017 | - $row2 = $this->describeField($name, $table2); |
|
| 1018 | - $returnArray = array( |
|
| 1019 | - 'table1' => $row1, |
|
| 1020 | - 'table2' => $row2, |
|
| 1021 | - 'msg' => 'error', |
|
| 1022 | - ); |
|
| 1023 | - |
|
| 1024 | - $ignore_filter = array('Key'=>1); |
|
| 1025 | - if ($row1) { |
|
| 1026 | - if (!$row2) { |
|
| 1027 | - // Exists on table1 but not table2 |
|
| 1028 | - $returnArray['msg'] = 'not_exists_table2'; |
|
| 1029 | - } |
|
| 1030 | - else { |
|
| 1031 | - if (sizeof($row1) != sizeof($row2)) { |
|
| 1032 | - $returnArray['msg'] = 'no_match'; |
|
| 1033 | - } |
|
| 1034 | - else { |
|
| 1035 | - $returnArray['msg'] = 'match'; |
|
| 1036 | - foreach($row1 as $key => $value){ |
|
| 1037 | - //ignore keys when checking we will check them when we do the index check |
|
| 1038 | - if( !isset($ignore_filter[$key]) && (!isset($row2[$key]) || $row1[$key] !== $row2[$key])){ |
|
| 1039 | - $returnArray['msg'] = 'no_match'; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1044 | - } |
|
| 1045 | - else { |
|
| 1046 | - $returnArray['msg'] = 'not_exists_table1'; |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - return $returnArray; |
|
| 1050 | - } |
|
| 1000 | + return false; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + return true; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + /** |
|
| 1007 | + * Compare a field in two tables |
|
| 1008 | + * @deprecated |
|
| 1009 | + * @param string $name field name |
|
| 1010 | + * @param string $table1 |
|
| 1011 | + * @param string $table2 |
|
| 1012 | + * @return array array with keys 'msg','table1','table2' |
|
| 1013 | + */ |
|
| 1014 | + public function compareFieldInTables($name, $table1, $table2) |
|
| 1015 | + { |
|
| 1016 | + $row1 = $this->describeField($name, $table1); |
|
| 1017 | + $row2 = $this->describeField($name, $table2); |
|
| 1018 | + $returnArray = array( |
|
| 1019 | + 'table1' => $row1, |
|
| 1020 | + 'table2' => $row2, |
|
| 1021 | + 'msg' => 'error', |
|
| 1022 | + ); |
|
| 1023 | + |
|
| 1024 | + $ignore_filter = array('Key'=>1); |
|
| 1025 | + if ($row1) { |
|
| 1026 | + if (!$row2) { |
|
| 1027 | + // Exists on table1 but not table2 |
|
| 1028 | + $returnArray['msg'] = 'not_exists_table2'; |
|
| 1029 | + } |
|
| 1030 | + else { |
|
| 1031 | + if (sizeof($row1) != sizeof($row2)) { |
|
| 1032 | + $returnArray['msg'] = 'no_match'; |
|
| 1033 | + } |
|
| 1034 | + else { |
|
| 1035 | + $returnArray['msg'] = 'match'; |
|
| 1036 | + foreach($row1 as $key => $value){ |
|
| 1037 | + //ignore keys when checking we will check them when we do the index check |
|
| 1038 | + if( !isset($ignore_filter[$key]) && (!isset($row2[$key]) || $row1[$key] !== $row2[$key])){ |
|
| 1039 | + $returnArray['msg'] = 'no_match'; |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | + } |
|
| 1045 | + else { |
|
| 1046 | + $returnArray['msg'] = 'not_exists_table1'; |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + return $returnArray; |
|
| 1050 | + } |
|
| 1051 | 1051 | // |
| 1052 | 1052 | // /** |
| 1053 | 1053 | // * Compare an index in two different tables |
@@ -1097,193 +1097,193 @@ discard block |
||
| 1097 | 1097 | // } |
| 1098 | 1098 | |
| 1099 | 1099 | |
| 1100 | - /** |
|
| 1101 | - * Creates an index identified by name on the given fields. |
|
| 1102 | - * |
|
| 1103 | - * @param SugarBean $bean SugarBean instance |
|
| 1104 | - * @param array $fieldDefs Field definitions, in vardef format |
|
| 1105 | - * @param string $name index name |
|
| 1106 | - * @param bool $unique optional, true if we want to create an unique index |
|
| 1100 | + /** |
|
| 1101 | + * Creates an index identified by name on the given fields. |
|
| 1102 | + * |
|
| 1103 | + * @param SugarBean $bean SugarBean instance |
|
| 1104 | + * @param array $fieldDefs Field definitions, in vardef format |
|
| 1105 | + * @param string $name index name |
|
| 1106 | + * @param bool $unique optional, true if we want to create an unique index |
|
| 1107 | 1107 | * @return bool query result |
| 1108 | 1108 | */ |
| 1109 | - public function createIndex(SugarBean $bean, $fieldDefs, $name, $unique = true) |
|
| 1110 | - { |
|
| 1111 | - $sql = $this->createIndexSQL($bean, $fieldDefs, $name, $unique); |
|
| 1112 | - $tablename = $bean->getTableName(); |
|
| 1113 | - $msg = "Error creating index $name on table: $tablename:"; |
|
| 1114 | - return $this->query($sql,true,$msg); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * returns a SQL query that creates the indices as defined in metadata |
|
| 1119 | - * @param array $indices Assoc array with index definitions from vardefs |
|
| 1120 | - * @param string $table Focus table |
|
| 1121 | - * @return array Array of SQL queries to generate indices |
|
| 1122 | - */ |
|
| 1123 | - public function getConstraintSql($indices, $table) |
|
| 1124 | - { |
|
| 1125 | - if (!$this->isFieldArray($indices)) |
|
| 1126 | - $indices = array($indices); |
|
| 1127 | - |
|
| 1128 | - $columns = array(); |
|
| 1129 | - |
|
| 1130 | - foreach ($indices as $index) { |
|
| 1131 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 1132 | - continue; |
|
| 1133 | - if (isset($index['source']) && $index['source'] != 'db') |
|
| 1134 | - continue; |
|
| 1135 | - |
|
| 1136 | - $sql = $this->add_drop_constraint($table, $index); |
|
| 1137 | - |
|
| 1138 | - if(!empty($sql)) { |
|
| 1139 | - $columns[] = $sql; |
|
| 1140 | - } |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - return $columns; |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * Adds a new indexes |
|
| 1148 | - * |
|
| 1149 | - * @param string $tablename |
|
| 1150 | - * @param array $indexes indexes to add |
|
| 1151 | - * @param bool $execute true if we want to execute the returned sql statement |
|
| 1152 | - * @return string SQL statement |
|
| 1153 | - */ |
|
| 1154 | - public function addIndexes($tablename, $indexes, $execute = true) |
|
| 1155 | - { |
|
| 1156 | - $alters = $this->getConstraintSql($indexes, $tablename); |
|
| 1157 | - if ($execute) { |
|
| 1158 | - foreach($alters as $sql) { |
|
| 1159 | - $this->query($sql, true, "Error adding index: "); |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - if(!empty($alters)) { |
|
| 1163 | - $sql = join(";\n", $alters).";\n"; |
|
| 1164 | - } else { |
|
| 1165 | - $sql = ''; |
|
| 1166 | - } |
|
| 1167 | - return $sql; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - /** |
|
| 1171 | - * Drops indexes |
|
| 1172 | - * |
|
| 1173 | - * @param string $tablename |
|
| 1174 | - * @param array $indexes indexes to drop |
|
| 1175 | - * @param bool $execute true if we want to execute the returned sql statement |
|
| 1176 | - * @return string SQL statement |
|
| 1177 | - */ |
|
| 1178 | - public function dropIndexes($tablename, $indexes, $execute = true) |
|
| 1179 | - { |
|
| 1180 | - $sqls = array(); |
|
| 1181 | - foreach ($indexes as $index) { |
|
| 1182 | - $name =$index['name']; |
|
| 1183 | - $sqls[$name] = $this->add_drop_constraint($tablename,$index,true); |
|
| 1184 | - } |
|
| 1185 | - if (!empty($sqls) && $execute) { |
|
| 1186 | - foreach($sqls as $name => $sql) { |
|
| 1187 | - unset(self::$index_descriptions[$tablename][$name]); |
|
| 1188 | - $this->query($sql); |
|
| 1189 | - } |
|
| 1190 | - } |
|
| 1191 | - if(!empty($sqls)) { |
|
| 1192 | - return join(";\n",$sqls).";"; |
|
| 1193 | - } else { |
|
| 1194 | - return ''; |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * Modifies indexes |
|
| 1200 | - * |
|
| 1201 | - * @param string $tablename |
|
| 1202 | - * @param array $indexes indexes to modify |
|
| 1203 | - * @param bool $execute true if we want to execute the returned sql statement |
|
| 1204 | - * @return string SQL statement |
|
| 1205 | - */ |
|
| 1206 | - public function modifyIndexes($tablename, $indexes, $execute = true) |
|
| 1207 | - { |
|
| 1208 | - return $this->dropIndexes($tablename, $indexes, $execute)."\n". |
|
| 1209 | - $this->addIndexes($tablename, $indexes, $execute); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - /** |
|
| 1213 | - * Adds a column to table identified by field def. |
|
| 1214 | - * |
|
| 1215 | - * @param string $tablename |
|
| 1216 | - * @param array $fieldDefs |
|
| 1109 | + public function createIndex(SugarBean $bean, $fieldDefs, $name, $unique = true) |
|
| 1110 | + { |
|
| 1111 | + $sql = $this->createIndexSQL($bean, $fieldDefs, $name, $unique); |
|
| 1112 | + $tablename = $bean->getTableName(); |
|
| 1113 | + $msg = "Error creating index $name on table: $tablename:"; |
|
| 1114 | + return $this->query($sql,true,$msg); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * returns a SQL query that creates the indices as defined in metadata |
|
| 1119 | + * @param array $indices Assoc array with index definitions from vardefs |
|
| 1120 | + * @param string $table Focus table |
|
| 1121 | + * @return array Array of SQL queries to generate indices |
|
| 1122 | + */ |
|
| 1123 | + public function getConstraintSql($indices, $table) |
|
| 1124 | + { |
|
| 1125 | + if (!$this->isFieldArray($indices)) |
|
| 1126 | + $indices = array($indices); |
|
| 1127 | + |
|
| 1128 | + $columns = array(); |
|
| 1129 | + |
|
| 1130 | + foreach ($indices as $index) { |
|
| 1131 | + if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 1132 | + continue; |
|
| 1133 | + if (isset($index['source']) && $index['source'] != 'db') |
|
| 1134 | + continue; |
|
| 1135 | + |
|
| 1136 | + $sql = $this->add_drop_constraint($table, $index); |
|
| 1137 | + |
|
| 1138 | + if(!empty($sql)) { |
|
| 1139 | + $columns[] = $sql; |
|
| 1140 | + } |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + return $columns; |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * Adds a new indexes |
|
| 1148 | + * |
|
| 1149 | + * @param string $tablename |
|
| 1150 | + * @param array $indexes indexes to add |
|
| 1151 | + * @param bool $execute true if we want to execute the returned sql statement |
|
| 1152 | + * @return string SQL statement |
|
| 1153 | + */ |
|
| 1154 | + public function addIndexes($tablename, $indexes, $execute = true) |
|
| 1155 | + { |
|
| 1156 | + $alters = $this->getConstraintSql($indexes, $tablename); |
|
| 1157 | + if ($execute) { |
|
| 1158 | + foreach($alters as $sql) { |
|
| 1159 | + $this->query($sql, true, "Error adding index: "); |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + if(!empty($alters)) { |
|
| 1163 | + $sql = join(";\n", $alters).";\n"; |
|
| 1164 | + } else { |
|
| 1165 | + $sql = ''; |
|
| 1166 | + } |
|
| 1167 | + return $sql; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + /** |
|
| 1171 | + * Drops indexes |
|
| 1172 | + * |
|
| 1173 | + * @param string $tablename |
|
| 1174 | + * @param array $indexes indexes to drop |
|
| 1175 | + * @param bool $execute true if we want to execute the returned sql statement |
|
| 1176 | + * @return string SQL statement |
|
| 1177 | + */ |
|
| 1178 | + public function dropIndexes($tablename, $indexes, $execute = true) |
|
| 1179 | + { |
|
| 1180 | + $sqls = array(); |
|
| 1181 | + foreach ($indexes as $index) { |
|
| 1182 | + $name =$index['name']; |
|
| 1183 | + $sqls[$name] = $this->add_drop_constraint($tablename,$index,true); |
|
| 1184 | + } |
|
| 1185 | + if (!empty($sqls) && $execute) { |
|
| 1186 | + foreach($sqls as $name => $sql) { |
|
| 1187 | + unset(self::$index_descriptions[$tablename][$name]); |
|
| 1188 | + $this->query($sql); |
|
| 1189 | + } |
|
| 1190 | + } |
|
| 1191 | + if(!empty($sqls)) { |
|
| 1192 | + return join(";\n",$sqls).";"; |
|
| 1193 | + } else { |
|
| 1194 | + return ''; |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * Modifies indexes |
|
| 1200 | + * |
|
| 1201 | + * @param string $tablename |
|
| 1202 | + * @param array $indexes indexes to modify |
|
| 1203 | + * @param bool $execute true if we want to execute the returned sql statement |
|
| 1204 | + * @return string SQL statement |
|
| 1205 | + */ |
|
| 1206 | + public function modifyIndexes($tablename, $indexes, $execute = true) |
|
| 1207 | + { |
|
| 1208 | + return $this->dropIndexes($tablename, $indexes, $execute)."\n". |
|
| 1209 | + $this->addIndexes($tablename, $indexes, $execute); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + /** |
|
| 1213 | + * Adds a column to table identified by field def. |
|
| 1214 | + * |
|
| 1215 | + * @param string $tablename |
|
| 1216 | + * @param array $fieldDefs |
|
| 1217 | 1217 | * @return bool query result |
| 1218 | 1218 | */ |
| 1219 | - public function addColumn($tablename, $fieldDefs) |
|
| 1220 | - { |
|
| 1221 | - $sql = $this->addColumnSQL($tablename, $fieldDefs); |
|
| 1222 | - if ($this->isFieldArray($fieldDefs)){ |
|
| 1223 | - $columns = array(); |
|
| 1224 | - foreach ($fieldDefs as $fieldDef) |
|
| 1225 | - $columns[] = $fieldDef['name']; |
|
| 1226 | - $columns = implode(",", $columns); |
|
| 1227 | - } |
|
| 1228 | - else { |
|
| 1229 | - $columns = $fieldDefs['name']; |
|
| 1230 | - } |
|
| 1231 | - $msg = "Error adding column(s) $columns on table: $tablename:"; |
|
| 1232 | - return $this->query($sql,true,$msg); |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Alters old column identified by oldFieldDef to new fieldDef. |
|
| 1237 | - * |
|
| 1238 | - * @param string $tablename |
|
| 1239 | - * @param array $newFieldDef |
|
| 1240 | - * @param bool $ignoreRequired optional, true if we are ignoring this being a required field |
|
| 1219 | + public function addColumn($tablename, $fieldDefs) |
|
| 1220 | + { |
|
| 1221 | + $sql = $this->addColumnSQL($tablename, $fieldDefs); |
|
| 1222 | + if ($this->isFieldArray($fieldDefs)){ |
|
| 1223 | + $columns = array(); |
|
| 1224 | + foreach ($fieldDefs as $fieldDef) |
|
| 1225 | + $columns[] = $fieldDef['name']; |
|
| 1226 | + $columns = implode(",", $columns); |
|
| 1227 | + } |
|
| 1228 | + else { |
|
| 1229 | + $columns = $fieldDefs['name']; |
|
| 1230 | + } |
|
| 1231 | + $msg = "Error adding column(s) $columns on table: $tablename:"; |
|
| 1232 | + return $this->query($sql,true,$msg); |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * Alters old column identified by oldFieldDef to new fieldDef. |
|
| 1237 | + * |
|
| 1238 | + * @param string $tablename |
|
| 1239 | + * @param array $newFieldDef |
|
| 1240 | + * @param bool $ignoreRequired optional, true if we are ignoring this being a required field |
|
| 1241 | 1241 | * @return bool query result |
| 1242 | 1242 | */ |
| 1243 | - public function alterColumn($tablename, $newFieldDef, $ignoreRequired = false) |
|
| 1244 | - { |
|
| 1245 | - $sql = $this->alterColumnSQL($tablename, $newFieldDef,$ignoreRequired); |
|
| 1246 | - if ($this->isFieldArray($newFieldDef)){ |
|
| 1247 | - $columns = array(); |
|
| 1248 | - foreach ($newFieldDef as $fieldDef) { |
|
| 1249 | - $columns[] = $fieldDef['name']; |
|
| 1250 | - } |
|
| 1251 | - $columns = implode(",", $columns); |
|
| 1252 | - } |
|
| 1253 | - else { |
|
| 1254 | - $columns = $newFieldDef['name']; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - $msg = "Error altering column(s) $columns on table: $tablename:"; |
|
| 1258 | - $res = $this->query($sql,true,$msg); |
|
| 1259 | - if($res) { |
|
| 1260 | - $this->getTableDescription($tablename, true); // reload table description after altering |
|
| 1261 | - } |
|
| 1262 | - return $res; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - /** |
|
| 1266 | - * Drops the table associated with a bean |
|
| 1267 | - * |
|
| 1268 | - * @param SugarBean $bean SugarBean instance |
|
| 1243 | + public function alterColumn($tablename, $newFieldDef, $ignoreRequired = false) |
|
| 1244 | + { |
|
| 1245 | + $sql = $this->alterColumnSQL($tablename, $newFieldDef,$ignoreRequired); |
|
| 1246 | + if ($this->isFieldArray($newFieldDef)){ |
|
| 1247 | + $columns = array(); |
|
| 1248 | + foreach ($newFieldDef as $fieldDef) { |
|
| 1249 | + $columns[] = $fieldDef['name']; |
|
| 1250 | + } |
|
| 1251 | + $columns = implode(",", $columns); |
|
| 1252 | + } |
|
| 1253 | + else { |
|
| 1254 | + $columns = $newFieldDef['name']; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + $msg = "Error altering column(s) $columns on table: $tablename:"; |
|
| 1258 | + $res = $this->query($sql,true,$msg); |
|
| 1259 | + if($res) { |
|
| 1260 | + $this->getTableDescription($tablename, true); // reload table description after altering |
|
| 1261 | + } |
|
| 1262 | + return $res; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + /** |
|
| 1266 | + * Drops the table associated with a bean |
|
| 1267 | + * |
|
| 1268 | + * @param SugarBean $bean SugarBean instance |
|
| 1269 | 1269 | * @return bool query result |
| 1270 | - */ |
|
| 1271 | - public function dropTable(SugarBean $bean) |
|
| 1272 | - { |
|
| 1273 | - return $this->dropTableName($bean->getTableName()); |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Drops the table by name |
|
| 1278 | - * |
|
| 1279 | - * @param string $name Table name |
|
| 1270 | + */ |
|
| 1271 | + public function dropTable(SugarBean $bean) |
|
| 1272 | + { |
|
| 1273 | + return $this->dropTableName($bean->getTableName()); |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Drops the table by name |
|
| 1278 | + * |
|
| 1279 | + * @param string $name Table name |
|
| 1280 | 1280 | * @return bool query result |
| 1281 | - */ |
|
| 1282 | - public function dropTableName($name) |
|
| 1283 | - { |
|
| 1284 | - $sql = $this->dropTableNameSQL($name); |
|
| 1285 | - return $this->query($sql,true,"Error dropping table $name:"); |
|
| 1286 | - } |
|
| 1281 | + */ |
|
| 1282 | + public function dropTableName($name) |
|
| 1283 | + { |
|
| 1284 | + $sql = $this->dropTableNameSQL($name); |
|
| 1285 | + return $this->query($sql,true,"Error dropping table $name:"); |
|
| 1286 | + } |
|
| 1287 | 1287 | |
| 1288 | 1288 | /** |
| 1289 | 1289 | * Deletes a column identified by fieldDef. |
@@ -1292,13 +1292,13 @@ discard block |
||
| 1292 | 1292 | * @param array $fieldDefs Vardef definition of the field |
| 1293 | 1293 | * @return bool query result |
| 1294 | 1294 | */ |
| 1295 | - public function deleteColumn(SugarBean $bean, $fieldDefs) |
|
| 1296 | - { |
|
| 1297 | - $tablename = $bean->getTableName(); |
|
| 1298 | - $sql = $this->dropColumnSQL($tablename, $fieldDefs); |
|
| 1299 | - $msg = "Error deleting column(s) on table: $tablename:"; |
|
| 1300 | - return $this->query($sql,true,$msg); |
|
| 1301 | - } |
|
| 1295 | + public function deleteColumn(SugarBean $bean, $fieldDefs) |
|
| 1296 | + { |
|
| 1297 | + $tablename = $bean->getTableName(); |
|
| 1298 | + $sql = $this->dropColumnSQL($tablename, $fieldDefs); |
|
| 1299 | + $msg = "Error deleting column(s) on table: $tablename:"; |
|
| 1300 | + return $this->query($sql,true,$msg); |
|
| 1301 | + } |
|
| 1302 | 1302 | |
| 1303 | 1303 | /** |
| 1304 | 1304 | * Generate a set of Insert statements based on the bean given |
@@ -1313,228 +1313,228 @@ discard block |
||
| 1313 | 1313 | * @param bool $is_related_query |
| 1314 | 1314 | * @return string SQL insert statement |
| 1315 | 1315 | */ |
| 1316 | - public function generateInsertSQL(SugarBean $bean, $select_query, $start, $count = -1, $table, $is_related_query = false) |
|
| 1317 | - { |
|
| 1318 | - $this->log->info('call to DBManager::generateInsertSQL() is deprecated'); |
|
| 1319 | - global $sugar_config; |
|
| 1320 | - |
|
| 1321 | - $rows_found = 0; |
|
| 1322 | - $count_query = $bean->create_list_count_query($select_query); |
|
| 1323 | - if(!empty($count_query)) |
|
| 1324 | - { |
|
| 1325 | - // We have a count query. Run it and get the results. |
|
| 1326 | - $result = $this->query($count_query, true, "Error running count query for $this->object_name List: "); |
|
| 1327 | - $assoc = $this->fetchByAssoc($result); |
|
| 1328 | - if(!empty($assoc['c'])) |
|
| 1329 | - { |
|
| 1330 | - $rows_found = $assoc['c']; |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - if($count == -1){ |
|
| 1334 | - $count = $sugar_config['list_max_entries_per_page']; |
|
| 1335 | - } |
|
| 1336 | - $next_offset = $start + $count; |
|
| 1337 | - |
|
| 1338 | - $result = $this->limitQuery($select_query, $start, $count); |
|
| 1339 | - // get basic insert |
|
| 1340 | - $sql = "INSERT INTO ".$table; |
|
| 1341 | - $custom_sql = "INSERT INTO ".$table."_cstm"; |
|
| 1342 | - |
|
| 1343 | - // get field definitions |
|
| 1344 | - $fields = $bean->getFieldDefinitions(); |
|
| 1345 | - $custom_fields = array(); |
|
| 1346 | - |
|
| 1347 | - if($bean->hasCustomFields()){ |
|
| 1348 | - foreach ($fields as $fieldDef){ |
|
| 1349 | - if($fieldDef['source'] == 'custom_fields'){ |
|
| 1350 | - $custom_fields[$fieldDef['name']] = $fieldDef['name']; |
|
| 1351 | - } |
|
| 1352 | - } |
|
| 1353 | - if(!empty($custom_fields)){ |
|
| 1354 | - $custom_fields['id_c'] = 'id_c'; |
|
| 1355 | - $id_field = array('name' => 'id_c', 'custom_type' => 'id',); |
|
| 1356 | - $fields[] = $id_field; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - // get column names and values |
|
| 1361 | - $row_array = array(); |
|
| 1362 | - $columns = array(); |
|
| 1363 | - $cstm_row_array = array(); |
|
| 1364 | - $cstm_columns = array(); |
|
| 1365 | - $built_columns = false; |
|
| 1366 | - while(($row = $this->fetchByAssoc($result)) != null) |
|
| 1367 | - { |
|
| 1368 | - $values = array(); |
|
| 1369 | - $cstm_values = array(); |
|
| 1370 | - if(!$is_related_query){ |
|
| 1371 | - foreach ($fields as $fieldDef) |
|
| 1372 | - { |
|
| 1373 | - if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue; |
|
| 1374 | - $val = $row[$fieldDef['name']]; |
|
| 1375 | - |
|
| 1376 | - //handle auto increment values here only need to do this on insert not create |
|
| 1377 | - if ($fieldDef['name'] == 'deleted'){ |
|
| 1378 | - $values['deleted'] = $val; |
|
| 1379 | - if(!$built_columns){ |
|
| 1380 | - $columns[] = 'deleted'; |
|
| 1381 | - } |
|
| 1382 | - } |
|
| 1383 | - else |
|
| 1384 | - { |
|
| 1385 | - $type = $fieldDef['type']; |
|
| 1386 | - if(!empty($fieldDef['custom_type'])){ |
|
| 1387 | - $type = $fieldDef['custom_type']; |
|
| 1388 | - } |
|
| 1389 | - // need to do some thing about types of values |
|
| 1390 | - if($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')){ |
|
| 1391 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1392 | - $cstm_values[$fieldDef['name']] = 'null'; |
|
| 1393 | - else |
|
| 1394 | - $values[$fieldDef['name']] = 'null'; |
|
| 1395 | - }else{ |
|
| 1396 | - if(isset($type) && $type=='int') { |
|
| 1397 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1398 | - $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1399 | - else |
|
| 1400 | - $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1401 | - } else { |
|
| 1402 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1403 | - $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1404 | - else |
|
| 1405 | - $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1406 | - } |
|
| 1407 | - } |
|
| 1408 | - if(!$built_columns){ |
|
| 1409 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1410 | - $cstm_columns[] = $fieldDef['name']; |
|
| 1411 | - else |
|
| 1412 | - $columns[] = $fieldDef['name']; |
|
| 1413 | - } |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - } |
|
| 1417 | - } else { |
|
| 1418 | - foreach ($row as $key=>$val) |
|
| 1419 | - { |
|
| 1420 | - if($key != 'orc_row'){ |
|
| 1421 | - $values[$key] = "'$val'"; |
|
| 1422 | - if(!$built_columns){ |
|
| 1423 | - $columns[] = $key; |
|
| 1424 | - } |
|
| 1425 | - } |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - $built_columns = true; |
|
| 1429 | - if(!empty($values)){ |
|
| 1430 | - $row_array[] = $values; |
|
| 1431 | - } |
|
| 1432 | - if(!empty($cstm_values) && !empty($cstm_values['id_c']) && (strlen($cstm_values['id_c']) > 7)){ |
|
| 1433 | - $cstm_row_array[] = $cstm_values; |
|
| 1434 | - } |
|
| 1435 | - } |
|
| 1436 | - |
|
| 1437 | - //if (sizeof ($values) == 0) return ""; // no columns set |
|
| 1438 | - |
|
| 1439 | - // get the entire sql |
|
| 1440 | - $sql .= "(".implode(",", $columns).") "; |
|
| 1441 | - $sql .= "VALUES"; |
|
| 1442 | - for($i = 0; $i < count($row_array); $i++){ |
|
| 1443 | - $sql .= " (".implode(",", $row_array[$i]).")"; |
|
| 1444 | - if($i < (count($row_array) - 1)){ |
|
| 1445 | - $sql .= ", "; |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - //custom |
|
| 1449 | - // get the entire sql |
|
| 1450 | - $custom_sql .= "(".implode(",", $cstm_columns).") "; |
|
| 1451 | - $custom_sql .= "VALUES"; |
|
| 1452 | - |
|
| 1453 | - for($i = 0; $i < count($cstm_row_array); $i++){ |
|
| 1454 | - $custom_sql .= " (".implode(",", $cstm_row_array[$i]).")"; |
|
| 1455 | - if($i < (count($cstm_row_array) - 1)){ |
|
| 1456 | - $custom_sql .= ", "; |
|
| 1457 | - } |
|
| 1458 | - } |
|
| 1459 | - return array('data' => $sql, 'cstm_sql' => $custom_sql, /*'result_count' => $row_count, */ 'total_count' => $rows_found, 'next_offset' => $next_offset); |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * @deprecated |
|
| 1464 | - * Disconnects all instances |
|
| 1465 | - */ |
|
| 1466 | - public function disconnectAll() |
|
| 1467 | - { |
|
| 1468 | - DBManagerFactory::disconnectAll(); |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * This function sets the query threshold limit |
|
| 1473 | - * |
|
| 1474 | - * @param int $limit value of query threshold limit |
|
| 1475 | - */ |
|
| 1476 | - public static function setQueryLimit($limit) |
|
| 1477 | - { |
|
| 1478 | - //reset the queryCount |
|
| 1479 | - self::$queryCount = 0; |
|
| 1480 | - self::$queryLimit = $limit; |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * Returns the static queryCount value |
|
| 1485 | - * |
|
| 1486 | - * @return int value of the queryCount static variable |
|
| 1487 | - */ |
|
| 1488 | - public static function getQueryCount() |
|
| 1489 | - { |
|
| 1490 | - return self::$queryCount; |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - |
|
| 1494 | - /** |
|
| 1495 | - * Resets the queryCount value to 0 |
|
| 1496 | - * |
|
| 1497 | - */ |
|
| 1498 | - public static function resetQueryCount() |
|
| 1499 | - { |
|
| 1500 | - self::$queryCount = 0; |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * This function increments the global $sql_queries variable |
|
| 1505 | - */ |
|
| 1506 | - public function countQuery() |
|
| 1507 | - { |
|
| 1508 | - if (self::$queryLimit != 0 && ++self::$queryCount > self::$queryLimit |
|
| 1509 | - &&(empty($GLOBALS['current_user']) || !is_admin($GLOBALS['current_user']))) { |
|
| 1316 | + public function generateInsertSQL(SugarBean $bean, $select_query, $start, $count = -1, $table, $is_related_query = false) |
|
| 1317 | + { |
|
| 1318 | + $this->log->info('call to DBManager::generateInsertSQL() is deprecated'); |
|
| 1319 | + global $sugar_config; |
|
| 1320 | + |
|
| 1321 | + $rows_found = 0; |
|
| 1322 | + $count_query = $bean->create_list_count_query($select_query); |
|
| 1323 | + if(!empty($count_query)) |
|
| 1324 | + { |
|
| 1325 | + // We have a count query. Run it and get the results. |
|
| 1326 | + $result = $this->query($count_query, true, "Error running count query for $this->object_name List: "); |
|
| 1327 | + $assoc = $this->fetchByAssoc($result); |
|
| 1328 | + if(!empty($assoc['c'])) |
|
| 1329 | + { |
|
| 1330 | + $rows_found = $assoc['c']; |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + if($count == -1){ |
|
| 1334 | + $count = $sugar_config['list_max_entries_per_page']; |
|
| 1335 | + } |
|
| 1336 | + $next_offset = $start + $count; |
|
| 1337 | + |
|
| 1338 | + $result = $this->limitQuery($select_query, $start, $count); |
|
| 1339 | + // get basic insert |
|
| 1340 | + $sql = "INSERT INTO ".$table; |
|
| 1341 | + $custom_sql = "INSERT INTO ".$table."_cstm"; |
|
| 1342 | + |
|
| 1343 | + // get field definitions |
|
| 1344 | + $fields = $bean->getFieldDefinitions(); |
|
| 1345 | + $custom_fields = array(); |
|
| 1346 | + |
|
| 1347 | + if($bean->hasCustomFields()){ |
|
| 1348 | + foreach ($fields as $fieldDef){ |
|
| 1349 | + if($fieldDef['source'] == 'custom_fields'){ |
|
| 1350 | + $custom_fields[$fieldDef['name']] = $fieldDef['name']; |
|
| 1351 | + } |
|
| 1352 | + } |
|
| 1353 | + if(!empty($custom_fields)){ |
|
| 1354 | + $custom_fields['id_c'] = 'id_c'; |
|
| 1355 | + $id_field = array('name' => 'id_c', 'custom_type' => 'id',); |
|
| 1356 | + $fields[] = $id_field; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + // get column names and values |
|
| 1361 | + $row_array = array(); |
|
| 1362 | + $columns = array(); |
|
| 1363 | + $cstm_row_array = array(); |
|
| 1364 | + $cstm_columns = array(); |
|
| 1365 | + $built_columns = false; |
|
| 1366 | + while(($row = $this->fetchByAssoc($result)) != null) |
|
| 1367 | + { |
|
| 1368 | + $values = array(); |
|
| 1369 | + $cstm_values = array(); |
|
| 1370 | + if(!$is_related_query){ |
|
| 1371 | + foreach ($fields as $fieldDef) |
|
| 1372 | + { |
|
| 1373 | + if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue; |
|
| 1374 | + $val = $row[$fieldDef['name']]; |
|
| 1375 | + |
|
| 1376 | + //handle auto increment values here only need to do this on insert not create |
|
| 1377 | + if ($fieldDef['name'] == 'deleted'){ |
|
| 1378 | + $values['deleted'] = $val; |
|
| 1379 | + if(!$built_columns){ |
|
| 1380 | + $columns[] = 'deleted'; |
|
| 1381 | + } |
|
| 1382 | + } |
|
| 1383 | + else |
|
| 1384 | + { |
|
| 1385 | + $type = $fieldDef['type']; |
|
| 1386 | + if(!empty($fieldDef['custom_type'])){ |
|
| 1387 | + $type = $fieldDef['custom_type']; |
|
| 1388 | + } |
|
| 1389 | + // need to do some thing about types of values |
|
| 1390 | + if($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')){ |
|
| 1391 | + if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1392 | + $cstm_values[$fieldDef['name']] = 'null'; |
|
| 1393 | + else |
|
| 1394 | + $values[$fieldDef['name']] = 'null'; |
|
| 1395 | + }else{ |
|
| 1396 | + if(isset($type) && $type=='int') { |
|
| 1397 | + if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1398 | + $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1399 | + else |
|
| 1400 | + $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1401 | + } else { |
|
| 1402 | + if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1403 | + $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1404 | + else |
|
| 1405 | + $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1406 | + } |
|
| 1407 | + } |
|
| 1408 | + if(!$built_columns){ |
|
| 1409 | + if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1410 | + $cstm_columns[] = $fieldDef['name']; |
|
| 1411 | + else |
|
| 1412 | + $columns[] = $fieldDef['name']; |
|
| 1413 | + } |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + } |
|
| 1417 | + } else { |
|
| 1418 | + foreach ($row as $key=>$val) |
|
| 1419 | + { |
|
| 1420 | + if($key != 'orc_row'){ |
|
| 1421 | + $values[$key] = "'$val'"; |
|
| 1422 | + if(!$built_columns){ |
|
| 1423 | + $columns[] = $key; |
|
| 1424 | + } |
|
| 1425 | + } |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + $built_columns = true; |
|
| 1429 | + if(!empty($values)){ |
|
| 1430 | + $row_array[] = $values; |
|
| 1431 | + } |
|
| 1432 | + if(!empty($cstm_values) && !empty($cstm_values['id_c']) && (strlen($cstm_values['id_c']) > 7)){ |
|
| 1433 | + $cstm_row_array[] = $cstm_values; |
|
| 1434 | + } |
|
| 1435 | + } |
|
| 1436 | + |
|
| 1437 | + //if (sizeof ($values) == 0) return ""; // no columns set |
|
| 1438 | + |
|
| 1439 | + // get the entire sql |
|
| 1440 | + $sql .= "(".implode(",", $columns).") "; |
|
| 1441 | + $sql .= "VALUES"; |
|
| 1442 | + for($i = 0; $i < count($row_array); $i++){ |
|
| 1443 | + $sql .= " (".implode(",", $row_array[$i]).")"; |
|
| 1444 | + if($i < (count($row_array) - 1)){ |
|
| 1445 | + $sql .= ", "; |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + //custom |
|
| 1449 | + // get the entire sql |
|
| 1450 | + $custom_sql .= "(".implode(",", $cstm_columns).") "; |
|
| 1451 | + $custom_sql .= "VALUES"; |
|
| 1452 | + |
|
| 1453 | + for($i = 0; $i < count($cstm_row_array); $i++){ |
|
| 1454 | + $custom_sql .= " (".implode(",", $cstm_row_array[$i]).")"; |
|
| 1455 | + if($i < (count($cstm_row_array) - 1)){ |
|
| 1456 | + $custom_sql .= ", "; |
|
| 1457 | + } |
|
| 1458 | + } |
|
| 1459 | + return array('data' => $sql, 'cstm_sql' => $custom_sql, /*'result_count' => $row_count, */ 'total_count' => $rows_found, 'next_offset' => $next_offset); |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * @deprecated |
|
| 1464 | + * Disconnects all instances |
|
| 1465 | + */ |
|
| 1466 | + public function disconnectAll() |
|
| 1467 | + { |
|
| 1468 | + DBManagerFactory::disconnectAll(); |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * This function sets the query threshold limit |
|
| 1473 | + * |
|
| 1474 | + * @param int $limit value of query threshold limit |
|
| 1475 | + */ |
|
| 1476 | + public static function setQueryLimit($limit) |
|
| 1477 | + { |
|
| 1478 | + //reset the queryCount |
|
| 1479 | + self::$queryCount = 0; |
|
| 1480 | + self::$queryLimit = $limit; |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * Returns the static queryCount value |
|
| 1485 | + * |
|
| 1486 | + * @return int value of the queryCount static variable |
|
| 1487 | + */ |
|
| 1488 | + public static function getQueryCount() |
|
| 1489 | + { |
|
| 1490 | + return self::$queryCount; |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + |
|
| 1494 | + /** |
|
| 1495 | + * Resets the queryCount value to 0 |
|
| 1496 | + * |
|
| 1497 | + */ |
|
| 1498 | + public static function resetQueryCount() |
|
| 1499 | + { |
|
| 1500 | + self::$queryCount = 0; |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * This function increments the global $sql_queries variable |
|
| 1505 | + */ |
|
| 1506 | + public function countQuery() |
|
| 1507 | + { |
|
| 1508 | + if (self::$queryLimit != 0 && ++self::$queryCount > self::$queryLimit |
|
| 1509 | + &&(empty($GLOBALS['current_user']) || !is_admin($GLOBALS['current_user']))) { |
|
| 1510 | 1510 | require_once('include/resource/ResourceManager.php'); |
| 1511 | 1511 | $resourceManager = ResourceManager::getInstance(); |
| 1512 | 1512 | $resourceManager->notifyObservers('ERR_QUERY_LIMIT'); |
| 1513 | - } |
|
| 1514 | - } |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + |
|
| 1516 | + /** |
|
| 1517 | + * Pre-process string for quoting |
|
| 1518 | + * @internal |
|
| 1519 | + * @param string $string |
|
| 1520 | + * @return string |
|
| 1521 | + */ |
|
| 1522 | + protected function quoteInternal($string) |
|
| 1523 | + { |
|
| 1524 | + return from_html($string); |
|
| 1525 | + } |
|
| 1515 | 1526 | |
| 1516 | - /** |
|
| 1517 | - * Pre-process string for quoting |
|
| 1518 | - * @internal |
|
| 1519 | - * @param string $string |
|
| 1527 | + /** |
|
| 1528 | + * Return string properly quoted with '' |
|
| 1529 | + * @param string $string |
|
| 1520 | 1530 | * @return string |
| 1521 | 1531 | */ |
| 1522 | - protected function quoteInternal($string) |
|
| 1523 | - { |
|
| 1524 | - return from_html($string); |
|
| 1525 | - } |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * Return string properly quoted with '' |
|
| 1529 | - * @param string $string |
|
| 1530 | - * @return string |
|
| 1531 | - */ |
|
| 1532 | - public function quoted($string) |
|
| 1533 | - { |
|
| 1534 | - return "'".$this->quote($string)."'"; |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - /** |
|
| 1532 | + public function quoted($string) |
|
| 1533 | + { |
|
| 1534 | + return "'".$this->quote($string)."'"; |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + /** |
|
| 1538 | 1538 | * Quote value according to type |
| 1539 | 1539 | * Numerics aren't quoted |
| 1540 | 1540 | * Dates are converted and quoted |
@@ -1544,13 +1544,13 @@ discard block |
||
| 1544 | 1544 | * @return string Quoted value |
| 1545 | 1545 | */ |
| 1546 | 1546 | public function quoteType($type, $value) |
| 1547 | - { |
|
| 1548 | - if($type == 'date') { |
|
| 1549 | - return $this->convert($this->quoted($value), "date"); |
|
| 1550 | - } |
|
| 1551 | - if($type == 'time') { |
|
| 1552 | - return $this->convert($this->quoted($value), "time"); |
|
| 1553 | - } |
|
| 1547 | + { |
|
| 1548 | + if($type == 'date') { |
|
| 1549 | + return $this->convert($this->quoted($value), "date"); |
|
| 1550 | + } |
|
| 1551 | + if($type == 'time') { |
|
| 1552 | + return $this->convert($this->quoted($value), "time"); |
|
| 1553 | + } |
|
| 1554 | 1554 | if(isset($this->type_class[$type]) && $this->type_class[$type] == "date") { |
| 1555 | 1555 | return $this->convert($this->quoted($value), "datetime"); |
| 1556 | 1556 | } |
@@ -1559,7 +1559,7 @@ discard block |
||
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | return $this->quoted($value); |
| 1562 | - } |
|
| 1562 | + } |
|
| 1563 | 1563 | |
| 1564 | 1564 | /** |
| 1565 | 1565 | * Quote the strings of the passed in array |
@@ -1569,177 +1569,177 @@ discard block |
||
| 1569 | 1569 | * @param array $array |
| 1570 | 1570 | * @return array Quoted strings |
| 1571 | 1571 | */ |
| 1572 | - public function arrayQuote(array &$array) |
|
| 1573 | - { |
|
| 1574 | - foreach($array as &$val) { |
|
| 1575 | - $val = $this->quote($val); |
|
| 1576 | - } |
|
| 1577 | - return $array; |
|
| 1578 | - } |
|
| 1572 | + public function arrayQuote(array &$array) |
|
| 1573 | + { |
|
| 1574 | + foreach($array as &$val) { |
|
| 1575 | + $val = $this->quote($val); |
|
| 1576 | + } |
|
| 1577 | + return $array; |
|
| 1578 | + } |
|
| 1579 | 1579 | |
| 1580 | 1580 | /** |
| 1581 | 1581 | * Frees out previous results |
| 1582 | 1582 | * |
| 1583 | 1583 | * @param resource|bool $result optional, pass if you want to free a single result instead of all results |
| 1584 | 1584 | */ |
| 1585 | - protected function freeResult($result = false) |
|
| 1586 | - { |
|
| 1587 | - if($result) { |
|
| 1588 | - $this->freeDbResult($result); |
|
| 1589 | - } |
|
| 1590 | - if($this->lastResult) { |
|
| 1591 | - $this->freeDbResult($this->lastResult); |
|
| 1592 | - $this->lastResult = null; |
|
| 1593 | - } |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * @abstract |
|
| 1598 | - * Check if query has LIMIT clause |
|
| 1599 | - * Relevant for now only for Mysql |
|
| 1600 | - * @param string $sql |
|
| 1601 | - * @return bool |
|
| 1602 | - */ |
|
| 1603 | - protected function hasLimit($sql) |
|
| 1604 | - { |
|
| 1605 | - return false; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * Runs a query and returns a single row containing single value |
|
| 1610 | - * |
|
| 1611 | - * @param string $sql SQL Statement to execute |
|
| 1612 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 1613 | - * @param string $msg Message to log if error occurs |
|
| 1614 | - * @return array single value from the query |
|
| 1615 | - */ |
|
| 1616 | - public function getOne($sql, $dieOnError = false, $msg = '') |
|
| 1617 | - { |
|
| 1618 | - $this->log->info("Get One: |$sql|"); |
|
| 1619 | - if(!$this->hasLimit($sql)) { |
|
| 1620 | - $queryresult = $this->limitQuery($sql, 0, 1, $dieOnError, $msg); |
|
| 1621 | - } else { |
|
| 1622 | - // support old code that passes LIMIT to sql |
|
| 1623 | - // works only for mysql, so do not rely on this |
|
| 1624 | - $queryresult = $this->query($sql, $dieOnError, $msg); |
|
| 1625 | - } |
|
| 1626 | - $this->checkError($msg.' Get One Failed:' . $sql, $dieOnError); |
|
| 1627 | - if (!$queryresult) return false; |
|
| 1628 | - $row = $this->fetchByAssoc($queryresult); |
|
| 1629 | - if(!empty($row)) { |
|
| 1630 | - return array_shift($row); |
|
| 1631 | - } |
|
| 1632 | - return false; |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * Runs a query and returns a single row |
|
| 1637 | - * |
|
| 1638 | - * @param string $sql SQL Statement to execute |
|
| 1639 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 1640 | - * @param string $msg Message to log if error occurs |
|
| 1641 | - * @param bool $suppress Message to log if error occurs |
|
| 1642 | - * @return array single row from the query |
|
| 1643 | - */ |
|
| 1644 | - public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
| 1645 | - { |
|
| 1646 | - $this->log->info("Fetch One: |$sql|"); |
|
| 1647 | - $this->checkConnection(); |
|
| 1648 | - $queryresult = $this->query($sql, $dieOnError, $msg); |
|
| 1649 | - $this->checkError($msg.' Fetch One Failed:' . $sql, $dieOnError); |
|
| 1650 | - |
|
| 1651 | - if (!$queryresult) return false; |
|
| 1652 | - |
|
| 1653 | - $row = $this->fetchByAssoc($queryresult); |
|
| 1654 | - if ( !$row ) return false; |
|
| 1655 | - |
|
| 1656 | - $this->freeResult($queryresult); |
|
| 1657 | - return $row; |
|
| 1658 | - } |
|
| 1585 | + protected function freeResult($result = false) |
|
| 1586 | + { |
|
| 1587 | + if($result) { |
|
| 1588 | + $this->freeDbResult($result); |
|
| 1589 | + } |
|
| 1590 | + if($this->lastResult) { |
|
| 1591 | + $this->freeDbResult($this->lastResult); |
|
| 1592 | + $this->lastResult = null; |
|
| 1593 | + } |
|
| 1594 | + } |
|
| 1659 | 1595 | |
| 1660 | 1596 | /** |
| 1661 | - * Returns the number of rows affected by the last query |
|
| 1662 | 1597 | * @abstract |
| 1663 | - * See also affected_rows capability, will return 0 unless the DB supports it |
|
| 1664 | - * @param resource $result query result resource |
|
| 1665 | - * @return int |
|
| 1598 | + * Check if query has LIMIT clause |
|
| 1599 | + * Relevant for now only for Mysql |
|
| 1600 | + * @param string $sql |
|
| 1601 | + * @return bool |
|
| 1666 | 1602 | */ |
| 1667 | - public function getAffectedRowCount($result) |
|
| 1668 | - { |
|
| 1669 | - return 0; |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - /** |
|
| 1673 | - * Returns the number of rows returned by the result |
|
| 1674 | - * |
|
| 1675 | - * This function can't be reliably implemented on most DB, do not use it. |
|
| 1676 | - * @abstract |
|
| 1677 | - * @deprecated |
|
| 1678 | - * @param resource $result |
|
| 1679 | - * @return int |
|
| 1680 | - */ |
|
| 1681 | - public function getRowCount($result) |
|
| 1682 | - { |
|
| 1683 | - return 0; |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - /** |
|
| 1687 | - * Get table description |
|
| 1688 | - * @param string $tablename |
|
| 1603 | + protected function hasLimit($sql) |
|
| 1604 | + { |
|
| 1605 | + return false; |
|
| 1606 | + } |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * Runs a query and returns a single row containing single value |
|
| 1610 | + * |
|
| 1611 | + * @param string $sql SQL Statement to execute |
|
| 1612 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 1613 | + * @param string $msg Message to log if error occurs |
|
| 1614 | + * @return array single value from the query |
|
| 1615 | + */ |
|
| 1616 | + public function getOne($sql, $dieOnError = false, $msg = '') |
|
| 1617 | + { |
|
| 1618 | + $this->log->info("Get One: |$sql|"); |
|
| 1619 | + if(!$this->hasLimit($sql)) { |
|
| 1620 | + $queryresult = $this->limitQuery($sql, 0, 1, $dieOnError, $msg); |
|
| 1621 | + } else { |
|
| 1622 | + // support old code that passes LIMIT to sql |
|
| 1623 | + // works only for mysql, so do not rely on this |
|
| 1624 | + $queryresult = $this->query($sql, $dieOnError, $msg); |
|
| 1625 | + } |
|
| 1626 | + $this->checkError($msg.' Get One Failed:' . $sql, $dieOnError); |
|
| 1627 | + if (!$queryresult) return false; |
|
| 1628 | + $row = $this->fetchByAssoc($queryresult); |
|
| 1629 | + if(!empty($row)) { |
|
| 1630 | + return array_shift($row); |
|
| 1631 | + } |
|
| 1632 | + return false; |
|
| 1633 | + } |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * Runs a query and returns a single row |
|
| 1637 | + * |
|
| 1638 | + * @param string $sql SQL Statement to execute |
|
| 1639 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 1640 | + * @param string $msg Message to log if error occurs |
|
| 1641 | + * @param bool $suppress Message to log if error occurs |
|
| 1642 | + * @return array single row from the query |
|
| 1643 | + */ |
|
| 1644 | + public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
| 1645 | + { |
|
| 1646 | + $this->log->info("Fetch One: |$sql|"); |
|
| 1647 | + $this->checkConnection(); |
|
| 1648 | + $queryresult = $this->query($sql, $dieOnError, $msg); |
|
| 1649 | + $this->checkError($msg.' Fetch One Failed:' . $sql, $dieOnError); |
|
| 1650 | + |
|
| 1651 | + if (!$queryresult) return false; |
|
| 1652 | + |
|
| 1653 | + $row = $this->fetchByAssoc($queryresult); |
|
| 1654 | + if ( !$row ) return false; |
|
| 1655 | + |
|
| 1656 | + $this->freeResult($queryresult); |
|
| 1657 | + return $row; |
|
| 1658 | + } |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * Returns the number of rows affected by the last query |
|
| 1662 | + * @abstract |
|
| 1663 | + * See also affected_rows capability, will return 0 unless the DB supports it |
|
| 1664 | + * @param resource $result query result resource |
|
| 1665 | + * @return int |
|
| 1666 | + */ |
|
| 1667 | + public function getAffectedRowCount($result) |
|
| 1668 | + { |
|
| 1669 | + return 0; |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + /** |
|
| 1673 | + * Returns the number of rows returned by the result |
|
| 1674 | + * |
|
| 1675 | + * This function can't be reliably implemented on most DB, do not use it. |
|
| 1676 | + * @abstract |
|
| 1677 | + * @deprecated |
|
| 1678 | + * @param resource $result |
|
| 1679 | + * @return int |
|
| 1680 | + */ |
|
| 1681 | + public function getRowCount($result) |
|
| 1682 | + { |
|
| 1683 | + return 0; |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + /** |
|
| 1687 | + * Get table description |
|
| 1688 | + * @param string $tablename |
|
| 1689 | 1689 | * @param bool $reload true means load from DB, false allows using cache |
| 1690 | 1690 | * @return array Vardef-format table description |
| 1691 | 1691 | * |
| 1692 | 1692 | */ |
| 1693 | - public function getTableDescription($tablename, $reload = false) |
|
| 1694 | - { |
|
| 1695 | - if($reload || empty(self::$table_descriptions[$tablename])) { |
|
| 1696 | - self::$table_descriptions[$tablename] = $this->get_columns($tablename); |
|
| 1697 | - } |
|
| 1698 | - return self::$table_descriptions[$tablename]; |
|
| 1699 | - } |
|
| 1700 | - |
|
| 1701 | - /** |
|
| 1702 | - * Returns the field description for a given field in table |
|
| 1703 | - * |
|
| 1704 | - * @param string $name |
|
| 1705 | - * @param string $tablename |
|
| 1706 | - * @return array |
|
| 1707 | - */ |
|
| 1708 | - protected function describeField($name, $tablename) |
|
| 1709 | - { |
|
| 1710 | - $table = $this->getTableDescription($tablename); |
|
| 1711 | - if(!empty($table) && isset($table[$name])) |
|
| 1712 | - return $table[$name]; |
|
| 1713 | - |
|
| 1714 | - $table = $this->getTableDescription($tablename, true); |
|
| 1715 | - |
|
| 1716 | - if(isset($table[$name])) |
|
| 1717 | - return $table[$name]; |
|
| 1718 | - |
|
| 1719 | - return array(); |
|
| 1720 | - } |
|
| 1721 | - |
|
| 1722 | - /** |
|
| 1723 | - * Returns the index description for a given index in table |
|
| 1724 | - * |
|
| 1725 | - * @param string $name |
|
| 1726 | - * @param string $tablename |
|
| 1727 | - * @return array |
|
| 1728 | - */ |
|
| 1729 | - protected function describeIndex($name, $tablename) |
|
| 1730 | - { |
|
| 1731 | - if(isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename][$name])){ |
|
| 1732 | - return self::$index_descriptions[$tablename][$name]; |
|
| 1733 | - } |
|
| 1734 | - |
|
| 1735 | - self::$index_descriptions[$tablename] = $this->get_indices($tablename); |
|
| 1736 | - |
|
| 1737 | - if(isset(self::$index_descriptions[$tablename][$name])){ |
|
| 1738 | - return self::$index_descriptions[$tablename][$name]; |
|
| 1739 | - } |
|
| 1740 | - |
|
| 1741 | - return array(); |
|
| 1742 | - } |
|
| 1693 | + public function getTableDescription($tablename, $reload = false) |
|
| 1694 | + { |
|
| 1695 | + if($reload || empty(self::$table_descriptions[$tablename])) { |
|
| 1696 | + self::$table_descriptions[$tablename] = $this->get_columns($tablename); |
|
| 1697 | + } |
|
| 1698 | + return self::$table_descriptions[$tablename]; |
|
| 1699 | + } |
|
| 1700 | + |
|
| 1701 | + /** |
|
| 1702 | + * Returns the field description for a given field in table |
|
| 1703 | + * |
|
| 1704 | + * @param string $name |
|
| 1705 | + * @param string $tablename |
|
| 1706 | + * @return array |
|
| 1707 | + */ |
|
| 1708 | + protected function describeField($name, $tablename) |
|
| 1709 | + { |
|
| 1710 | + $table = $this->getTableDescription($tablename); |
|
| 1711 | + if(!empty($table) && isset($table[$name])) |
|
| 1712 | + return $table[$name]; |
|
| 1713 | + |
|
| 1714 | + $table = $this->getTableDescription($tablename, true); |
|
| 1715 | + |
|
| 1716 | + if(isset($table[$name])) |
|
| 1717 | + return $table[$name]; |
|
| 1718 | + |
|
| 1719 | + return array(); |
|
| 1720 | + } |
|
| 1721 | + |
|
| 1722 | + /** |
|
| 1723 | + * Returns the index description for a given index in table |
|
| 1724 | + * |
|
| 1725 | + * @param string $name |
|
| 1726 | + * @param string $tablename |
|
| 1727 | + * @return array |
|
| 1728 | + */ |
|
| 1729 | + protected function describeIndex($name, $tablename) |
|
| 1730 | + { |
|
| 1731 | + if(isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename][$name])){ |
|
| 1732 | + return self::$index_descriptions[$tablename][$name]; |
|
| 1733 | + } |
|
| 1734 | + |
|
| 1735 | + self::$index_descriptions[$tablename] = $this->get_indices($tablename); |
|
| 1736 | + |
|
| 1737 | + if(isset(self::$index_descriptions[$tablename][$name])){ |
|
| 1738 | + return self::$index_descriptions[$tablename][$name]; |
|
| 1739 | + } |
|
| 1740 | + |
|
| 1741 | + return array(); |
|
| 1742 | + } |
|
| 1743 | 1743 | |
| 1744 | 1744 | /** |
| 1745 | 1745 | * Truncates a string to a given length |
@@ -1749,14 +1749,14 @@ discard block |
||
| 1749 | 1749 | * @return string |
| 1750 | 1750 | * |
| 1751 | 1751 | */ |
| 1752 | - public function truncate($string, $len) |
|
| 1753 | - { |
|
| 1754 | - if ( is_numeric($len) && $len > 0) |
|
| 1755 | - { |
|
| 1756 | - $string = mb_substr($string,0,(int) $len, "UTF-8"); |
|
| 1757 | - } |
|
| 1758 | - return $string; |
|
| 1759 | - } |
|
| 1752 | + public function truncate($string, $len) |
|
| 1753 | + { |
|
| 1754 | + if ( is_numeric($len) && $len > 0) |
|
| 1755 | + { |
|
| 1756 | + $string = mb_substr($string,0,(int) $len, "UTF-8"); |
|
| 1757 | + } |
|
| 1758 | + return $string; |
|
| 1759 | + } |
|
| 1760 | 1760 | |
| 1761 | 1761 | /** |
| 1762 | 1762 | * Returns the database string needed for concatinating multiple database strings together |
@@ -1766,121 +1766,121 @@ discard block |
||
| 1766 | 1766 | * @param string $space Separator between strings, default is single space |
| 1767 | 1767 | * @return string |
| 1768 | 1768 | */ |
| 1769 | - public function concat($table, array $fields, $space = ' ') |
|
| 1770 | - { |
|
| 1771 | - if(empty($fields)) return ''; |
|
| 1772 | - $elems = array(); |
|
| 1773 | - $space = $this->quoted($space); |
|
| 1774 | - foreach ( $fields as $field ) { |
|
| 1775 | - if(!empty($elems)) $elems[] = $space; |
|
| 1776 | - $elems[] = $this->convert("$table.$field", 'IFNULL', array("''")); |
|
| 1777 | - } |
|
| 1778 | - $first = array_shift($elems); |
|
| 1779 | - return "LTRIM(RTRIM(".$this->convert($first, 'CONCAT', $elems)."))"; |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - /** |
|
| 1783 | - * Given a sql stmt attempt to parse it into the sql and the tokens. Then return the index of this prepared statement |
|
| 1784 | - * Tokens can come in the following forms: |
|
| 1785 | - * ? - a scalar which will be quoted |
|
| 1786 | - * ! - a literal which will not be quoted |
|
| 1787 | - * & - binary data to read from a file |
|
| 1788 | - * |
|
| 1789 | - * @param string $sql The sql to parse |
|
| 1790 | - * @return int index of the prepared statement to be used with execute |
|
| 1791 | - */ |
|
| 1792 | - public function prepareQuery($sql) |
|
| 1793 | - { |
|
| 1794 | - //parse out the tokens |
|
| 1795 | - $tokens = preg_split('/((?<!\\\)[&?!])/', $sql, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1796 | - |
|
| 1797 | - //maintain a count of the actual tokens for quick reference in execute |
|
| 1798 | - $count = 0; |
|
| 1799 | - |
|
| 1800 | - $sqlStr = ''; |
|
| 1801 | - foreach ($tokens as $key => $val) { |
|
| 1802 | - switch ($val) { |
|
| 1803 | - case '?' : |
|
| 1804 | - case '!' : |
|
| 1805 | - case '&' : |
|
| 1806 | - $count++; |
|
| 1807 | - $sqlStr .= '?'; |
|
| 1808 | - break; |
|
| 1809 | - |
|
| 1810 | - default : |
|
| 1811 | - //escape any special characters |
|
| 1812 | - $tokens[$key] = preg_replace('/\\\([&?!])/', "\\1", $val); |
|
| 1813 | - $sqlStr .= $tokens[$key]; |
|
| 1814 | - break; |
|
| 1815 | - } // switch |
|
| 1816 | - } // foreach |
|
| 1817 | - |
|
| 1818 | - $this->preparedTokens[] = array('tokens' => $tokens, 'tokenCount' => $count, 'sqlString' => $sqlStr); |
|
| 1819 | - end($this->preparedTokens); |
|
| 1820 | - return key($this->preparedTokens); |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * Takes a prepared stmt index and the data to replace and creates the query and runs it. |
|
| 1825 | - * |
|
| 1826 | - * @param int $stmt The index of the prepared statement from preparedTokens |
|
| 1827 | - * @param array $data The array of data to replace the tokens with. |
|
| 1828 | - * @return resource result set or false on error |
|
| 1829 | - */ |
|
| 1830 | - public function executePreparedQuery($stmt, $data = array()) |
|
| 1831 | - { |
|
| 1832 | - if(!empty($this->preparedTokens[$stmt])){ |
|
| 1833 | - if(!is_array($data)){ |
|
| 1834 | - $data = array($data); |
|
| 1835 | - } |
|
| 1836 | - |
|
| 1837 | - $pTokens = $this->preparedTokens[$stmt]; |
|
| 1838 | - |
|
| 1839 | - //ensure that the number of data elements matches the number of replacement tokens |
|
| 1840 | - //we found in prepare(). |
|
| 1841 | - if(count($data) != $pTokens['tokenCount']){ |
|
| 1842 | - //error the data count did not match the token count |
|
| 1843 | - return false; |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - $query = ''; |
|
| 1847 | - $dataIndex = 0; |
|
| 1848 | - $tokens = $pTokens['tokens']; |
|
| 1849 | - foreach ($tokens as $val) { |
|
| 1850 | - switch ($val) { |
|
| 1851 | - case '?': |
|
| 1852 | - $query .= $this->quote($data[$dataIndex++]); |
|
| 1853 | - break; |
|
| 1854 | - case '&': |
|
| 1855 | - $filename = $data[$dataIndex++]; |
|
| 1856 | - $query .= file_get_contents($filename); |
|
| 1857 | - break; |
|
| 1858 | - case '!': |
|
| 1859 | - $query .= $data[$dataIndex++]; |
|
| 1860 | - break; |
|
| 1861 | - default: |
|
| 1862 | - $query .= $val; |
|
| 1863 | - break; |
|
| 1864 | - }//switch |
|
| 1865 | - }//foreach |
|
| 1866 | - return $this->query($query); |
|
| 1867 | - }else{ |
|
| 1868 | - return false; |
|
| 1869 | - } |
|
| 1870 | - } |
|
| 1871 | - |
|
| 1872 | - /** |
|
| 1873 | - * Run both prepare and execute without the client having to run both individually. |
|
| 1874 | - * |
|
| 1875 | - * @param string $sql The sql to parse |
|
| 1876 | - * @param array $data The array of data to replace the tokens with. |
|
| 1877 | - * @return resource result set or false on error |
|
| 1878 | - */ |
|
| 1879 | - public function pQuery($sql, $data = array()) |
|
| 1880 | - { |
|
| 1881 | - $stmt = $this->prepareQuery($sql); |
|
| 1882 | - return $this->executePreparedQuery($stmt, $data); |
|
| 1883 | - } |
|
| 1769 | + public function concat($table, array $fields, $space = ' ') |
|
| 1770 | + { |
|
| 1771 | + if(empty($fields)) return ''; |
|
| 1772 | + $elems = array(); |
|
| 1773 | + $space = $this->quoted($space); |
|
| 1774 | + foreach ( $fields as $field ) { |
|
| 1775 | + if(!empty($elems)) $elems[] = $space; |
|
| 1776 | + $elems[] = $this->convert("$table.$field", 'IFNULL', array("''")); |
|
| 1777 | + } |
|
| 1778 | + $first = array_shift($elems); |
|
| 1779 | + return "LTRIM(RTRIM(".$this->convert($first, 'CONCAT', $elems)."))"; |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + /** |
|
| 1783 | + * Given a sql stmt attempt to parse it into the sql and the tokens. Then return the index of this prepared statement |
|
| 1784 | + * Tokens can come in the following forms: |
|
| 1785 | + * ? - a scalar which will be quoted |
|
| 1786 | + * ! - a literal which will not be quoted |
|
| 1787 | + * & - binary data to read from a file |
|
| 1788 | + * |
|
| 1789 | + * @param string $sql The sql to parse |
|
| 1790 | + * @return int index of the prepared statement to be used with execute |
|
| 1791 | + */ |
|
| 1792 | + public function prepareQuery($sql) |
|
| 1793 | + { |
|
| 1794 | + //parse out the tokens |
|
| 1795 | + $tokens = preg_split('/((?<!\\\)[&?!])/', $sql, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 1796 | + |
|
| 1797 | + //maintain a count of the actual tokens for quick reference in execute |
|
| 1798 | + $count = 0; |
|
| 1799 | + |
|
| 1800 | + $sqlStr = ''; |
|
| 1801 | + foreach ($tokens as $key => $val) { |
|
| 1802 | + switch ($val) { |
|
| 1803 | + case '?' : |
|
| 1804 | + case '!' : |
|
| 1805 | + case '&' : |
|
| 1806 | + $count++; |
|
| 1807 | + $sqlStr .= '?'; |
|
| 1808 | + break; |
|
| 1809 | + |
|
| 1810 | + default : |
|
| 1811 | + //escape any special characters |
|
| 1812 | + $tokens[$key] = preg_replace('/\\\([&?!])/', "\\1", $val); |
|
| 1813 | + $sqlStr .= $tokens[$key]; |
|
| 1814 | + break; |
|
| 1815 | + } // switch |
|
| 1816 | + } // foreach |
|
| 1817 | + |
|
| 1818 | + $this->preparedTokens[] = array('tokens' => $tokens, 'tokenCount' => $count, 'sqlString' => $sqlStr); |
|
| 1819 | + end($this->preparedTokens); |
|
| 1820 | + return key($this->preparedTokens); |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * Takes a prepared stmt index and the data to replace and creates the query and runs it. |
|
| 1825 | + * |
|
| 1826 | + * @param int $stmt The index of the prepared statement from preparedTokens |
|
| 1827 | + * @param array $data The array of data to replace the tokens with. |
|
| 1828 | + * @return resource result set or false on error |
|
| 1829 | + */ |
|
| 1830 | + public function executePreparedQuery($stmt, $data = array()) |
|
| 1831 | + { |
|
| 1832 | + if(!empty($this->preparedTokens[$stmt])){ |
|
| 1833 | + if(!is_array($data)){ |
|
| 1834 | + $data = array($data); |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + $pTokens = $this->preparedTokens[$stmt]; |
|
| 1838 | + |
|
| 1839 | + //ensure that the number of data elements matches the number of replacement tokens |
|
| 1840 | + //we found in prepare(). |
|
| 1841 | + if(count($data) != $pTokens['tokenCount']){ |
|
| 1842 | + //error the data count did not match the token count |
|
| 1843 | + return false; |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + $query = ''; |
|
| 1847 | + $dataIndex = 0; |
|
| 1848 | + $tokens = $pTokens['tokens']; |
|
| 1849 | + foreach ($tokens as $val) { |
|
| 1850 | + switch ($val) { |
|
| 1851 | + case '?': |
|
| 1852 | + $query .= $this->quote($data[$dataIndex++]); |
|
| 1853 | + break; |
|
| 1854 | + case '&': |
|
| 1855 | + $filename = $data[$dataIndex++]; |
|
| 1856 | + $query .= file_get_contents($filename); |
|
| 1857 | + break; |
|
| 1858 | + case '!': |
|
| 1859 | + $query .= $data[$dataIndex++]; |
|
| 1860 | + break; |
|
| 1861 | + default: |
|
| 1862 | + $query .= $val; |
|
| 1863 | + break; |
|
| 1864 | + }//switch |
|
| 1865 | + }//foreach |
|
| 1866 | + return $this->query($query); |
|
| 1867 | + }else{ |
|
| 1868 | + return false; |
|
| 1869 | + } |
|
| 1870 | + } |
|
| 1871 | + |
|
| 1872 | + /** |
|
| 1873 | + * Run both prepare and execute without the client having to run both individually. |
|
| 1874 | + * |
|
| 1875 | + * @param string $sql The sql to parse |
|
| 1876 | + * @param array $data The array of data to replace the tokens with. |
|
| 1877 | + * @return resource result set or false on error |
|
| 1878 | + */ |
|
| 1879 | + public function pQuery($sql, $data = array()) |
|
| 1880 | + { |
|
| 1881 | + $stmt = $this->prepareQuery($sql); |
|
| 1882 | + return $this->executePreparedQuery($stmt, $data); |
|
| 1883 | + } |
|
| 1884 | 1884 | |
| 1885 | 1885 | /********************** SQL FUNCTIONS ****************************/ |
| 1886 | 1886 | /** |
@@ -1890,933 +1890,933 @@ discard block |
||
| 1890 | 1890 | * @param SugarBean $bean SugarBean instance |
| 1891 | 1891 | * @return string SQL Create Table statement |
| 1892 | 1892 | */ |
| 1893 | - public function createTableSQL(SugarBean $bean) |
|
| 1894 | - { |
|
| 1895 | - $tablename = $bean->getTableName(); |
|
| 1896 | - $fieldDefs = $bean->getFieldDefinitions(); |
|
| 1897 | - $indices = $bean->getIndices(); |
|
| 1898 | - return $this->createTableSQLParams($tablename, $fieldDefs, $indices); |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - /** |
|
| 1902 | - * Generates SQL for insert statement. |
|
| 1903 | - * |
|
| 1904 | - * @param SugarBean $bean SugarBean instance |
|
| 1905 | - * @return string SQL Create Table statement |
|
| 1906 | - */ |
|
| 1907 | - public function insertSQL(SugarBean $bean) |
|
| 1908 | - { |
|
| 1909 | - // get column names and values |
|
| 1910 | - $sql = $this->insertParams($bean->getTableName(), $bean->getFieldDefinitions(), get_object_vars($bean), |
|
| 1911 | - isset($bean->field_name_map)?$bean->field_name_map:null, false); |
|
| 1912 | - return $sql; |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - /** |
|
| 1916 | - * Generates SQL for update statement. |
|
| 1917 | - * |
|
| 1918 | - * @param SugarBean $bean SugarBean instance |
|
| 1919 | - * @param array $where Optional, where conditions in an array |
|
| 1920 | - * @return string SQL Create Table statement |
|
| 1921 | - */ |
|
| 1922 | - public function updateSQL(SugarBean $bean, array $where = array()) |
|
| 1923 | - { |
|
| 1924 | - $primaryField = $bean->getPrimaryFieldDefinition(); |
|
| 1925 | - $columns = array(); |
|
| 1893 | + public function createTableSQL(SugarBean $bean) |
|
| 1894 | + { |
|
| 1895 | + $tablename = $bean->getTableName(); |
|
| 1896 | + $fieldDefs = $bean->getFieldDefinitions(); |
|
| 1897 | + $indices = $bean->getIndices(); |
|
| 1898 | + return $this->createTableSQLParams($tablename, $fieldDefs, $indices); |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + /** |
|
| 1902 | + * Generates SQL for insert statement. |
|
| 1903 | + * |
|
| 1904 | + * @param SugarBean $bean SugarBean instance |
|
| 1905 | + * @return string SQL Create Table statement |
|
| 1906 | + */ |
|
| 1907 | + public function insertSQL(SugarBean $bean) |
|
| 1908 | + { |
|
| 1909 | + // get column names and values |
|
| 1910 | + $sql = $this->insertParams($bean->getTableName(), $bean->getFieldDefinitions(), get_object_vars($bean), |
|
| 1911 | + isset($bean->field_name_map)?$bean->field_name_map:null, false); |
|
| 1912 | + return $sql; |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + /** |
|
| 1916 | + * Generates SQL for update statement. |
|
| 1917 | + * |
|
| 1918 | + * @param SugarBean $bean SugarBean instance |
|
| 1919 | + * @param array $where Optional, where conditions in an array |
|
| 1920 | + * @return string SQL Create Table statement |
|
| 1921 | + */ |
|
| 1922 | + public function updateSQL(SugarBean $bean, array $where = array()) |
|
| 1923 | + { |
|
| 1924 | + $primaryField = $bean->getPrimaryFieldDefinition(); |
|
| 1925 | + $columns = array(); |
|
| 1926 | 1926 | $fields = $bean->getFieldDefinitions(); |
| 1927 | - // get column names and values |
|
| 1928 | - foreach ($fields as $field => $fieldDef) { |
|
| 1929 | - if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
| 1930 | - // Do not write out the id field on the update statement. |
|
| 1931 | - // We are not allowed to change ids. |
|
| 1932 | - if ($fieldDef['name'] == $primaryField['name']) continue; |
|
| 1933 | - |
|
| 1934 | - // If the field is an auto_increment field, then we shouldn't be setting it. This was added |
|
| 1935 | - // specially for Bugs and Cases which have a number associated with them. |
|
| 1936 | - if (!empty($bean->field_name_map[$field]['auto_increment'])) continue; |
|
| 1937 | - |
|
| 1938 | - //custom fields handle their save separately |
|
| 1939 | - if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) continue; |
|
| 1940 | - |
|
| 1941 | - // no need to clear deleted since we only update not deleted records anyway |
|
| 1942 | - if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue; |
|
| 1943 | - |
|
| 1944 | - if(isset($bean->$field)) { |
|
| 1945 | - $val = from_html($bean->$field); |
|
| 1946 | - } else { |
|
| 1947 | - continue; |
|
| 1948 | - } |
|
| 1949 | - |
|
| 1950 | - if(!empty($fieldDef['type']) && $fieldDef['type'] == 'bool'){ |
|
| 1951 | - $val = $bean->getFieldValue($field); |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - if(strlen($val) == 0) { |
|
| 1955 | - if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 1956 | - $val = $fieldDef['default']; |
|
| 1957 | - } else { |
|
| 1958 | - $val = null; |
|
| 1959 | - } |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 1963 | - $val = $this->truncate($val, $fieldDef['len']); |
|
| 1964 | - } |
|
| 1965 | - $columnName = $this->quoteIdentifier($fieldDef['name']); |
|
| 1966 | - if(!is_null($val) || !empty($fieldDef['required'])) { |
|
| 1967 | - $columns[] = "{$columnName}=".$this->massageValue($val, $fieldDef); |
|
| 1968 | - } elseif($this->isNullable($fieldDef)) { |
|
| 1969 | - $columns[] = "{$columnName}=NULL"; |
|
| 1970 | - } else { |
|
| 1971 | - $columns[] = "{$columnName}=".$this->emptyValue($fieldDef['type']); |
|
| 1972 | - } |
|
| 1973 | - } |
|
| 1974 | - |
|
| 1975 | - if ( sizeof($columns) == 0 ) |
|
| 1976 | - return ""; // no columns set |
|
| 1977 | - |
|
| 1978 | - // build where clause |
|
| 1979 | - $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
|
| 1980 | - if(isset($fields['deleted'])) { |
|
| 1981 | - $where .= " AND deleted=0"; |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - return "UPDATE ".$bean->getTableName()." |
|
| 1927 | + // get column names and values |
|
| 1928 | + foreach ($fields as $field => $fieldDef) { |
|
| 1929 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
| 1930 | + // Do not write out the id field on the update statement. |
|
| 1931 | + // We are not allowed to change ids. |
|
| 1932 | + if ($fieldDef['name'] == $primaryField['name']) continue; |
|
| 1933 | + |
|
| 1934 | + // If the field is an auto_increment field, then we shouldn't be setting it. This was added |
|
| 1935 | + // specially for Bugs and Cases which have a number associated with them. |
|
| 1936 | + if (!empty($bean->field_name_map[$field]['auto_increment'])) continue; |
|
| 1937 | + |
|
| 1938 | + //custom fields handle their save separately |
|
| 1939 | + if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) continue; |
|
| 1940 | + |
|
| 1941 | + // no need to clear deleted since we only update not deleted records anyway |
|
| 1942 | + if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue; |
|
| 1943 | + |
|
| 1944 | + if(isset($bean->$field)) { |
|
| 1945 | + $val = from_html($bean->$field); |
|
| 1946 | + } else { |
|
| 1947 | + continue; |
|
| 1948 | + } |
|
| 1949 | + |
|
| 1950 | + if(!empty($fieldDef['type']) && $fieldDef['type'] == 'bool'){ |
|
| 1951 | + $val = $bean->getFieldValue($field); |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + if(strlen($val) == 0) { |
|
| 1955 | + if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 1956 | + $val = $fieldDef['default']; |
|
| 1957 | + } else { |
|
| 1958 | + $val = null; |
|
| 1959 | + } |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 1963 | + $val = $this->truncate($val, $fieldDef['len']); |
|
| 1964 | + } |
|
| 1965 | + $columnName = $this->quoteIdentifier($fieldDef['name']); |
|
| 1966 | + if(!is_null($val) || !empty($fieldDef['required'])) { |
|
| 1967 | + $columns[] = "{$columnName}=".$this->massageValue($val, $fieldDef); |
|
| 1968 | + } elseif($this->isNullable($fieldDef)) { |
|
| 1969 | + $columns[] = "{$columnName}=NULL"; |
|
| 1970 | + } else { |
|
| 1971 | + $columns[] = "{$columnName}=".$this->emptyValue($fieldDef['type']); |
|
| 1972 | + } |
|
| 1973 | + } |
|
| 1974 | + |
|
| 1975 | + if ( sizeof($columns) == 0 ) |
|
| 1976 | + return ""; // no columns set |
|
| 1977 | + |
|
| 1978 | + // build where clause |
|
| 1979 | + $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
|
| 1980 | + if(isset($fields['deleted'])) { |
|
| 1981 | + $where .= " AND deleted=0"; |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + return "UPDATE ".$bean->getTableName()." |
|
| 1985 | 1985 | SET ".implode(",", $columns)." |
| 1986 | 1986 | $where"; |
| 1987 | - } |
|
| 1988 | - |
|
| 1989 | - /** |
|
| 1990 | - * This method returns a where array so that it has id entry if |
|
| 1991 | - * where is not an array or is empty |
|
| 1992 | - * |
|
| 1993 | - * @param SugarBean $bean SugarBean instance |
|
| 1994 | - * @param array $where Optional, where conditions in an array |
|
| 1995 | - * @return array |
|
| 1996 | - */ |
|
| 1997 | - protected function updateWhereArray(SugarBean $bean, array $where = array()) |
|
| 1998 | - { |
|
| 1999 | - if (count($where) == 0) { |
|
| 2000 | - $fieldDef = $bean->getPrimaryFieldDefinition(); |
|
| 2001 | - $primaryColumn = $fieldDef['name']; |
|
| 2002 | - |
|
| 2003 | - $val = $bean->getFieldValue($fieldDef['name']); |
|
| 2004 | - if ($val != FALSE){ |
|
| 2005 | - $where[$primaryColumn] = $val; |
|
| 2006 | - } |
|
| 2007 | - } |
|
| 2008 | - |
|
| 2009 | - return $where; |
|
| 2010 | - } |
|
| 2011 | - |
|
| 2012 | - /** |
|
| 2013 | - * Returns a where clause without the 'where' key word |
|
| 2014 | - * |
|
| 2015 | - * The clause returned does not have an 'and' at the beginning and the columns |
|
| 2016 | - * are joined by 'and'. |
|
| 2017 | - * |
|
| 2018 | - * @param string $table table name |
|
| 2019 | - * @param array $whereArray Optional, where conditions in an array |
|
| 2020 | - * @return string |
|
| 2021 | - */ |
|
| 2022 | - protected function getColumnWhereClause($table, array $whereArray = array()) |
|
| 2023 | - { |
|
| 2024 | - $where = array(); |
|
| 2025 | - foreach ($whereArray as $name => $val) { |
|
| 2026 | - $op = "="; |
|
| 2027 | - if (is_array($val)) { |
|
| 2028 | - $op = "IN"; |
|
| 2029 | - $temp = array(); |
|
| 2030 | - foreach ($val as $tval){ |
|
| 2031 | - $temp[] = $this->quoted($tval); |
|
| 2032 | - } |
|
| 2033 | - $val = implode(",", $temp); |
|
| 2034 | - $val = "($val)"; |
|
| 2035 | - } else { |
|
| 2036 | - $val = $this->quoted($val); |
|
| 2037 | - } |
|
| 2038 | - |
|
| 2039 | - $where[] = " $table.$name $op $val"; |
|
| 2040 | - } |
|
| 2041 | - |
|
| 2042 | - if (!empty($where)) |
|
| 2043 | - return implode(" AND ", $where); |
|
| 2044 | - |
|
| 2045 | - return ''; |
|
| 2046 | - } |
|
| 2047 | - |
|
| 2048 | - /** |
|
| 2049 | - * This method returns a complete where clause built from the |
|
| 2050 | - * where values specified. |
|
| 2051 | - * |
|
| 2052 | - * @param SugarBean $bean SugarBean that describes the table |
|
| 2053 | - * @param array $whereArray Optional, where conditions in an array |
|
| 2054 | - * @return string |
|
| 2055 | - */ |
|
| 2056 | - protected function getWhereClause(SugarBean $bean, array $whereArray=array()) |
|
| 2057 | - { |
|
| 2058 | - return " WHERE " . $this->getColumnWhereClause($bean->getTableName(), $whereArray); |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - /** |
|
| 2062 | - * Outputs a correct string for the sql statement according to value |
|
| 2063 | - * |
|
| 2064 | - * @param mixed $val |
|
| 2065 | - * @param array $fieldDef field definition |
|
| 2066 | - * @return mixed |
|
| 2067 | - */ |
|
| 2068 | - public function massageValue($val, $fieldDef) |
|
| 2069 | - { |
|
| 2070 | - $type = $this->getFieldType($fieldDef); |
|
| 2071 | - |
|
| 2072 | - if(isset($this->type_class[$type])) { |
|
| 2073 | - // handle some known types |
|
| 2074 | - switch($this->type_class[$type]) { |
|
| 2075 | - case 'bool': |
|
| 2076 | - case 'int': |
|
| 2077 | - if (!empty($fieldDef['required']) && $val == ''){ |
|
| 2078 | - if (isset($fieldDef['default'])){ |
|
| 2079 | - return $fieldDef['default']; |
|
| 2080 | - } |
|
| 2081 | - return 0; |
|
| 2082 | - } |
|
| 2083 | - return intval($val); |
|
| 1987 | + } |
|
| 1988 | + |
|
| 1989 | + /** |
|
| 1990 | + * This method returns a where array so that it has id entry if |
|
| 1991 | + * where is not an array or is empty |
|
| 1992 | + * |
|
| 1993 | + * @param SugarBean $bean SugarBean instance |
|
| 1994 | + * @param array $where Optional, where conditions in an array |
|
| 1995 | + * @return array |
|
| 1996 | + */ |
|
| 1997 | + protected function updateWhereArray(SugarBean $bean, array $where = array()) |
|
| 1998 | + { |
|
| 1999 | + if (count($where) == 0) { |
|
| 2000 | + $fieldDef = $bean->getPrimaryFieldDefinition(); |
|
| 2001 | + $primaryColumn = $fieldDef['name']; |
|
| 2002 | + |
|
| 2003 | + $val = $bean->getFieldValue($fieldDef['name']); |
|
| 2004 | + if ($val != FALSE){ |
|
| 2005 | + $where[$primaryColumn] = $val; |
|
| 2006 | + } |
|
| 2007 | + } |
|
| 2008 | + |
|
| 2009 | + return $where; |
|
| 2010 | + } |
|
| 2011 | + |
|
| 2012 | + /** |
|
| 2013 | + * Returns a where clause without the 'where' key word |
|
| 2014 | + * |
|
| 2015 | + * The clause returned does not have an 'and' at the beginning and the columns |
|
| 2016 | + * are joined by 'and'. |
|
| 2017 | + * |
|
| 2018 | + * @param string $table table name |
|
| 2019 | + * @param array $whereArray Optional, where conditions in an array |
|
| 2020 | + * @return string |
|
| 2021 | + */ |
|
| 2022 | + protected function getColumnWhereClause($table, array $whereArray = array()) |
|
| 2023 | + { |
|
| 2024 | + $where = array(); |
|
| 2025 | + foreach ($whereArray as $name => $val) { |
|
| 2026 | + $op = "="; |
|
| 2027 | + if (is_array($val)) { |
|
| 2028 | + $op = "IN"; |
|
| 2029 | + $temp = array(); |
|
| 2030 | + foreach ($val as $tval){ |
|
| 2031 | + $temp[] = $this->quoted($tval); |
|
| 2032 | + } |
|
| 2033 | + $val = implode(",", $temp); |
|
| 2034 | + $val = "($val)"; |
|
| 2035 | + } else { |
|
| 2036 | + $val = $this->quoted($val); |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + $where[] = " $table.$name $op $val"; |
|
| 2040 | + } |
|
| 2041 | + |
|
| 2042 | + if (!empty($where)) |
|
| 2043 | + return implode(" AND ", $where); |
|
| 2044 | + |
|
| 2045 | + return ''; |
|
| 2046 | + } |
|
| 2047 | + |
|
| 2048 | + /** |
|
| 2049 | + * This method returns a complete where clause built from the |
|
| 2050 | + * where values specified. |
|
| 2051 | + * |
|
| 2052 | + * @param SugarBean $bean SugarBean that describes the table |
|
| 2053 | + * @param array $whereArray Optional, where conditions in an array |
|
| 2054 | + * @return string |
|
| 2055 | + */ |
|
| 2056 | + protected function getWhereClause(SugarBean $bean, array $whereArray=array()) |
|
| 2057 | + { |
|
| 2058 | + return " WHERE " . $this->getColumnWhereClause($bean->getTableName(), $whereArray); |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + /** |
|
| 2062 | + * Outputs a correct string for the sql statement according to value |
|
| 2063 | + * |
|
| 2064 | + * @param mixed $val |
|
| 2065 | + * @param array $fieldDef field definition |
|
| 2066 | + * @return mixed |
|
| 2067 | + */ |
|
| 2068 | + public function massageValue($val, $fieldDef) |
|
| 2069 | + { |
|
| 2070 | + $type = $this->getFieldType($fieldDef); |
|
| 2071 | + |
|
| 2072 | + if(isset($this->type_class[$type])) { |
|
| 2073 | + // handle some known types |
|
| 2074 | + switch($this->type_class[$type]) { |
|
| 2075 | + case 'bool': |
|
| 2076 | + case 'int': |
|
| 2077 | + if (!empty($fieldDef['required']) && $val == ''){ |
|
| 2078 | + if (isset($fieldDef['default'])){ |
|
| 2079 | + return $fieldDef['default']; |
|
| 2080 | + } |
|
| 2081 | + return 0; |
|
| 2082 | + } |
|
| 2083 | + return intval($val); |
|
| 2084 | 2084 | case 'bigint' : |
| 2085 | 2085 | $val = (float)$val; |
| 2086 | - if (!empty($fieldDef['required']) && $val == false){ |
|
| 2087 | - if (isset($fieldDef['default'])){ |
|
| 2088 | - return $fieldDef['default']; |
|
| 2089 | - } |
|
| 2090 | - return 0; |
|
| 2091 | - } |
|
| 2086 | + if (!empty($fieldDef['required']) && $val == false){ |
|
| 2087 | + if (isset($fieldDef['default'])){ |
|
| 2088 | + return $fieldDef['default']; |
|
| 2089 | + } |
|
| 2090 | + return 0; |
|
| 2091 | + } |
|
| 2092 | 2092 | return $val; |
| 2093 | - case 'float': |
|
| 2094 | - if (!empty($fieldDef['required']) && $val == ''){ |
|
| 2095 | - if (isset($fieldDef['default'])){ |
|
| 2096 | - return $fieldDef['default']; |
|
| 2097 | - } |
|
| 2098 | - return 0; |
|
| 2099 | - } |
|
| 2100 | - return floatval($val); |
|
| 2101 | - case 'time': |
|
| 2102 | - case 'date': |
|
| 2103 | - // empty date can't be '', so convert it to either NULL or empty date value |
|
| 2104 | - if($val == '') { |
|
| 2105 | - if (!empty($fieldDef['required'])) { |
|
| 2106 | - if (isset($fieldDef['default'])) { |
|
| 2107 | - return $fieldDef['default']; |
|
| 2108 | - } |
|
| 2109 | - return $this->emptyValue($type); |
|
| 2110 | - } |
|
| 2111 | - return "NULL"; |
|
| 2112 | - } |
|
| 2113 | - break; |
|
| 2114 | - } |
|
| 2115 | - } else { |
|
| 2116 | - if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 2117 | - $val = $this->truncate($val, $fieldDef['len']); |
|
| 2118 | - } |
|
| 2119 | - } |
|
| 2120 | - |
|
| 2121 | - if ( is_null($val) ) { |
|
| 2122 | - if(!empty($fieldDef['required'])) { |
|
| 2123 | - if (isset($fieldDef['default'])){ |
|
| 2124 | - return $fieldDef['default']; |
|
| 2125 | - } |
|
| 2126 | - return $this->emptyValue($type); |
|
| 2127 | - } else { |
|
| 2128 | - return "NULL"; |
|
| 2129 | - } |
|
| 2130 | - } |
|
| 2093 | + case 'float': |
|
| 2094 | + if (!empty($fieldDef['required']) && $val == ''){ |
|
| 2095 | + if (isset($fieldDef['default'])){ |
|
| 2096 | + return $fieldDef['default']; |
|
| 2097 | + } |
|
| 2098 | + return 0; |
|
| 2099 | + } |
|
| 2100 | + return floatval($val); |
|
| 2101 | + case 'time': |
|
| 2102 | + case 'date': |
|
| 2103 | + // empty date can't be '', so convert it to either NULL or empty date value |
|
| 2104 | + if($val == '') { |
|
| 2105 | + if (!empty($fieldDef['required'])) { |
|
| 2106 | + if (isset($fieldDef['default'])) { |
|
| 2107 | + return $fieldDef['default']; |
|
| 2108 | + } |
|
| 2109 | + return $this->emptyValue($type); |
|
| 2110 | + } |
|
| 2111 | + return "NULL"; |
|
| 2112 | + } |
|
| 2113 | + break; |
|
| 2114 | + } |
|
| 2115 | + } else { |
|
| 2116 | + if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 2117 | + $val = $this->truncate($val, $fieldDef['len']); |
|
| 2118 | + } |
|
| 2119 | + } |
|
| 2120 | + |
|
| 2121 | + if ( is_null($val) ) { |
|
| 2122 | + if(!empty($fieldDef['required'])) { |
|
| 2123 | + if (isset($fieldDef['default'])){ |
|
| 2124 | + return $fieldDef['default']; |
|
| 2125 | + } |
|
| 2126 | + return $this->emptyValue($type); |
|
| 2127 | + } else { |
|
| 2128 | + return "NULL"; |
|
| 2129 | + } |
|
| 2130 | + } |
|
| 2131 | 2131 | if($type == "datetimecombo") { |
| 2132 | 2132 | $type = "datetime"; |
| 2133 | 2133 | } |
| 2134 | - return $this->convert($this->quoted($val), $type); |
|
| 2135 | - } |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * Massages the field defintions to fill in anything else the DB backend may add |
|
| 2139 | - * |
|
| 2140 | - * @param array $fieldDef |
|
| 2141 | - * @param string $tablename |
|
| 2142 | - * @return array |
|
| 2143 | - */ |
|
| 2144 | - public function massageFieldDef(&$fieldDef, $tablename) |
|
| 2145 | - { |
|
| 2146 | - if ( !isset($fieldDef['dbType']) ) { |
|
| 2147 | - if ( isset($fieldDef['dbtype']) ) |
|
| 2148 | - $fieldDef['dbType'] = $fieldDef['dbtype']; |
|
| 2149 | - else |
|
| 2150 | - $fieldDef['dbType'] = $fieldDef['type']; |
|
| 2151 | - } |
|
| 2152 | - $type = $this->getColumnType($fieldDef['dbType'],$fieldDef['name'],$tablename); |
|
| 2153 | - $matches = array(); |
|
| 2134 | + return $this->convert($this->quoted($val), $type); |
|
| 2135 | + } |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * Massages the field defintions to fill in anything else the DB backend may add |
|
| 2139 | + * |
|
| 2140 | + * @param array $fieldDef |
|
| 2141 | + * @param string $tablename |
|
| 2142 | + * @return array |
|
| 2143 | + */ |
|
| 2144 | + public function massageFieldDef(&$fieldDef, $tablename) |
|
| 2145 | + { |
|
| 2146 | + if ( !isset($fieldDef['dbType']) ) { |
|
| 2147 | + if ( isset($fieldDef['dbtype']) ) |
|
| 2148 | + $fieldDef['dbType'] = $fieldDef['dbtype']; |
|
| 2149 | + else |
|
| 2150 | + $fieldDef['dbType'] = $fieldDef['type']; |
|
| 2151 | + } |
|
| 2152 | + $type = $this->getColumnType($fieldDef['dbType'],$fieldDef['name'],$tablename); |
|
| 2153 | + $matches = array(); |
|
| 2154 | 2154 | // len can be a number or a string like 'max', for example, nvarchar(max) |
| 2155 | 2155 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*|\w+)\)|)/i', $type, $matches); |
| 2156 | - if ( isset($matches[1][0]) ) |
|
| 2157 | - $fieldDef['type'] = $matches[1][0]; |
|
| 2158 | - if ( isset($matches[2][0]) && empty($fieldDef['len']) ) |
|
| 2159 | - $fieldDef['len'] = $matches[2][0]; |
|
| 2160 | - if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) |
|
| 2161 | - $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
|
| 2162 | - if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required'])) ) { |
|
| 2163 | - $fieldDef['required'] = 'true'; |
|
| 2164 | - } |
|
| 2165 | - } |
|
| 2166 | - |
|
| 2167 | - /** |
|
| 2168 | - * Take an SQL statement and produce a list of fields used in that select |
|
| 2169 | - * @param string $selectStatement |
|
| 2170 | - * @return array |
|
| 2171 | - */ |
|
| 2172 | - public function getSelectFieldsFromQuery($selectStatement) |
|
| 2173 | - { |
|
| 2174 | - $selectStatement = trim($selectStatement); |
|
| 2175 | - if (strtoupper(substr($selectStatement, 0, 6)) == "SELECT") |
|
| 2176 | - $selectStatement = trim(substr($selectStatement, 6)); |
|
| 2177 | - |
|
| 2178 | - //Due to sql functions existing in many selects, we can't use php explode |
|
| 2179 | - $fields = array(); |
|
| 2180 | - $level = 0; |
|
| 2181 | - $selectField = ""; |
|
| 2182 | - $strLen = strlen($selectStatement); |
|
| 2183 | - for($i = 0; $i < $strLen; $i++) |
|
| 2184 | - { |
|
| 2185 | - $char = $selectStatement[$i]; |
|
| 2186 | - |
|
| 2187 | - if ($char == "," && $level == 0) |
|
| 2188 | - { |
|
| 2189 | - $field = $this->getFieldNameFromSelect(trim($selectField)); |
|
| 2190 | - $fields[$field] = $selectField; |
|
| 2191 | - $selectField = ""; |
|
| 2192 | - } |
|
| 2193 | - else if ($char == "("){ |
|
| 2194 | - $level++; |
|
| 2195 | - $selectField .= $char; |
|
| 2196 | - } |
|
| 2197 | - else if($char == ")"){ |
|
| 2198 | - $level--; |
|
| 2199 | - $selectField .= $char; |
|
| 2200 | - |
|
| 2201 | - |
|
| 2202 | - }else{ |
|
| 2203 | - $selectField .= $char; |
|
| 2204 | - } |
|
| 2205 | - |
|
| 2206 | - } |
|
| 2207 | - $fields[$this->getFieldNameFromSelect($selectField)] = $selectField; |
|
| 2208 | - return $fields; |
|
| 2209 | - } |
|
| 2210 | - |
|
| 2211 | - /** |
|
| 2212 | - * returns the field name used in a select |
|
| 2213 | - * @param string $string SELECT query |
|
| 2156 | + if ( isset($matches[1][0]) ) |
|
| 2157 | + $fieldDef['type'] = $matches[1][0]; |
|
| 2158 | + if ( isset($matches[2][0]) && empty($fieldDef['len']) ) |
|
| 2159 | + $fieldDef['len'] = $matches[2][0]; |
|
| 2160 | + if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) |
|
| 2161 | + $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
|
| 2162 | + if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required'])) ) { |
|
| 2163 | + $fieldDef['required'] = 'true'; |
|
| 2164 | + } |
|
| 2165 | + } |
|
| 2166 | + |
|
| 2167 | + /** |
|
| 2168 | + * Take an SQL statement and produce a list of fields used in that select |
|
| 2169 | + * @param string $selectStatement |
|
| 2170 | + * @return array |
|
| 2171 | + */ |
|
| 2172 | + public function getSelectFieldsFromQuery($selectStatement) |
|
| 2173 | + { |
|
| 2174 | + $selectStatement = trim($selectStatement); |
|
| 2175 | + if (strtoupper(substr($selectStatement, 0, 6)) == "SELECT") |
|
| 2176 | + $selectStatement = trim(substr($selectStatement, 6)); |
|
| 2177 | + |
|
| 2178 | + //Due to sql functions existing in many selects, we can't use php explode |
|
| 2179 | + $fields = array(); |
|
| 2180 | + $level = 0; |
|
| 2181 | + $selectField = ""; |
|
| 2182 | + $strLen = strlen($selectStatement); |
|
| 2183 | + for($i = 0; $i < $strLen; $i++) |
|
| 2184 | + { |
|
| 2185 | + $char = $selectStatement[$i]; |
|
| 2186 | + |
|
| 2187 | + if ($char == "," && $level == 0) |
|
| 2188 | + { |
|
| 2189 | + $field = $this->getFieldNameFromSelect(trim($selectField)); |
|
| 2190 | + $fields[$field] = $selectField; |
|
| 2191 | + $selectField = ""; |
|
| 2192 | + } |
|
| 2193 | + else if ($char == "("){ |
|
| 2194 | + $level++; |
|
| 2195 | + $selectField .= $char; |
|
| 2196 | + } |
|
| 2197 | + else if($char == ")"){ |
|
| 2198 | + $level--; |
|
| 2199 | + $selectField .= $char; |
|
| 2200 | + |
|
| 2201 | + |
|
| 2202 | + }else{ |
|
| 2203 | + $selectField .= $char; |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + } |
|
| 2207 | + $fields[$this->getFieldNameFromSelect($selectField)] = $selectField; |
|
| 2208 | + return $fields; |
|
| 2209 | + } |
|
| 2210 | + |
|
| 2211 | + /** |
|
| 2212 | + * returns the field name used in a select |
|
| 2213 | + * @param string $string SELECT query |
|
| 2214 | 2214 | * @return string |
| 2215 | 2215 | */ |
| 2216 | - protected function getFieldNameFromSelect($string) |
|
| 2217 | - { |
|
| 2218 | - if(strncasecmp($string, "DISTINCT ", 9) == 0) { |
|
| 2219 | - $string = substr($string, 9); |
|
| 2220 | - } |
|
| 2221 | - if (stripos($string, " as ") !== false) |
|
| 2222 | - //"as" used for an alias |
|
| 2223 | - return trim(substr($string, strripos($string, " as ") + 4)); |
|
| 2224 | - else if (strrpos($string, " ") != 0) |
|
| 2225 | - //Space used as a delimiter for an alias |
|
| 2226 | - return trim(substr($string, strrpos($string, " "))); |
|
| 2227 | - else if (strpos($string, ".") !== false) |
|
| 2228 | - //No alias, but a table.field format was used |
|
| 2229 | - return substr($string, strpos($string, ".") + 1); |
|
| 2230 | - else |
|
| 2231 | - //Give up and assume the whole thing is the field name |
|
| 2232 | - return $string; |
|
| 2233 | - } |
|
| 2234 | - |
|
| 2235 | - /** |
|
| 2236 | - * Generates SQL for delete statement identified by id. |
|
| 2237 | - * |
|
| 2238 | - * @param SugarBean $bean SugarBean instance |
|
| 2239 | - * @param array $where where conditions in an array |
|
| 2240 | - * @return string SQL Update Statement |
|
| 2241 | - */ |
|
| 2242 | - public function deleteSQL(SugarBean $bean, array $where) |
|
| 2243 | - { |
|
| 2244 | - $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
|
| 2245 | - return "UPDATE ".$bean->getTableName()." SET deleted=1 $where"; |
|
| 2246 | - } |
|
| 2216 | + protected function getFieldNameFromSelect($string) |
|
| 2217 | + { |
|
| 2218 | + if(strncasecmp($string, "DISTINCT ", 9) == 0) { |
|
| 2219 | + $string = substr($string, 9); |
|
| 2220 | + } |
|
| 2221 | + if (stripos($string, " as ") !== false) |
|
| 2222 | + //"as" used for an alias |
|
| 2223 | + return trim(substr($string, strripos($string, " as ") + 4)); |
|
| 2224 | + else if (strrpos($string, " ") != 0) |
|
| 2225 | + //Space used as a delimiter for an alias |
|
| 2226 | + return trim(substr($string, strrpos($string, " "))); |
|
| 2227 | + else if (strpos($string, ".") !== false) |
|
| 2228 | + //No alias, but a table.field format was used |
|
| 2229 | + return substr($string, strpos($string, ".") + 1); |
|
| 2230 | + else |
|
| 2231 | + //Give up and assume the whole thing is the field name |
|
| 2232 | + return $string; |
|
| 2233 | + } |
|
| 2234 | + |
|
| 2235 | + /** |
|
| 2236 | + * Generates SQL for delete statement identified by id. |
|
| 2237 | + * |
|
| 2238 | + * @param SugarBean $bean SugarBean instance |
|
| 2239 | + * @param array $where where conditions in an array |
|
| 2240 | + * @return string SQL Update Statement |
|
| 2241 | + */ |
|
| 2242 | + public function deleteSQL(SugarBean $bean, array $where) |
|
| 2243 | + { |
|
| 2244 | + $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
|
| 2245 | + return "UPDATE ".$bean->getTableName()." SET deleted=1 $where"; |
|
| 2246 | + } |
|
| 2247 | + |
|
| 2248 | + /** |
|
| 2249 | + * Generates SQL for select statement for any bean identified by id. |
|
| 2250 | + * |
|
| 2251 | + * @param SugarBean $bean SugarBean instance |
|
| 2252 | + * @param array $where where conditions in an array |
|
| 2253 | + * @return string SQL Select Statement |
|
| 2254 | + */ |
|
| 2255 | + public function retrieveSQL(SugarBean $bean, array $where) |
|
| 2256 | + { |
|
| 2257 | + $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
|
| 2258 | + return "SELECT * FROM ".$bean->getTableName()." $where AND deleted=0"; |
|
| 2259 | + } |
|
| 2260 | + |
|
| 2261 | + /** |
|
| 2262 | + * This method implements a generic sql for a collection of beans. |
|
| 2263 | + * |
|
| 2264 | + * Currently, this function does not support outer joins. |
|
| 2265 | + * |
|
| 2266 | + * @param array $beans Array of values returned by get_class method as the keys and a bean as |
|
| 2267 | + * the value for that key. These beans will be joined in the sql by the key |
|
| 2268 | + * attribute of field defs. |
|
| 2269 | + * @param array $cols Optional, columns to be returned with the keys as names of bean |
|
| 2270 | + * as identified by get_class of bean. Values of this array is the array of fieldDefs |
|
| 2271 | + * to be returned for a bean. If an empty array is passed, all columns are selected. |
|
| 2272 | + * @param array $whereClause Optional, values with the keys as names of bean as identified |
|
| 2273 | + * by get_class of bean. Each value at the first level is an array of values for that |
|
| 2274 | + * bean identified by name of fields. If we want to pass multiple values for a name, |
|
| 2275 | + * pass it as an array. If where is not passed, all the rows will be returned. |
|
| 2276 | + * |
|
| 2277 | + * @return string SQL Select Statement |
|
| 2278 | + */ |
|
| 2279 | + public function retrieveViewSQL(array $beans, array $cols = array(), array $whereClause = array()) |
|
| 2280 | + { |
|
| 2281 | + $relations = array(); // stores relations between tables as they are discovered |
|
| 2282 | + $where = $select = array(); |
|
| 2283 | + foreach ($beans as $beanID => $bean) { |
|
| 2284 | + $tableName = $bean->getTableName(); |
|
| 2285 | + $beanTables[$beanID] = $tableName; |
|
| 2286 | + |
|
| 2287 | + $table = $beanID; |
|
| 2288 | + $tables[$table] = $tableName; |
|
| 2289 | + $aliases[$tableName][] = $table; |
|
| 2290 | + |
|
| 2291 | + // build part of select for this table |
|
| 2292 | + if (is_array($cols[$beanID])) |
|
| 2293 | + foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
|
| 2294 | + |
|
| 2295 | + // build part of where clause |
|
| 2296 | + if (is_array($whereClause[$beanID])){ |
|
| 2297 | + $where[] = $this->getColumnWhereClause($table, $whereClause[$beanID]); |
|
| 2298 | + } |
|
| 2299 | + // initialize so that it can be used properly in form clause generation |
|
| 2300 | + $table_used_in_from[$table] = false; |
|
| 2301 | + |
|
| 2302 | + $indices = $bean->getIndices(); |
|
| 2303 | + foreach ($indices as $index){ |
|
| 2304 | + if ($index['type'] == 'foreign') { |
|
| 2305 | + $relationship[$table][] = array('foreignTable'=> $index['foreignTable'] |
|
| 2306 | + ,'foreignColumn'=>$index['foreignField'] |
|
| 2307 | + ,'localColumn'=> $index['fields'] |
|
| 2308 | + ); |
|
| 2309 | + } |
|
| 2310 | + } |
|
| 2311 | + $where[] = " $table.deleted = 0"; |
|
| 2312 | + } |
|
| 2313 | + |
|
| 2314 | + // join these clauses |
|
| 2315 | + $select = !empty($select) ? implode(",", $select) : "*"; |
|
| 2316 | + $where = implode(" AND ", $where); |
|
| 2317 | + |
|
| 2318 | + // generate the from clause. Use relations array to generate outer joins |
|
| 2319 | + // all the rest of the tables will be used as a simple from |
|
| 2320 | + // relations table define relations between table1 and table2 through column on table 1 |
|
| 2321 | + // table2 is assumed to joining through primary key called id |
|
| 2322 | + $separator = ""; |
|
| 2323 | + $from = ''; $table_used_in_from = array(); |
|
| 2324 | + foreach ($relations as $table1 => $rightsidearray){ |
|
| 2325 | + if ($table_used_in_from[$table1]) continue; // table has been joined |
|
| 2326 | + |
|
| 2327 | + $from .= $separator." ".$table1; |
|
| 2328 | + $table_used_in_from[$table1] = true; |
|
| 2329 | + foreach ($rightsidearray as $tablearray){ |
|
| 2330 | + $table2 = $tablearray['foreignTable']; // get foreign table |
|
| 2331 | + $tableAlias = $aliases[$table2]; // get a list of aliases for this table |
|
| 2332 | + foreach ($tableAlias as $table2) { |
|
| 2333 | + //choose first alias that does not match |
|
| 2334 | + // we are doing this because of self joins. |
|
| 2335 | + // in case of self joins, the same table will have many aliases. |
|
| 2336 | + if ($table2 != $table1) break; |
|
| 2337 | + } |
|
| 2338 | + |
|
| 2339 | + $col = $tablearray['foreingColumn']; |
|
| 2340 | + $name = $tablearray['localColumn']; |
|
| 2341 | + $from .= " LEFT JOIN $table on ($table1.$name = $table2.$col)"; |
|
| 2342 | + $table_used_in_from[$table2] = true; |
|
| 2343 | + } |
|
| 2344 | + $separator = ","; |
|
| 2345 | + } |
|
| 2346 | + |
|
| 2347 | + return "SELECT $select FROM $from WHERE $where"; |
|
| 2348 | + } |
|
| 2349 | + |
|
| 2350 | + /** |
|
| 2351 | + * Generates SQL for create index statement for a bean. |
|
| 2352 | + * |
|
| 2353 | + * @param SugarBean $bean SugarBean instance |
|
| 2354 | + * @param array $fields fields used in the index |
|
| 2355 | + * @param string $name index name |
|
| 2356 | + * @param bool $unique Optional, set to true if this is an unique index |
|
| 2357 | + * @return string SQL Select Statement |
|
| 2358 | + */ |
|
| 2359 | + public function createIndexSQL(SugarBean $bean, array $fields, $name, $unique = true) |
|
| 2360 | + { |
|
| 2361 | + $unique = ($unique) ? "unique" : ""; |
|
| 2362 | + $tablename = $bean->getTableName(); |
|
| 2363 | + $columns = array(); |
|
| 2364 | + // get column names |
|
| 2365 | + foreach ($fields as $fieldDef) |
|
| 2366 | + $columns[] = $fieldDef['name']; |
|
| 2367 | + |
|
| 2368 | + if (empty($columns)) |
|
| 2369 | + return ""; |
|
| 2370 | + |
|
| 2371 | + $columns = implode(",", $columns); |
|
| 2372 | + |
|
| 2373 | + return "CREATE $unique INDEX $name ON $tablename ($columns)"; |
|
| 2374 | + } |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * Returns the type of the variable in the field |
|
| 2378 | + * |
|
| 2379 | + * @param array $fieldDef Vardef-format field def |
|
| 2380 | + * @return string |
|
| 2381 | + */ |
|
| 2382 | + public function getFieldType($fieldDef) |
|
| 2383 | + { |
|
| 2384 | + // get the type for db type. if that is not set, |
|
| 2385 | + // get it from type. This is done so that |
|
| 2386 | + // we do not have change a lot of existing code |
|
| 2387 | + // and add dbtype where type is being used for some special |
|
| 2388 | + // purposes like referring to foreign table etc. |
|
| 2389 | + if(!empty($fieldDef['dbType'])) |
|
| 2390 | + return $fieldDef['dbType']; |
|
| 2391 | + if(!empty($fieldDef['dbtype'])) |
|
| 2392 | + return $fieldDef['dbtype']; |
|
| 2393 | + if (!empty($fieldDef['type'])) |
|
| 2394 | + return $fieldDef['type']; |
|
| 2395 | + if (!empty($fieldDef['Type'])) |
|
| 2396 | + return $fieldDef['Type']; |
|
| 2397 | + if (!empty($fieldDef['data_type'])) |
|
| 2398 | + return $fieldDef['data_type']; |
|
| 2399 | + |
|
| 2400 | + return null; |
|
| 2401 | + } |
|
| 2402 | + |
|
| 2403 | + /** |
|
| 2404 | + * retrieves the different components from the passed column type as it is used in the type mapping and vardefs |
|
| 2405 | + * type format: <baseType>[(<len>[,<scale>])] |
|
| 2406 | + * @param string $type Column type |
|
| 2407 | + * @return array|bool array containing the different components of the passed in type or false in case the type contains illegal characters |
|
| 2408 | + */ |
|
| 2409 | + public function getTypeParts($type) |
|
| 2410 | + { |
|
| 2411 | + if(preg_match("#(?P<type>\w+)\s*(?P<arg>\((?P<len>\w+)\s*(,\s*(?P<scale>\d+))*\))*#", $type, $matches)) |
|
| 2412 | + { |
|
| 2413 | + $return = array(); // Not returning matches array as such as we don't want to expose the regex make up on the interface |
|
| 2414 | + $return['baseType'] = $matches['type']; |
|
| 2415 | + if( isset($matches['arg'])) { |
|
| 2416 | + $return['arg'] = $matches['arg']; |
|
| 2417 | + } |
|
| 2418 | + if( isset($matches['len'])) { |
|
| 2419 | + $return['len'] = $matches['len']; |
|
| 2420 | + } |
|
| 2421 | + if( isset($matches['scale'])) { |
|
| 2422 | + $return['scale'] = $matches['scale']; |
|
| 2423 | + } |
|
| 2424 | + return $return; |
|
| 2425 | + } else { |
|
| 2426 | + return false; |
|
| 2427 | + } |
|
| 2428 | + } |
|
| 2429 | + |
|
| 2430 | + /** |
|
| 2431 | + * Returns the defintion for a single column |
|
| 2432 | + * |
|
| 2433 | + * @param array $fieldDef Vardef-format field def |
|
| 2434 | + * @param bool $ignoreRequired Optional, true if we should ignore this being a required field |
|
| 2435 | + * @param string $table Optional, table name |
|
| 2436 | + * @param bool $return_as_array Optional, true if we should return the result as an array instead of sql |
|
| 2437 | + * @return string or array if $return_as_array is true |
|
| 2438 | + */ |
|
| 2439 | + protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
| 2440 | + { |
|
| 2441 | + $name = $fieldDef['name']; |
|
| 2442 | + $type = $this->getFieldType($fieldDef); |
|
| 2443 | + $colType = $this->getColumnType($type); |
|
| 2444 | + |
|
| 2445 | + if($parts = $this->getTypeParts($colType)) |
|
| 2446 | + { |
|
| 2447 | + $colBaseType = $parts['baseType']; |
|
| 2448 | + $defLen = isset($parts['len']) ? $parts['len'] : '255'; // Use the mappings length (precision) as default if it exists |
|
| 2449 | + } |
|
| 2450 | + |
|
| 2451 | + if(!empty($fieldDef['len'])) { |
|
| 2452 | + if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char', |
|
| 2453 | + 'clob', 'blob', 'text'))) { |
|
| 2454 | + $colType = "$colBaseType(${fieldDef['len']})"; |
|
| 2455 | + } elseif(($colBaseType == 'decimal' || $colBaseType == 'float')){ |
|
| 2456 | + if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) |
|
| 2457 | + if(strpos($fieldDef['len'],',') === false){ |
|
| 2458 | + $colType = $colBaseType . "(".$fieldDef['len'].",".$fieldDef['precision'].")"; |
|
| 2459 | + }else{ |
|
| 2460 | + $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2461 | + } |
|
| 2462 | + else |
|
| 2463 | + $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2464 | + } |
|
| 2465 | + } else { |
|
| 2466 | + if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) { |
|
| 2467 | + $colType = "$colBaseType($defLen)"; |
|
| 2468 | + } |
|
| 2469 | + } |
|
| 2470 | + |
|
| 2471 | + $default = ''; |
|
| 2472 | + |
|
| 2473 | + // Bug #52610 We should have ability don't add DEFAULT part to query for boolean fields |
|
| 2474 | + if (!empty($fieldDef['no_default'])) |
|
| 2475 | + { |
|
| 2476 | + // nothing to do |
|
| 2477 | + } |
|
| 2478 | + elseif (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) |
|
| 2479 | + { |
|
| 2480 | + $default = " DEFAULT ".$this->quoted($fieldDef['default']); |
|
| 2481 | + } |
|
| 2482 | + elseif (!isset($default) && $type == 'bool') |
|
| 2483 | + { |
|
| 2484 | + $default = " DEFAULT 0 "; |
|
| 2485 | + } |
|
| 2486 | + |
|
| 2487 | + $auto_increment = ''; |
|
| 2488 | + if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) |
|
| 2489 | + $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
| 2490 | + |
|
| 2491 | + $required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify |
|
| 2492 | + //Starting in 6.0, only ID and auto_increment fields will be NOT NULL in the DB. |
|
| 2493 | + if ((empty($fieldDef['isnull']) || strtolower($fieldDef['isnull']) == 'false') && |
|
| 2494 | + (!empty($auto_increment) || $name == 'id' || ($fieldDef['type'] == 'id' && !empty($fieldDef['required'])))) { |
|
| 2495 | + $required = "NOT NULL"; |
|
| 2496 | + } |
|
| 2497 | + // If the field is marked both required & isnull=>false - alwqys make it not null |
|
| 2498 | + // Use this to ensure primary key fields never defined as null |
|
| 2499 | + if(isset($fieldDef['isnull']) && (strtolower($fieldDef['isnull']) == 'false' || $fieldDef['isnull'] === false) |
|
| 2500 | + && !empty($fieldDef['required'])) { |
|
| 2501 | + $required = "NOT NULL"; |
|
| 2502 | + } |
|
| 2503 | + if ($ignoreRequired) |
|
| 2504 | + $required = ""; |
|
| 2505 | + |
|
| 2506 | + if ( $return_as_array ) { |
|
| 2507 | + return array( |
|
| 2508 | + 'name' => $name, |
|
| 2509 | + 'colType' => $colType, |
|
| 2510 | + 'colBaseType' => $colBaseType, // Adding base type for easier processing in derived classes |
|
| 2511 | + 'default' => $default, |
|
| 2512 | + 'required' => $required, |
|
| 2513 | + 'auto_increment' => $auto_increment, |
|
| 2514 | + 'full' => "$name $colType $default $required $auto_increment", |
|
| 2515 | + ); |
|
| 2516 | + } else { |
|
| 2517 | + return "$name $colType $default $required $auto_increment"; |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + /** |
|
| 2522 | + * Returns SQL defintions for all columns in a table |
|
| 2523 | + * |
|
| 2524 | + * @param array $fieldDefs Vardef-format field def |
|
| 2525 | + * @param bool $ignoreRequired Optional, true if we should ignor this being a required field |
|
| 2526 | + * @param string $tablename Optional, table name |
|
| 2527 | + * @return string SQL column definitions |
|
| 2528 | + */ |
|
| 2529 | + protected function columnSQLRep($fieldDefs, $ignoreRequired = false, $tablename) |
|
| 2530 | + { |
|
| 2531 | + $columns = array(); |
|
| 2532 | + |
|
| 2533 | + if ($this->isFieldArray($fieldDefs)) { |
|
| 2534 | + foreach ($fieldDefs as $fieldDef) { |
|
| 2535 | + if(!isset($fieldDef['source']) || $fieldDef['source'] == 'db') { |
|
| 2536 | + $columns[] = $this->oneColumnSQLRep($fieldDef,false, $tablename); |
|
| 2537 | + } |
|
| 2538 | + } |
|
| 2539 | + $columns = implode(",", $columns); |
|
| 2540 | + } |
|
| 2541 | + else { |
|
| 2542 | + $columns = $this->oneColumnSQLRep($fieldDefs,$ignoreRequired, $tablename); |
|
| 2543 | + } |
|
| 2544 | + |
|
| 2545 | + return $columns; |
|
| 2546 | + } |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * Returns the next value for an auto increment |
|
| 2550 | + * @abstract |
|
| 2551 | + * @param string $table Table name |
|
| 2552 | + * @param string $field_name Field name |
|
| 2553 | + * @return string |
|
| 2554 | + */ |
|
| 2555 | + public function getAutoIncrement($table, $field_name) |
|
| 2556 | + { |
|
| 2557 | + return ""; |
|
| 2558 | + } |
|
| 2559 | + |
|
| 2560 | + /** |
|
| 2561 | + * Returns the sql for the next value in a sequence |
|
| 2562 | + * @abstract |
|
| 2563 | + * @param string $table Table name |
|
| 2564 | + * @param string $field_name Field name |
|
| 2565 | + * @return string |
|
| 2566 | + */ |
|
| 2567 | + public function getAutoIncrementSQL($table, $field_name) |
|
| 2568 | + { |
|
| 2569 | + return ""; |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + /** |
|
| 2573 | + * Either creates an auto increment through queries or returns sql for auto increment |
|
| 2574 | + * that can be appended to the end of column defination (mysql) |
|
| 2575 | + * @abstract |
|
| 2576 | + * @param string $table Table name |
|
| 2577 | + * @param string $field_name Field name |
|
| 2578 | + * @return string |
|
| 2579 | + */ |
|
| 2580 | + protected function setAutoIncrement($table, $field_name) |
|
| 2581 | + { |
|
| 2582 | + $this->deleteAutoIncrement($table, $field_name); |
|
| 2583 | + return ""; |
|
| 2584 | + } |
|
| 2585 | + |
|
| 2586 | + /** |
|
| 2587 | + * Sets the next auto-increment value of a column to a specific value. |
|
| 2588 | + * @abstract |
|
| 2589 | + * @param string $table Table name |
|
| 2590 | + * @param string $field_name Field name |
|
| 2591 | + * @param int $start_value Starting autoincrement value |
|
| 2592 | + * @return string |
|
| 2593 | + * |
|
| 2594 | + */ |
|
| 2595 | + public function setAutoIncrementStart($table, $field_name, $start_value) |
|
| 2596 | + { |
|
| 2597 | + return ""; |
|
| 2598 | + } |
|
| 2599 | + |
|
| 2600 | + /** |
|
| 2601 | + * Deletes an auto increment |
|
| 2602 | + * @abstract |
|
| 2603 | + * @param string $table tablename |
|
| 2604 | + * @param string $field_name |
|
| 2605 | + */ |
|
| 2606 | + public function deleteAutoIncrement($table, $field_name) |
|
| 2607 | + { |
|
| 2608 | + return; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + /** |
|
| 2612 | + * This method generates sql for adding a column to table identified by field def. |
|
| 2613 | + * |
|
| 2614 | + * @param string $tablename |
|
| 2615 | + * @param array $fieldDefs |
|
| 2616 | + * @return string SQL statement |
|
| 2617 | + */ |
|
| 2618 | + public function addColumnSQL($tablename, $fieldDefs) |
|
| 2619 | + { |
|
| 2620 | + return $this->changeColumnSQL($tablename, $fieldDefs, 'add'); |
|
| 2621 | + } |
|
| 2622 | + |
|
| 2623 | + /** |
|
| 2624 | + * This method genrates sql for altering old column identified by oldFieldDef to new fieldDef. |
|
| 2625 | + * |
|
| 2626 | + * @param string $tablename |
|
| 2627 | + * @param array $newFieldDefs |
|
| 2628 | + * @param bool $ignorerequired Optional, true if we should ignor this being a required field |
|
| 2629 | + * @return string|array SQL statement(s) |
|
| 2630 | + */ |
|
| 2631 | + public function alterColumnSQL($tablename, $newFieldDefs, $ignorerequired = false) |
|
| 2632 | + { |
|
| 2633 | + return $this->changeColumnSQL($tablename, $newFieldDefs, 'modify', $ignorerequired); |
|
| 2634 | + } |
|
| 2247 | 2635 | |
| 2248 | 2636 | /** |
| 2249 | - * Generates SQL for select statement for any bean identified by id. |
|
| 2637 | + * Generates SQL for dropping a table. |
|
| 2250 | 2638 | * |
| 2251 | - * @param SugarBean $bean SugarBean instance |
|
| 2252 | - * @param array $where where conditions in an array |
|
| 2253 | - * @return string SQL Select Statement |
|
| 2639 | + * @param SugarBean $bean Sugarbean instance |
|
| 2640 | + * @return string SQL statement |
|
| 2254 | 2641 | */ |
| 2255 | - public function retrieveSQL(SugarBean $bean, array $where) |
|
| 2256 | - { |
|
| 2257 | - $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
|
| 2258 | - return "SELECT * FROM ".$bean->getTableName()." $where AND deleted=0"; |
|
| 2259 | - } |
|
| 2642 | + public function dropTableSQL(SugarBean $bean) |
|
| 2643 | + { |
|
| 2644 | + return $this->dropTableNameSQL($bean->getTableName()); |
|
| 2645 | + } |
|
| 2260 | 2646 | |
| 2261 | 2647 | /** |
| 2262 | - * This method implements a generic sql for a collection of beans. |
|
| 2648 | + * Generates SQL for dropping a table. |
|
| 2263 | 2649 | * |
| 2264 | - * Currently, this function does not support outer joins. |
|
| 2650 | + * @param string $name table name |
|
| 2651 | + * @return string SQL statement |
|
| 2652 | + */ |
|
| 2653 | + public function dropTableNameSQL($name) |
|
| 2654 | + { |
|
| 2655 | + return "DROP TABLE ".$name; |
|
| 2656 | + } |
|
| 2657 | + |
|
| 2658 | + /** |
|
| 2659 | + * Generates SQL for truncating a table. |
|
| 2660 | + * @param string $name table name |
|
| 2661 | + * @return string |
|
| 2662 | + */ |
|
| 2663 | + public function truncateTableSQL($name) |
|
| 2664 | + { |
|
| 2665 | + return "TRUNCATE $name"; |
|
| 2666 | + } |
|
| 2667 | + |
|
| 2668 | + /** |
|
| 2669 | + * This method generates sql that deletes a column identified by fieldDef. |
|
| 2265 | 2670 | * |
| 2266 | - * @param array $beans Array of values returned by get_class method as the keys and a bean as |
|
| 2267 | - * the value for that key. These beans will be joined in the sql by the key |
|
| 2268 | - * attribute of field defs. |
|
| 2269 | - * @param array $cols Optional, columns to be returned with the keys as names of bean |
|
| 2270 | - * as identified by get_class of bean. Values of this array is the array of fieldDefs |
|
| 2271 | - * to be returned for a bean. If an empty array is passed, all columns are selected. |
|
| 2272 | - * @param array $whereClause Optional, values with the keys as names of bean as identified |
|
| 2273 | - * by get_class of bean. Each value at the first level is an array of values for that |
|
| 2274 | - * bean identified by name of fields. If we want to pass multiple values for a name, |
|
| 2275 | - * pass it as an array. If where is not passed, all the rows will be returned. |
|
| 2671 | + * @param SugarBean $bean Sugarbean instance |
|
| 2672 | + * @param array $fieldDefs |
|
| 2673 | + * @return string SQL statement |
|
| 2674 | + */ |
|
| 2675 | + public function deleteColumnSQL(SugarBean $bean, $fieldDefs) |
|
| 2676 | + { |
|
| 2677 | + return $this->dropColumnSQL($bean->getTableName(), $fieldDefs); |
|
| 2678 | + } |
|
| 2679 | + |
|
| 2680 | + /** |
|
| 2681 | + * This method generates sql that drops a column identified by fieldDef. |
|
| 2682 | + * Designed to work like the other addColumnSQL() and alterColumnSQL() functions |
|
| 2276 | 2683 | * |
| 2277 | - * @return string SQL Select Statement |
|
| 2684 | + * @param string $tablename |
|
| 2685 | + * @param array $fieldDefs |
|
| 2686 | + * @return string SQL statement |
|
| 2278 | 2687 | */ |
| 2279 | - public function retrieveViewSQL(array $beans, array $cols = array(), array $whereClause = array()) |
|
| 2280 | - { |
|
| 2281 | - $relations = array(); // stores relations between tables as they are discovered |
|
| 2282 | - $where = $select = array(); |
|
| 2283 | - foreach ($beans as $beanID => $bean) { |
|
| 2284 | - $tableName = $bean->getTableName(); |
|
| 2285 | - $beanTables[$beanID] = $tableName; |
|
| 2286 | - |
|
| 2287 | - $table = $beanID; |
|
| 2288 | - $tables[$table] = $tableName; |
|
| 2289 | - $aliases[$tableName][] = $table; |
|
| 2290 | - |
|
| 2291 | - // build part of select for this table |
|
| 2292 | - if (is_array($cols[$beanID])) |
|
| 2293 | - foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
|
| 2294 | - |
|
| 2295 | - // build part of where clause |
|
| 2296 | - if (is_array($whereClause[$beanID])){ |
|
| 2297 | - $where[] = $this->getColumnWhereClause($table, $whereClause[$beanID]); |
|
| 2298 | - } |
|
| 2299 | - // initialize so that it can be used properly in form clause generation |
|
| 2300 | - $table_used_in_from[$table] = false; |
|
| 2301 | - |
|
| 2302 | - $indices = $bean->getIndices(); |
|
| 2303 | - foreach ($indices as $index){ |
|
| 2304 | - if ($index['type'] == 'foreign') { |
|
| 2305 | - $relationship[$table][] = array('foreignTable'=> $index['foreignTable'] |
|
| 2306 | - ,'foreignColumn'=>$index['foreignField'] |
|
| 2307 | - ,'localColumn'=> $index['fields'] |
|
| 2308 | - ); |
|
| 2309 | - } |
|
| 2310 | - } |
|
| 2311 | - $where[] = " $table.deleted = 0"; |
|
| 2312 | - } |
|
| 2313 | - |
|
| 2314 | - // join these clauses |
|
| 2315 | - $select = !empty($select) ? implode(",", $select) : "*"; |
|
| 2316 | - $where = implode(" AND ", $where); |
|
| 2317 | - |
|
| 2318 | - // generate the from clause. Use relations array to generate outer joins |
|
| 2319 | - // all the rest of the tables will be used as a simple from |
|
| 2320 | - // relations table define relations between table1 and table2 through column on table 1 |
|
| 2321 | - // table2 is assumed to joining through primary key called id |
|
| 2322 | - $separator = ""; |
|
| 2323 | - $from = ''; $table_used_in_from = array(); |
|
| 2324 | - foreach ($relations as $table1 => $rightsidearray){ |
|
| 2325 | - if ($table_used_in_from[$table1]) continue; // table has been joined |
|
| 2326 | - |
|
| 2327 | - $from .= $separator." ".$table1; |
|
| 2328 | - $table_used_in_from[$table1] = true; |
|
| 2329 | - foreach ($rightsidearray as $tablearray){ |
|
| 2330 | - $table2 = $tablearray['foreignTable']; // get foreign table |
|
| 2331 | - $tableAlias = $aliases[$table2]; // get a list of aliases for this table |
|
| 2332 | - foreach ($tableAlias as $table2) { |
|
| 2333 | - //choose first alias that does not match |
|
| 2334 | - // we are doing this because of self joins. |
|
| 2335 | - // in case of self joins, the same table will have many aliases. |
|
| 2336 | - if ($table2 != $table1) break; |
|
| 2337 | - } |
|
| 2338 | - |
|
| 2339 | - $col = $tablearray['foreingColumn']; |
|
| 2340 | - $name = $tablearray['localColumn']; |
|
| 2341 | - $from .= " LEFT JOIN $table on ($table1.$name = $table2.$col)"; |
|
| 2342 | - $table_used_in_from[$table2] = true; |
|
| 2343 | - } |
|
| 2344 | - $separator = ","; |
|
| 2345 | - } |
|
| 2346 | - |
|
| 2347 | - return "SELECT $select FROM $from WHERE $where"; |
|
| 2348 | - } |
|
| 2349 | - |
|
| 2350 | - /** |
|
| 2351 | - * Generates SQL for create index statement for a bean. |
|
| 2352 | - * |
|
| 2353 | - * @param SugarBean $bean SugarBean instance |
|
| 2354 | - * @param array $fields fields used in the index |
|
| 2355 | - * @param string $name index name |
|
| 2356 | - * @param bool $unique Optional, set to true if this is an unique index |
|
| 2357 | - * @return string SQL Select Statement |
|
| 2358 | - */ |
|
| 2359 | - public function createIndexSQL(SugarBean $bean, array $fields, $name, $unique = true) |
|
| 2360 | - { |
|
| 2361 | - $unique = ($unique) ? "unique" : ""; |
|
| 2362 | - $tablename = $bean->getTableName(); |
|
| 2363 | - $columns = array(); |
|
| 2364 | - // get column names |
|
| 2365 | - foreach ($fields as $fieldDef) |
|
| 2366 | - $columns[] = $fieldDef['name']; |
|
| 2367 | - |
|
| 2368 | - if (empty($columns)) |
|
| 2369 | - return ""; |
|
| 2370 | - |
|
| 2371 | - $columns = implode(",", $columns); |
|
| 2372 | - |
|
| 2373 | - return "CREATE $unique INDEX $name ON $tablename ($columns)"; |
|
| 2374 | - } |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * Returns the type of the variable in the field |
|
| 2378 | - * |
|
| 2379 | - * @param array $fieldDef Vardef-format field def |
|
| 2380 | - * @return string |
|
| 2381 | - */ |
|
| 2382 | - public function getFieldType($fieldDef) |
|
| 2383 | - { |
|
| 2384 | - // get the type for db type. if that is not set, |
|
| 2385 | - // get it from type. This is done so that |
|
| 2386 | - // we do not have change a lot of existing code |
|
| 2387 | - // and add dbtype where type is being used for some special |
|
| 2388 | - // purposes like referring to foreign table etc. |
|
| 2389 | - if(!empty($fieldDef['dbType'])) |
|
| 2390 | - return $fieldDef['dbType']; |
|
| 2391 | - if(!empty($fieldDef['dbtype'])) |
|
| 2392 | - return $fieldDef['dbtype']; |
|
| 2393 | - if (!empty($fieldDef['type'])) |
|
| 2394 | - return $fieldDef['type']; |
|
| 2395 | - if (!empty($fieldDef['Type'])) |
|
| 2396 | - return $fieldDef['Type']; |
|
| 2397 | - if (!empty($fieldDef['data_type'])) |
|
| 2398 | - return $fieldDef['data_type']; |
|
| 2399 | - |
|
| 2400 | - return null; |
|
| 2401 | - } |
|
| 2688 | + public function dropColumnSQL($tablename, $fieldDefs) |
|
| 2689 | + { |
|
| 2690 | + return $this->changeColumnSQL($tablename, $fieldDefs, 'drop'); |
|
| 2691 | + } |
|
| 2402 | 2692 | |
| 2403 | 2693 | /** |
| 2404 | - * retrieves the different components from the passed column type as it is used in the type mapping and vardefs |
|
| 2405 | - * type format: <baseType>[(<len>[,<scale>])] |
|
| 2406 | - * @param string $type Column type |
|
| 2407 | - * @return array|bool array containing the different components of the passed in type or false in case the type contains illegal characters |
|
| 2694 | + * Return a version of $proposed that can be used as a column name in any of our supported databases |
|
| 2695 | + * Practically this means no longer than 25 characters as the smallest identifier length for our supported DBs is 30 chars for Oracle plus we add on at least four characters in some places (for indicies for example) |
|
| 2696 | + * @param string|array $name Proposed name for the column |
|
| 2697 | + * @param bool|string $ensureUnique Ensure the name is unique |
|
| 2698 | + * @param string $type Name type (table, column) |
|
| 2699 | + * @param bool $force Force new name |
|
| 2700 | + * @return string|array Valid column name trimmed to right length and with invalid characters removed |
|
| 2408 | 2701 | */ |
| 2409 | - public function getTypeParts($type) |
|
| 2702 | + public function getValidDBName($name, $ensureUnique = false, $type = 'column', $force = false) |
|
| 2410 | 2703 | { |
| 2411 | - if(preg_match("#(?P<type>\w+)\s*(?P<arg>\((?P<len>\w+)\s*(,\s*(?P<scale>\d+))*\))*#", $type, $matches)) |
|
| 2412 | - { |
|
| 2413 | - $return = array(); // Not returning matches array as such as we don't want to expose the regex make up on the interface |
|
| 2414 | - $return['baseType'] = $matches['type']; |
|
| 2415 | - if( isset($matches['arg'])) { |
|
| 2416 | - $return['arg'] = $matches['arg']; |
|
| 2704 | + if(is_array($name)) { |
|
| 2705 | + $result = array(); |
|
| 2706 | + foreach($name as $field) { |
|
| 2707 | + $result[] = $this->getValidDBName($field, $ensureUnique, $type); |
|
| 2417 | 2708 | } |
| 2418 | - if( isset($matches['len'])) { |
|
| 2419 | - $return['len'] = $matches['len']; |
|
| 2709 | + return $result; |
|
| 2710 | + } else { |
|
| 2711 | + if(strchr($name, ".")) { |
|
| 2712 | + // this is a compound name with dots, handle separately |
|
| 2713 | + $parts = explode(".", $name); |
|
| 2714 | + if(count($parts) > 2) { |
|
| 2715 | + // some weird name, cut to table.name |
|
| 2716 | + array_splice($parts, 0, count($parts)-2); |
|
| 2717 | + } |
|
| 2718 | + $parts = $this->getValidDBName($parts, $ensureUnique, $type, $force); |
|
| 2719 | + return join(".", $parts); |
|
| 2420 | 2720 | } |
| 2421 | - if( isset($matches['scale'])) { |
|
| 2422 | - $return['scale'] = $matches['scale']; |
|
| 2721 | + // first strip any invalid characters - all but word chars (which is alphanumeric and _) |
|
| 2722 | + $name = preg_replace( '/[^\w]+/i', '', $name ) ; |
|
| 2723 | + $len = strlen( $name ) ; |
|
| 2724 | + $maxLen = empty($this->maxNameLengths[$type]) ? $this->maxNameLengths[$type]['column'] : $this->maxNameLengths[$type]; |
|
| 2725 | + if ($len <= $maxLen && !$force) { |
|
| 2726 | + return strtolower($name); |
|
| 2727 | + } |
|
| 2728 | + if ($ensureUnique) { |
|
| 2729 | + $md5str = md5($name); |
|
| 2730 | + $tail = substr ( $name, -11) ; |
|
| 2731 | + $temp = substr($md5str , strlen($md5str)-4 ); |
|
| 2732 | + $result = substr( $name, 0, 10) . $temp . $tail ; |
|
| 2733 | + } else { |
|
| 2734 | + $result = substr( $name, 0, 11) . substr( $name, 11 - $maxLen); |
|
| 2423 | 2735 | } |
| 2424 | - return $return; |
|
| 2425 | - } else { |
|
| 2426 | - return false; |
|
| 2427 | - } |
|
| 2428 | - } |
|
| 2429 | - |
|
| 2430 | - /** |
|
| 2431 | - * Returns the defintion for a single column |
|
| 2432 | - * |
|
| 2433 | - * @param array $fieldDef Vardef-format field def |
|
| 2434 | - * @param bool $ignoreRequired Optional, true if we should ignore this being a required field |
|
| 2435 | - * @param string $table Optional, table name |
|
| 2436 | - * @param bool $return_as_array Optional, true if we should return the result as an array instead of sql |
|
| 2437 | - * @return string or array if $return_as_array is true |
|
| 2438 | - */ |
|
| 2439 | - protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
| 2440 | - { |
|
| 2441 | - $name = $fieldDef['name']; |
|
| 2442 | - $type = $this->getFieldType($fieldDef); |
|
| 2443 | - $colType = $this->getColumnType($type); |
|
| 2444 | 2736 | |
| 2445 | - if($parts = $this->getTypeParts($colType)) |
|
| 2446 | - { |
|
| 2447 | - $colBaseType = $parts['baseType']; |
|
| 2448 | - $defLen = isset($parts['len']) ? $parts['len'] : '255'; // Use the mappings length (precision) as default if it exists |
|
| 2737 | + return strtolower( $result ) ; |
|
| 2449 | 2738 | } |
| 2739 | + } |
|
| 2450 | 2740 | |
| 2451 | - if(!empty($fieldDef['len'])) { |
|
| 2452 | - if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char', |
|
| 2453 | - 'clob', 'blob', 'text'))) { |
|
| 2454 | - $colType = "$colBaseType(${fieldDef['len']})"; |
|
| 2455 | - } elseif(($colBaseType == 'decimal' || $colBaseType == 'float')){ |
|
| 2456 | - if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) |
|
| 2457 | - if(strpos($fieldDef['len'],',') === false){ |
|
| 2458 | - $colType = $colBaseType . "(".$fieldDef['len'].",".$fieldDef['precision'].")"; |
|
| 2459 | - }else{ |
|
| 2460 | - $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2461 | - } |
|
| 2462 | - else |
|
| 2463 | - $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2464 | - } |
|
| 2465 | - } else { |
|
| 2466 | - if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) { |
|
| 2467 | - $colType = "$colBaseType($defLen)"; |
|
| 2468 | - } |
|
| 2469 | - } |
|
| 2741 | + /** |
|
| 2742 | + * Returns the valid type for a column given the type in fieldDef |
|
| 2743 | + * |
|
| 2744 | + * @param string $type field type |
|
| 2745 | + * @return string valid type for the given field |
|
| 2746 | + */ |
|
| 2747 | + public function getColumnType($type) |
|
| 2748 | + { |
|
| 2749 | + return isset($this->type_map[$type])?$this->type_map[$type]:$type; |
|
| 2750 | + } |
|
| 2470 | 2751 | |
| 2471 | - $default = ''; |
|
| 2752 | + /** |
|
| 2753 | + * Checks to see if passed array is truely an array of defitions |
|
| 2754 | + * |
|
| 2755 | + * Such an array may have type as a key but it will point to an array |
|
| 2756 | + * for a true array of definitions an to a col type for a definition only |
|
| 2757 | + * |
|
| 2758 | + * @param mixed $defArray |
|
| 2759 | + * @return bool |
|
| 2760 | + */ |
|
| 2761 | + public function isFieldArray($defArray) |
|
| 2762 | + { |
|
| 2763 | + if ( !is_array($defArray) ) |
|
| 2764 | + return false; |
|
| 2472 | 2765 | |
| 2473 | - // Bug #52610 We should have ability don't add DEFAULT part to query for boolean fields |
|
| 2474 | - if (!empty($fieldDef['no_default'])) |
|
| 2475 | - { |
|
| 2476 | - // nothing to do |
|
| 2477 | - } |
|
| 2478 | - elseif (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) |
|
| 2479 | - { |
|
| 2480 | - $default = " DEFAULT ".$this->quoted($fieldDef['default']); |
|
| 2481 | - } |
|
| 2482 | - elseif (!isset($default) && $type == 'bool') |
|
| 2483 | - { |
|
| 2484 | - $default = " DEFAULT 0 "; |
|
| 2766 | + if ( isset($defArray['type']) ){ |
|
| 2767 | + // type key exists. May be an array of defs or a simple definition |
|
| 2768 | + return is_array($defArray['type']); // type is not an array => definition else array |
|
| 2485 | 2769 | } |
| 2486 | 2770 | |
| 2487 | - $auto_increment = ''; |
|
| 2488 | - if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) |
|
| 2489 | - $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
| 2490 | - |
|
| 2491 | - $required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify |
|
| 2492 | - //Starting in 6.0, only ID and auto_increment fields will be NOT NULL in the DB. |
|
| 2493 | - if ((empty($fieldDef['isnull']) || strtolower($fieldDef['isnull']) == 'false') && |
|
| 2494 | - (!empty($auto_increment) || $name == 'id' || ($fieldDef['type'] == 'id' && !empty($fieldDef['required'])))) { |
|
| 2495 | - $required = "NOT NULL"; |
|
| 2496 | - } |
|
| 2497 | - // If the field is marked both required & isnull=>false - alwqys make it not null |
|
| 2498 | - // Use this to ensure primary key fields never defined as null |
|
| 2499 | - if(isset($fieldDef['isnull']) && (strtolower($fieldDef['isnull']) == 'false' || $fieldDef['isnull'] === false) |
|
| 2500 | - && !empty($fieldDef['required'])) { |
|
| 2501 | - $required = "NOT NULL"; |
|
| 2502 | - } |
|
| 2503 | - if ($ignoreRequired) |
|
| 2504 | - $required = ""; |
|
| 2505 | - |
|
| 2506 | - if ( $return_as_array ) { |
|
| 2507 | - return array( |
|
| 2508 | - 'name' => $name, |
|
| 2509 | - 'colType' => $colType, |
|
| 2510 | - 'colBaseType' => $colBaseType, // Adding base type for easier processing in derived classes |
|
| 2511 | - 'default' => $default, |
|
| 2512 | - 'required' => $required, |
|
| 2513 | - 'auto_increment' => $auto_increment, |
|
| 2514 | - 'full' => "$name $colType $default $required $auto_increment", |
|
| 2515 | - ); |
|
| 2516 | - } else { |
|
| 2517 | - return "$name $colType $default $required $auto_increment"; |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - /** |
|
| 2522 | - * Returns SQL defintions for all columns in a table |
|
| 2523 | - * |
|
| 2524 | - * @param array $fieldDefs Vardef-format field def |
|
| 2525 | - * @param bool $ignoreRequired Optional, true if we should ignor this being a required field |
|
| 2526 | - * @param string $tablename Optional, table name |
|
| 2527 | - * @return string SQL column definitions |
|
| 2528 | - */ |
|
| 2529 | - protected function columnSQLRep($fieldDefs, $ignoreRequired = false, $tablename) |
|
| 2530 | - { |
|
| 2531 | - $columns = array(); |
|
| 2532 | - |
|
| 2533 | - if ($this->isFieldArray($fieldDefs)) { |
|
| 2534 | - foreach ($fieldDefs as $fieldDef) { |
|
| 2535 | - if(!isset($fieldDef['source']) || $fieldDef['source'] == 'db') { |
|
| 2536 | - $columns[] = $this->oneColumnSQLRep($fieldDef,false, $tablename); |
|
| 2537 | - } |
|
| 2538 | - } |
|
| 2539 | - $columns = implode(",", $columns); |
|
| 2540 | - } |
|
| 2541 | - else { |
|
| 2542 | - $columns = $this->oneColumnSQLRep($fieldDefs,$ignoreRequired, $tablename); |
|
| 2543 | - } |
|
| 2544 | - |
|
| 2545 | - return $columns; |
|
| 2546 | - } |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * Returns the next value for an auto increment |
|
| 2550 | - * @abstract |
|
| 2551 | - * @param string $table Table name |
|
| 2552 | - * @param string $field_name Field name |
|
| 2553 | - * @return string |
|
| 2554 | - */ |
|
| 2555 | - public function getAutoIncrement($table, $field_name) |
|
| 2556 | - { |
|
| 2557 | - return ""; |
|
| 2558 | - } |
|
| 2559 | - |
|
| 2560 | - /** |
|
| 2561 | - * Returns the sql for the next value in a sequence |
|
| 2562 | - * @abstract |
|
| 2563 | - * @param string $table Table name |
|
| 2564 | - * @param string $field_name Field name |
|
| 2565 | - * @return string |
|
| 2566 | - */ |
|
| 2567 | - public function getAutoIncrementSQL($table, $field_name) |
|
| 2568 | - { |
|
| 2569 | - return ""; |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - /** |
|
| 2573 | - * Either creates an auto increment through queries or returns sql for auto increment |
|
| 2574 | - * that can be appended to the end of column defination (mysql) |
|
| 2575 | - * @abstract |
|
| 2576 | - * @param string $table Table name |
|
| 2577 | - * @param string $field_name Field name |
|
| 2578 | - * @return string |
|
| 2579 | - */ |
|
| 2580 | - protected function setAutoIncrement($table, $field_name) |
|
| 2581 | - { |
|
| 2582 | - $this->deleteAutoIncrement($table, $field_name); |
|
| 2583 | - return ""; |
|
| 2584 | - } |
|
| 2771 | + // type does not exist. Must be array of definitions |
|
| 2772 | + return true; |
|
| 2773 | + } |
|
| 2585 | 2774 | |
| 2586 | 2775 | /** |
| 2587 | - * Sets the next auto-increment value of a column to a specific value. |
|
| 2588 | - * @abstract |
|
| 2589 | - * @param string $table Table name |
|
| 2590 | - * @param string $field_name Field name |
|
| 2591 | - * @param int $start_value Starting autoincrement value |
|
| 2592 | - * @return string |
|
| 2776 | + * returns true if the type can be mapped to a valid column type |
|
| 2593 | 2777 | * |
| 2778 | + * @param string $type |
|
| 2779 | + * @return bool |
|
| 2594 | 2780 | */ |
| 2595 | - public function setAutoIncrementStart($table, $field_name, $start_value) |
|
| 2596 | - { |
|
| 2597 | - return ""; |
|
| 2598 | - } |
|
| 2599 | - |
|
| 2600 | - /** |
|
| 2601 | - * Deletes an auto increment |
|
| 2602 | - * @abstract |
|
| 2603 | - * @param string $table tablename |
|
| 2604 | - * @param string $field_name |
|
| 2605 | - */ |
|
| 2606 | - public function deleteAutoIncrement($table, $field_name) |
|
| 2607 | - { |
|
| 2608 | - return; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - /** |
|
| 2612 | - * This method generates sql for adding a column to table identified by field def. |
|
| 2613 | - * |
|
| 2614 | - * @param string $tablename |
|
| 2615 | - * @param array $fieldDefs |
|
| 2616 | - * @return string SQL statement |
|
| 2617 | - */ |
|
| 2618 | - public function addColumnSQL($tablename, $fieldDefs) |
|
| 2619 | - { |
|
| 2620 | - return $this->changeColumnSQL($tablename, $fieldDefs, 'add'); |
|
| 2621 | - } |
|
| 2622 | - |
|
| 2623 | - /** |
|
| 2624 | - * This method genrates sql for altering old column identified by oldFieldDef to new fieldDef. |
|
| 2625 | - * |
|
| 2626 | - * @param string $tablename |
|
| 2627 | - * @param array $newFieldDefs |
|
| 2628 | - * @param bool $ignorerequired Optional, true if we should ignor this being a required field |
|
| 2629 | - * @return string|array SQL statement(s) |
|
| 2630 | - */ |
|
| 2631 | - public function alterColumnSQL($tablename, $newFieldDefs, $ignorerequired = false) |
|
| 2632 | - { |
|
| 2633 | - return $this->changeColumnSQL($tablename, $newFieldDefs, 'modify', $ignorerequired); |
|
| 2634 | - } |
|
| 2635 | - |
|
| 2636 | - /** |
|
| 2637 | - * Generates SQL for dropping a table. |
|
| 2638 | - * |
|
| 2639 | - * @param SugarBean $bean Sugarbean instance |
|
| 2640 | - * @return string SQL statement |
|
| 2641 | - */ |
|
| 2642 | - public function dropTableSQL(SugarBean $bean) |
|
| 2643 | - { |
|
| 2644 | - return $this->dropTableNameSQL($bean->getTableName()); |
|
| 2645 | - } |
|
| 2646 | - |
|
| 2647 | - /** |
|
| 2648 | - * Generates SQL for dropping a table. |
|
| 2649 | - * |
|
| 2650 | - * @param string $name table name |
|
| 2651 | - * @return string SQL statement |
|
| 2652 | - */ |
|
| 2653 | - public function dropTableNameSQL($name) |
|
| 2654 | - { |
|
| 2655 | - return "DROP TABLE ".$name; |
|
| 2656 | - } |
|
| 2657 | - |
|
| 2658 | - /** |
|
| 2659 | - * Generates SQL for truncating a table. |
|
| 2660 | - * @param string $name table name |
|
| 2661 | - * @return string |
|
| 2662 | - */ |
|
| 2663 | - public function truncateTableSQL($name) |
|
| 2664 | - { |
|
| 2665 | - return "TRUNCATE $name"; |
|
| 2666 | - } |
|
| 2667 | - |
|
| 2668 | - /** |
|
| 2669 | - * This method generates sql that deletes a column identified by fieldDef. |
|
| 2670 | - * |
|
| 2671 | - * @param SugarBean $bean Sugarbean instance |
|
| 2672 | - * @param array $fieldDefs |
|
| 2673 | - * @return string SQL statement |
|
| 2674 | - */ |
|
| 2675 | - public function deleteColumnSQL(SugarBean $bean, $fieldDefs) |
|
| 2676 | - { |
|
| 2677 | - return $this->dropColumnSQL($bean->getTableName(), $fieldDefs); |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - /** |
|
| 2681 | - * This method generates sql that drops a column identified by fieldDef. |
|
| 2682 | - * Designed to work like the other addColumnSQL() and alterColumnSQL() functions |
|
| 2683 | - * |
|
| 2684 | - * @param string $tablename |
|
| 2685 | - * @param array $fieldDefs |
|
| 2686 | - * @return string SQL statement |
|
| 2687 | - */ |
|
| 2688 | - public function dropColumnSQL($tablename, $fieldDefs) |
|
| 2689 | - { |
|
| 2690 | - return $this->changeColumnSQL($tablename, $fieldDefs, 'drop'); |
|
| 2691 | - } |
|
| 2781 | + protected function validColumnType($type) |
|
| 2782 | + { |
|
| 2783 | + $type = $this->getColumnType($type); |
|
| 2784 | + return !empty($type); |
|
| 2785 | + } |
|
| 2692 | 2786 | |
| 2693 | 2787 | /** |
| 2694 | - * Return a version of $proposed that can be used as a column name in any of our supported databases |
|
| 2695 | - * Practically this means no longer than 25 characters as the smallest identifier length for our supported DBs is 30 chars for Oracle plus we add on at least four characters in some places (for indicies for example) |
|
| 2696 | - * @param string|array $name Proposed name for the column |
|
| 2697 | - * @param bool|string $ensureUnique Ensure the name is unique |
|
| 2698 | - * @param string $type Name type (table, column) |
|
| 2699 | - * @param bool $force Force new name |
|
| 2700 | - * @return string|array Valid column name trimmed to right length and with invalid characters removed |
|
| 2701 | - */ |
|
| 2702 | - public function getValidDBName($name, $ensureUnique = false, $type = 'column', $force = false) |
|
| 2703 | - { |
|
| 2704 | - if(is_array($name)) { |
|
| 2705 | - $result = array(); |
|
| 2706 | - foreach($name as $field) { |
|
| 2707 | - $result[] = $this->getValidDBName($field, $ensureUnique, $type); |
|
| 2708 | - } |
|
| 2709 | - return $result; |
|
| 2710 | - } else { |
|
| 2711 | - if(strchr($name, ".")) { |
|
| 2712 | - // this is a compound name with dots, handle separately |
|
| 2713 | - $parts = explode(".", $name); |
|
| 2714 | - if(count($parts) > 2) { |
|
| 2715 | - // some weird name, cut to table.name |
|
| 2716 | - array_splice($parts, 0, count($parts)-2); |
|
| 2717 | - } |
|
| 2718 | - $parts = $this->getValidDBName($parts, $ensureUnique, $type, $force); |
|
| 2719 | - return join(".", $parts); |
|
| 2720 | - } |
|
| 2721 | - // first strip any invalid characters - all but word chars (which is alphanumeric and _) |
|
| 2722 | - $name = preg_replace( '/[^\w]+/i', '', $name ) ; |
|
| 2723 | - $len = strlen( $name ) ; |
|
| 2724 | - $maxLen = empty($this->maxNameLengths[$type]) ? $this->maxNameLengths[$type]['column'] : $this->maxNameLengths[$type]; |
|
| 2725 | - if ($len <= $maxLen && !$force) { |
|
| 2726 | - return strtolower($name); |
|
| 2727 | - } |
|
| 2728 | - if ($ensureUnique) { |
|
| 2729 | - $md5str = md5($name); |
|
| 2730 | - $tail = substr ( $name, -11) ; |
|
| 2731 | - $temp = substr($md5str , strlen($md5str)-4 ); |
|
| 2732 | - $result = substr( $name, 0, 10) . $temp . $tail ; |
|
| 2733 | - } else { |
|
| 2734 | - $result = substr( $name, 0, 11) . substr( $name, 11 - $maxLen); |
|
| 2735 | - } |
|
| 2736 | - |
|
| 2737 | - return strtolower( $result ) ; |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - |
|
| 2741 | - /** |
|
| 2742 | - * Returns the valid type for a column given the type in fieldDef |
|
| 2743 | - * |
|
| 2744 | - * @param string $type field type |
|
| 2745 | - * @return string valid type for the given field |
|
| 2746 | - */ |
|
| 2747 | - public function getColumnType($type) |
|
| 2748 | - { |
|
| 2749 | - return isset($this->type_map[$type])?$this->type_map[$type]:$type; |
|
| 2750 | - } |
|
| 2751 | - |
|
| 2752 | - /** |
|
| 2753 | - * Checks to see if passed array is truely an array of defitions |
|
| 2754 | - * |
|
| 2755 | - * Such an array may have type as a key but it will point to an array |
|
| 2756 | - * for a true array of definitions an to a col type for a definition only |
|
| 2757 | - * |
|
| 2758 | - * @param mixed $defArray |
|
| 2759 | - * @return bool |
|
| 2760 | - */ |
|
| 2761 | - public function isFieldArray($defArray) |
|
| 2762 | - { |
|
| 2763 | - if ( !is_array($defArray) ) |
|
| 2764 | - return false; |
|
| 2765 | - |
|
| 2766 | - if ( isset($defArray['type']) ){ |
|
| 2767 | - // type key exists. May be an array of defs or a simple definition |
|
| 2768 | - return is_array($defArray['type']); // type is not an array => definition else array |
|
| 2769 | - } |
|
| 2770 | - |
|
| 2771 | - // type does not exist. Must be array of definitions |
|
| 2772 | - return true; |
|
| 2773 | - } |
|
| 2774 | - |
|
| 2775 | - /** |
|
| 2776 | - * returns true if the type can be mapped to a valid column type |
|
| 2777 | - * |
|
| 2778 | - * @param string $type |
|
| 2779 | - * @return bool |
|
| 2780 | - */ |
|
| 2781 | - protected function validColumnType($type) |
|
| 2782 | - { |
|
| 2783 | - $type = $this->getColumnType($type); |
|
| 2784 | - return !empty($type); |
|
| 2785 | - } |
|
| 2786 | - |
|
| 2787 | - /** |
|
| 2788 | - * Generate query for audit table |
|
| 2789 | - * @param SugarBean $bean SugarBean that was changed |
|
| 2790 | - * @param array $changes List of changes, contains 'before' and 'after' |
|
| 2788 | + * Generate query for audit table |
|
| 2789 | + * @param SugarBean $bean SugarBean that was changed |
|
| 2790 | + * @param array $changes List of changes, contains 'before' and 'after' |
|
| 2791 | 2791 | * @return string Audit table INSERT query |
| 2792 | 2792 | */ |
| 2793 | - protected function auditSQL(SugarBean $bean, $changes) |
|
| 2794 | - { |
|
| 2795 | - global $current_user; |
|
| 2796 | - $sql = "INSERT INTO ".$bean->get_audit_table_name(); |
|
| 2797 | - //get field defs for the audit table. |
|
| 2798 | - require('metadata/audit_templateMetaData.php'); |
|
| 2799 | - $fieldDefs = $dictionary['audit']['fields']; |
|
| 2800 | - |
|
| 2801 | - $values=array(); |
|
| 2802 | - $values['id'] = $this->massageValue(create_guid(), $fieldDefs['id']); |
|
| 2803 | - $values['parent_id']= $this->massageValue($bean->id, $fieldDefs['parent_id']); |
|
| 2804 | - $values['field_name']= $this->massageValue($changes['field_name'], $fieldDefs['field_name']); |
|
| 2805 | - $values['data_type'] = $this->massageValue($changes['data_type'], $fieldDefs['data_type']); |
|
| 2806 | - if ($changes['data_type']=='text') { |
|
| 2807 | - $values['before_value_text'] = $this->massageValue($changes['before'], $fieldDefs['before_value_text']); |
|
| 2808 | - $values['after_value_text'] = $this->massageValue($changes['after'], $fieldDefs['after_value_text']); |
|
| 2809 | - } else { |
|
| 2810 | - $values['before_value_string'] = $this->massageValue($changes['before'], $fieldDefs['before_value_string']); |
|
| 2811 | - $values['after_value_string'] = $this->massageValue($changes['after'], $fieldDefs['after_value_string']); |
|
| 2812 | - } |
|
| 2813 | - $values['date_created'] = $this->massageValue(TimeDate::getInstance()->nowDb(), $fieldDefs['date_created'] ); |
|
| 2814 | - $values['created_by'] = $this->massageValue($current_user->id, $fieldDefs['created_by']); |
|
| 2815 | - |
|
| 2816 | - $sql .= "(".implode(",", array_keys($values)).") "; |
|
| 2817 | - $sql .= "VALUES(".implode(",", $values).")"; |
|
| 2818 | - return $sql; |
|
| 2819 | - } |
|
| 2793 | + protected function auditSQL(SugarBean $bean, $changes) |
|
| 2794 | + { |
|
| 2795 | + global $current_user; |
|
| 2796 | + $sql = "INSERT INTO ".$bean->get_audit_table_name(); |
|
| 2797 | + //get field defs for the audit table. |
|
| 2798 | + require('metadata/audit_templateMetaData.php'); |
|
| 2799 | + $fieldDefs = $dictionary['audit']['fields']; |
|
| 2800 | + |
|
| 2801 | + $values=array(); |
|
| 2802 | + $values['id'] = $this->massageValue(create_guid(), $fieldDefs['id']); |
|
| 2803 | + $values['parent_id']= $this->massageValue($bean->id, $fieldDefs['parent_id']); |
|
| 2804 | + $values['field_name']= $this->massageValue($changes['field_name'], $fieldDefs['field_name']); |
|
| 2805 | + $values['data_type'] = $this->massageValue($changes['data_type'], $fieldDefs['data_type']); |
|
| 2806 | + if ($changes['data_type']=='text') { |
|
| 2807 | + $values['before_value_text'] = $this->massageValue($changes['before'], $fieldDefs['before_value_text']); |
|
| 2808 | + $values['after_value_text'] = $this->massageValue($changes['after'], $fieldDefs['after_value_text']); |
|
| 2809 | + } else { |
|
| 2810 | + $values['before_value_string'] = $this->massageValue($changes['before'], $fieldDefs['before_value_string']); |
|
| 2811 | + $values['after_value_string'] = $this->massageValue($changes['after'], $fieldDefs['after_value_string']); |
|
| 2812 | + } |
|
| 2813 | + $values['date_created'] = $this->massageValue(TimeDate::getInstance()->nowDb(), $fieldDefs['date_created'] ); |
|
| 2814 | + $values['created_by'] = $this->massageValue($current_user->id, $fieldDefs['created_by']); |
|
| 2815 | + |
|
| 2816 | + $sql .= "(".implode(",", array_keys($values)).") "; |
|
| 2817 | + $sql .= "VALUES(".implode(",", $values).")"; |
|
| 2818 | + return $sql; |
|
| 2819 | + } |
|
| 2820 | 2820 | |
| 2821 | 2821 | /** |
| 2822 | 2822 | * Saves changes to module's audit table |
@@ -2826,10 +2826,10 @@ discard block |
||
| 2826 | 2826 | * @return bool query result |
| 2827 | 2827 | * |
| 2828 | 2828 | */ |
| 2829 | - public function save_audit_records(SugarBean $bean, $changes) |
|
| 2830 | - { |
|
| 2831 | - return $this->query($this->auditSQL($bean, $changes)); |
|
| 2832 | - } |
|
| 2829 | + public function save_audit_records(SugarBean $bean, $changes) |
|
| 2830 | + { |
|
| 2831 | + return $this->query($this->auditSQL($bean, $changes)); |
|
| 2832 | + } |
|
| 2833 | 2833 | |
| 2834 | 2834 | /** |
| 2835 | 2835 | * Finds fields whose value has changed. |
@@ -2841,7 +2841,7 @@ discard block |
||
| 2841 | 2841 | * @return array |
| 2842 | 2842 | */ |
| 2843 | 2843 | public function getDataChanges(SugarBean &$bean, array $field_filter = null) |
| 2844 | - { |
|
| 2844 | + { |
|
| 2845 | 2845 | $changed_values=array(); |
| 2846 | 2846 | |
| 2847 | 2847 | $fetched_row = array(); |
@@ -2918,10 +2918,10 @@ discard block |
||
| 2918 | 2918 | } |
| 2919 | 2919 | } |
| 2920 | 2920 | } |
| 2921 | - } |
|
| 2922 | - } |
|
| 2923 | - return $changed_values; |
|
| 2924 | - } |
|
| 2921 | + } |
|
| 2922 | + } |
|
| 2923 | + return $changed_values; |
|
| 2924 | + } |
|
| 2925 | 2925 | |
| 2926 | 2926 | /** |
| 2927 | 2927 | * Uses the audit enabled fields array to find fields whose value has changed. |
@@ -2937,40 +2937,40 @@ discard block |
||
| 2937 | 2937 | return $this->getDataChanges($bean, array_keys($audit_fields)); |
| 2938 | 2938 | } |
| 2939 | 2939 | |
| 2940 | - /** |
|
| 2941 | - * Setup FT indexing |
|
| 2942 | - * @abstract |
|
| 2943 | - */ |
|
| 2944 | - public function full_text_indexing_setup() |
|
| 2945 | - { |
|
| 2946 | - // Most DBs have nothing to setup, so provide default empty function |
|
| 2947 | - } |
|
| 2948 | - |
|
| 2949 | - /** |
|
| 2950 | - * Quotes a string for storing in the database |
|
| 2951 | - * @deprecated |
|
| 2952 | - * Return value will be not surrounded by quotes |
|
| 2953 | - * |
|
| 2954 | - * @param string $string |
|
| 2955 | - * @return string |
|
| 2956 | - */ |
|
| 2957 | - public function escape_quote($string) |
|
| 2958 | - { |
|
| 2959 | - return $this->quote($string); |
|
| 2960 | - } |
|
| 2961 | - |
|
| 2962 | - /** |
|
| 2963 | - * Quotes a string for storing in the database |
|
| 2964 | - * @deprecated |
|
| 2965 | - * Return value will be not surrounded by quotes |
|
| 2966 | - * |
|
| 2967 | - * @param string $string |
|
| 2968 | - * @return string |
|
| 2969 | - */ |
|
| 2970 | - public function quoteFormEmail($string) |
|
| 2971 | - { |
|
| 2972 | - return $this->quote($string); |
|
| 2973 | - } |
|
| 2940 | + /** |
|
| 2941 | + * Setup FT indexing |
|
| 2942 | + * @abstract |
|
| 2943 | + */ |
|
| 2944 | + public function full_text_indexing_setup() |
|
| 2945 | + { |
|
| 2946 | + // Most DBs have nothing to setup, so provide default empty function |
|
| 2947 | + } |
|
| 2948 | + |
|
| 2949 | + /** |
|
| 2950 | + * Quotes a string for storing in the database |
|
| 2951 | + * @deprecated |
|
| 2952 | + * Return value will be not surrounded by quotes |
|
| 2953 | + * |
|
| 2954 | + * @param string $string |
|
| 2955 | + * @return string |
|
| 2956 | + */ |
|
| 2957 | + public function escape_quote($string) |
|
| 2958 | + { |
|
| 2959 | + return $this->quote($string); |
|
| 2960 | + } |
|
| 2961 | + |
|
| 2962 | + /** |
|
| 2963 | + * Quotes a string for storing in the database |
|
| 2964 | + * @deprecated |
|
| 2965 | + * Return value will be not surrounded by quotes |
|
| 2966 | + * |
|
| 2967 | + * @param string $string |
|
| 2968 | + * @return string |
|
| 2969 | + */ |
|
| 2970 | + public function quoteFormEmail($string) |
|
| 2971 | + { |
|
| 2972 | + return $this->quote($string); |
|
| 2973 | + } |
|
| 2974 | 2974 | |
| 2975 | 2975 | /** |
| 2976 | 2976 | * Renames an index using fields definition |
@@ -2980,49 +2980,49 @@ discard block |
||
| 2980 | 2980 | * @param string $table_name |
| 2981 | 2981 | * @return string SQL statement |
| 2982 | 2982 | */ |
| 2983 | - public function renameIndexDefs($old_definition, $new_definition, $table_name) |
|
| 2984 | - { |
|
| 2985 | - return array($this->add_drop_constraint($table_name,$old_definition,true), |
|
| 2986 | - $this->add_drop_constraint($table_name,$new_definition), false); |
|
| 2987 | - } |
|
| 2983 | + public function renameIndexDefs($old_definition, $new_definition, $table_name) |
|
| 2984 | + { |
|
| 2985 | + return array($this->add_drop_constraint($table_name,$old_definition,true), |
|
| 2986 | + $this->add_drop_constraint($table_name,$new_definition), false); |
|
| 2987 | + } |
|
| 2988 | 2988 | |
| 2989 | - /** |
|
| 2990 | - * Check if type is boolean |
|
| 2991 | - * @param string $type |
|
| 2989 | + /** |
|
| 2990 | + * Check if type is boolean |
|
| 2991 | + * @param string $type |
|
| 2992 | 2992 | * @return bool |
| 2993 | 2993 | */ |
| 2994 | - public function isBooleanType($type) |
|
| 2995 | - { |
|
| 2996 | - return 'bool' == $type; |
|
| 2997 | - } |
|
| 2994 | + public function isBooleanType($type) |
|
| 2995 | + { |
|
| 2996 | + return 'bool' == $type; |
|
| 2997 | + } |
|
| 2998 | 2998 | |
| 2999 | - /** |
|
| 3000 | - * Get truth value for boolean type |
|
| 3001 | - * Allows 'off' to mean false, along with all 'empty' values |
|
| 3002 | - * @param mixed $val |
|
| 2999 | + /** |
|
| 3000 | + * Get truth value for boolean type |
|
| 3001 | + * Allows 'off' to mean false, along with all 'empty' values |
|
| 3002 | + * @param mixed $val |
|
| 3003 | 3003 | * @return bool |
| 3004 | - */ |
|
| 3005 | - protected function _getBooleanValue($val) |
|
| 3006 | - { |
|
| 3007 | - //need to put the === sign here otherwise true == 'non empty string' |
|
| 3008 | - if (empty($val) or $val==='off') |
|
| 3009 | - return false; |
|
| 3010 | - |
|
| 3011 | - return true; |
|
| 3012 | - } |
|
| 3013 | - |
|
| 3014 | - /** |
|
| 3015 | - * Check if type is a number |
|
| 3016 | - * @param string $type |
|
| 3004 | + */ |
|
| 3005 | + protected function _getBooleanValue($val) |
|
| 3006 | + { |
|
| 3007 | + //need to put the === sign here otherwise true == 'non empty string' |
|
| 3008 | + if (empty($val) or $val==='off') |
|
| 3009 | + return false; |
|
| 3010 | + |
|
| 3011 | + return true; |
|
| 3012 | + } |
|
| 3013 | + |
|
| 3014 | + /** |
|
| 3015 | + * Check if type is a number |
|
| 3016 | + * @param string $type |
|
| 3017 | 3017 | * @return bool |
| 3018 | - */ |
|
| 3019 | - public function isNumericType($type) |
|
| 3020 | - { |
|
| 3021 | - if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3022 | - return true; |
|
| 3023 | - } |
|
| 3024 | - return false; |
|
| 3025 | - } |
|
| 3018 | + */ |
|
| 3019 | + public function isNumericType($type) |
|
| 3020 | + { |
|
| 3021 | + if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3022 | + return true; |
|
| 3023 | + } |
|
| 3024 | + return false; |
|
| 3025 | + } |
|
| 3026 | 3026 | |
| 3027 | 3027 | /** |
| 3028 | 3028 | * Check if the value is empty value for this type |
@@ -3030,272 +3030,272 @@ discard block |
||
| 3030 | 3030 | * @param string $type Type (one of vardef types) |
| 3031 | 3031 | * @return bool true if the value if empty |
| 3032 | 3032 | */ |
| 3033 | - protected function _emptyValue($val, $type) |
|
| 3034 | - { |
|
| 3035 | - if (empty($val)) |
|
| 3036 | - return true; |
|
| 3037 | - |
|
| 3038 | - if($this->emptyValue($type) == $val) { |
|
| 3039 | - return true; |
|
| 3040 | - } |
|
| 3041 | - switch ($type) { |
|
| 3042 | - case 'decimal': |
|
| 3043 | - case 'decimal2': |
|
| 3044 | - case 'int': |
|
| 3045 | - case 'double': |
|
| 3046 | - case 'float': |
|
| 3047 | - case 'uint': |
|
| 3048 | - case 'ulong': |
|
| 3049 | - case 'long': |
|
| 3050 | - case 'short': |
|
| 3051 | - return ($val == 0); |
|
| 3052 | - case 'date': |
|
| 3053 | - if ($val == '0000-00-00') |
|
| 3054 | - return true; |
|
| 3055 | - if ($val == 'NULL') |
|
| 3056 | - return true; |
|
| 3057 | - return false; |
|
| 3058 | - } |
|
| 3059 | - |
|
| 3060 | - return false; |
|
| 3061 | - } |
|
| 3062 | - |
|
| 3063 | - /** |
|
| 3033 | + protected function _emptyValue($val, $type) |
|
| 3034 | + { |
|
| 3035 | + if (empty($val)) |
|
| 3036 | + return true; |
|
| 3037 | + |
|
| 3038 | + if($this->emptyValue($type) == $val) { |
|
| 3039 | + return true; |
|
| 3040 | + } |
|
| 3041 | + switch ($type) { |
|
| 3042 | + case 'decimal': |
|
| 3043 | + case 'decimal2': |
|
| 3044 | + case 'int': |
|
| 3045 | + case 'double': |
|
| 3046 | + case 'float': |
|
| 3047 | + case 'uint': |
|
| 3048 | + case 'ulong': |
|
| 3049 | + case 'long': |
|
| 3050 | + case 'short': |
|
| 3051 | + return ($val == 0); |
|
| 3052 | + case 'date': |
|
| 3053 | + if ($val == '0000-00-00') |
|
| 3054 | + return true; |
|
| 3055 | + if ($val == 'NULL') |
|
| 3056 | + return true; |
|
| 3057 | + return false; |
|
| 3058 | + } |
|
| 3059 | + |
|
| 3060 | + return false; |
|
| 3061 | + } |
|
| 3062 | + |
|
| 3063 | + /** |
|
| 3064 | 3064 | * @abstract |
| 3065 | - * Does this type represent text (i.e., non-varchar) value? |
|
| 3066 | - * @param string $type |
|
| 3065 | + * Does this type represent text (i.e., non-varchar) value? |
|
| 3066 | + * @param string $type |
|
| 3067 | 3067 | * @return bool |
| 3068 | - */ |
|
| 3069 | - public function isTextType($type) |
|
| 3070 | - { |
|
| 3071 | - return false; |
|
| 3072 | - } |
|
| 3073 | - |
|
| 3074 | - /** |
|
| 3075 | - * Check if this DB supports certain capability |
|
| 3076 | - * See $this->capabilities for the list |
|
| 3077 | - * @param string $cap |
|
| 3068 | + */ |
|
| 3069 | + public function isTextType($type) |
|
| 3070 | + { |
|
| 3071 | + return false; |
|
| 3072 | + } |
|
| 3073 | + |
|
| 3074 | + /** |
|
| 3075 | + * Check if this DB supports certain capability |
|
| 3076 | + * See $this->capabilities for the list |
|
| 3077 | + * @param string $cap |
|
| 3078 | 3078 | * @return bool |
| 3079 | - */ |
|
| 3080 | - public function supports($cap) |
|
| 3081 | - { |
|
| 3082 | - return !empty($this->capabilities[$cap]); |
|
| 3083 | - } |
|
| 3084 | - |
|
| 3085 | - /** |
|
| 3086 | - * Create ORDER BY clause for ENUM type field |
|
| 3087 | - * @param string $order_by Field name |
|
| 3088 | - * @param array $values Possible enum value |
|
| 3089 | - * @param string $order_dir Order direction, ASC or DESC |
|
| 3079 | + */ |
|
| 3080 | + public function supports($cap) |
|
| 3081 | + { |
|
| 3082 | + return !empty($this->capabilities[$cap]); |
|
| 3083 | + } |
|
| 3084 | + |
|
| 3085 | + /** |
|
| 3086 | + * Create ORDER BY clause for ENUM type field |
|
| 3087 | + * @param string $order_by Field name |
|
| 3088 | + * @param array $values Possible enum value |
|
| 3089 | + * @param string $order_dir Order direction, ASC or DESC |
|
| 3090 | 3090 | * @return string |
| 3091 | 3091 | */ |
| 3092 | - public function orderByEnum($order_by, $values, $order_dir) |
|
| 3093 | - { |
|
| 3094 | - $i = 0; |
|
| 3095 | - $order_by_arr = array(); |
|
| 3096 | - foreach ($values as $key => $value) { |
|
| 3097 | - if($key == '') { |
|
| 3098 | - $order_by_arr[] = "WHEN ($order_by='' OR $order_by IS NULL) THEN $i"; |
|
| 3099 | - } else { |
|
| 3100 | - $order_by_arr[] = "WHEN $order_by=".$this->quoted($key)." THEN $i"; |
|
| 3101 | - } |
|
| 3102 | - $i++; |
|
| 3103 | - } |
|
| 3104 | - return "CASE ".implode("\n", $order_by_arr)." ELSE $i END $order_dir\n"; |
|
| 3105 | - } |
|
| 3106 | - |
|
| 3107 | - /** |
|
| 3108 | - * Return representation of an empty value depending on type |
|
| 3109 | - * The value is fully quoted, converted, etc. |
|
| 3110 | - * @param string $type |
|
| 3092 | + public function orderByEnum($order_by, $values, $order_dir) |
|
| 3093 | + { |
|
| 3094 | + $i = 0; |
|
| 3095 | + $order_by_arr = array(); |
|
| 3096 | + foreach ($values as $key => $value) { |
|
| 3097 | + if($key == '') { |
|
| 3098 | + $order_by_arr[] = "WHEN ($order_by='' OR $order_by IS NULL) THEN $i"; |
|
| 3099 | + } else { |
|
| 3100 | + $order_by_arr[] = "WHEN $order_by=".$this->quoted($key)." THEN $i"; |
|
| 3101 | + } |
|
| 3102 | + $i++; |
|
| 3103 | + } |
|
| 3104 | + return "CASE ".implode("\n", $order_by_arr)." ELSE $i END $order_dir\n"; |
|
| 3105 | + } |
|
| 3106 | + |
|
| 3107 | + /** |
|
| 3108 | + * Return representation of an empty value depending on type |
|
| 3109 | + * The value is fully quoted, converted, etc. |
|
| 3110 | + * @param string $type |
|
| 3111 | 3111 | * @return mixed Empty value |
| 3112 | 3112 | */ |
| 3113 | - public function emptyValue($type) |
|
| 3114 | - { |
|
| 3115 | - if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'bool' || $this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3116 | - return 0; |
|
| 3117 | - } |
|
| 3113 | + public function emptyValue($type) |
|
| 3114 | + { |
|
| 3115 | + if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'bool' || $this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3116 | + return 0; |
|
| 3117 | + } |
|
| 3118 | 3118 | |
| 3119 | - return "''"; |
|
| 3120 | - } |
|
| 3119 | + return "''"; |
|
| 3120 | + } |
|
| 3121 | 3121 | |
| 3122 | - /** |
|
| 3123 | - * List of available collation settings |
|
| 3122 | + /** |
|
| 3123 | + * List of available collation settings |
|
| 3124 | 3124 | * @abstract |
| 3125 | - * @return string |
|
| 3126 | - */ |
|
| 3127 | - public function getDefaultCollation() |
|
| 3128 | - { |
|
| 3129 | - return null; |
|
| 3130 | - } |
|
| 3131 | - |
|
| 3132 | - /** |
|
| 3133 | - * List of available collation settings |
|
| 3125 | + * @return string |
|
| 3126 | + */ |
|
| 3127 | + public function getDefaultCollation() |
|
| 3128 | + { |
|
| 3129 | + return null; |
|
| 3130 | + } |
|
| 3131 | + |
|
| 3132 | + /** |
|
| 3133 | + * List of available collation settings |
|
| 3134 | 3134 | * @abstract |
| 3135 | - * @return array |
|
| 3136 | - */ |
|
| 3137 | - public function getCollationList() |
|
| 3138 | - { |
|
| 3139 | - return null; |
|
| 3140 | - } |
|
| 3141 | - |
|
| 3142 | - /** |
|
| 3143 | - * Returns the number of columns in a table |
|
| 3144 | - * |
|
| 3145 | - * @param string $table_name |
|
| 3146 | - * @return int |
|
| 3147 | - */ |
|
| 3148 | - public function number_of_columns($table_name) |
|
| 3149 | - { |
|
| 3150 | - $table = $this->getTableDescription($table_name); |
|
| 3151 | - return count($table); |
|
| 3152 | - } |
|
| 3153 | - |
|
| 3154 | - /** |
|
| 3155 | - * Return limit query based on given query |
|
| 3156 | - * @param string $sql |
|
| 3157 | - * @param int $start |
|
| 3158 | - * @param int $count |
|
| 3159 | - * @param bool $dieOnError |
|
| 3160 | - * @param string $msg |
|
| 3135 | + * @return array |
|
| 3136 | + */ |
|
| 3137 | + public function getCollationList() |
|
| 3138 | + { |
|
| 3139 | + return null; |
|
| 3140 | + } |
|
| 3141 | + |
|
| 3142 | + /** |
|
| 3143 | + * Returns the number of columns in a table |
|
| 3144 | + * |
|
| 3145 | + * @param string $table_name |
|
| 3146 | + * @return int |
|
| 3147 | + */ |
|
| 3148 | + public function number_of_columns($table_name) |
|
| 3149 | + { |
|
| 3150 | + $table = $this->getTableDescription($table_name); |
|
| 3151 | + return count($table); |
|
| 3152 | + } |
|
| 3153 | + |
|
| 3154 | + /** |
|
| 3155 | + * Return limit query based on given query |
|
| 3156 | + * @param string $sql |
|
| 3157 | + * @param int $start |
|
| 3158 | + * @param int $count |
|
| 3159 | + * @param bool $dieOnError |
|
| 3160 | + * @param string $msg |
|
| 3161 | 3161 | * @return resource|bool query result |
| 3162 | 3162 | * @see DBManager::limitQuery() |
| 3163 | - */ |
|
| 3164 | - public function limitQuerySql($sql, $start, $count, $dieOnError=false, $msg='') |
|
| 3165 | - { |
|
| 3166 | - return $this->limitQuery($sql,$start,$count,$dieOnError,$msg,false); |
|
| 3167 | - } |
|
| 3168 | - |
|
| 3169 | - /** |
|
| 3170 | - * Return current time in format fit for insertion into DB (with quotes) |
|
| 3171 | - * @return string |
|
| 3172 | - */ |
|
| 3173 | - public function now() |
|
| 3174 | - { |
|
| 3175 | - return $this->convert($this->quoted(TimeDate::getInstance()->nowDb()), "datetime"); |
|
| 3176 | - } |
|
| 3177 | - |
|
| 3178 | - /** |
|
| 3179 | - * Check if connecting user has certain privilege |
|
| 3180 | - * @param string $privilege |
|
| 3163 | + */ |
|
| 3164 | + public function limitQuerySql($sql, $start, $count, $dieOnError=false, $msg='') |
|
| 3165 | + { |
|
| 3166 | + return $this->limitQuery($sql,$start,$count,$dieOnError,$msg,false); |
|
| 3167 | + } |
|
| 3168 | + |
|
| 3169 | + /** |
|
| 3170 | + * Return current time in format fit for insertion into DB (with quotes) |
|
| 3171 | + * @return string |
|
| 3172 | + */ |
|
| 3173 | + public function now() |
|
| 3174 | + { |
|
| 3175 | + return $this->convert($this->quoted(TimeDate::getInstance()->nowDb()), "datetime"); |
|
| 3176 | + } |
|
| 3177 | + |
|
| 3178 | + /** |
|
| 3179 | + * Check if connecting user has certain privilege |
|
| 3180 | + * @param string $privilege |
|
| 3181 | 3181 | * @return bool Privilege allowed? |
| 3182 | 3182 | */ |
| 3183 | - public function checkPrivilege($privilege) |
|
| 3184 | - { |
|
| 3185 | - switch($privilege) { |
|
| 3186 | - case "CREATE TABLE": |
|
| 3187 | - $this->query("CREATE TABLE temp (id varchar(36))"); |
|
| 3188 | - break; |
|
| 3189 | - case "DROP TABLE": |
|
| 3190 | - $sql = $this->dropTableNameSQL("temp"); |
|
| 3191 | - $this->query($sql); |
|
| 3192 | - break; |
|
| 3193 | - case "INSERT": |
|
| 3194 | - $this->query("INSERT INTO temp (id) VALUES ('abcdef0123456789abcdef0123456789abcd')"); |
|
| 3195 | - break; |
|
| 3196 | - case "UPDATE": |
|
| 3197 | - $this->query("UPDATE temp SET id = '100000000000000000000000000000000000' WHERE id = 'abcdef0123456789abcdef0123456789abcd'"); |
|
| 3198 | - break; |
|
| 3199 | - case 'SELECT': |
|
| 3200 | - return $this->getOne('SELECT id FROM temp WHERE id=\'100000000000000000000000000000000000\'', false); |
|
| 3201 | - case 'DELETE': |
|
| 3202 | - $this->query("DELETE FROM temp WHERE id = '100000000000000000000000000000000000'"); |
|
| 3203 | - break; |
|
| 3204 | - case "ADD COLUMN": |
|
| 3205 | - $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 50)); |
|
| 3206 | - $sql = $this->changeColumnSQL("temp", $test, "add"); |
|
| 3207 | - $this->query($sql); |
|
| 3208 | - break; |
|
| 3209 | - case "CHANGE COLUMN": |
|
| 3210 | - $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100)); |
|
| 3211 | - $sql = $this->changeColumnSQL("temp", $test, "modify"); |
|
| 3212 | - $this->query($sql); |
|
| 3213 | - break; |
|
| 3214 | - case "DROP COLUMN": |
|
| 3215 | - $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100)); |
|
| 3216 | - $sql = $this->changeColumnSQL("temp", $test, "drop"); |
|
| 3217 | - $this->query($sql); |
|
| 3218 | - break; |
|
| 3219 | - default: |
|
| 3220 | - return false; |
|
| 3221 | - } |
|
| 3222 | - if($this->checkError("Checking privileges")) { |
|
| 3223 | - return false; |
|
| 3224 | - } |
|
| 3225 | - return true; |
|
| 3226 | - } |
|
| 3227 | - |
|
| 3228 | - /** |
|
| 3229 | - * Check if the query is a select query |
|
| 3230 | - * @param string $query |
|
| 3183 | + public function checkPrivilege($privilege) |
|
| 3184 | + { |
|
| 3185 | + switch($privilege) { |
|
| 3186 | + case "CREATE TABLE": |
|
| 3187 | + $this->query("CREATE TABLE temp (id varchar(36))"); |
|
| 3188 | + break; |
|
| 3189 | + case "DROP TABLE": |
|
| 3190 | + $sql = $this->dropTableNameSQL("temp"); |
|
| 3191 | + $this->query($sql); |
|
| 3192 | + break; |
|
| 3193 | + case "INSERT": |
|
| 3194 | + $this->query("INSERT INTO temp (id) VALUES ('abcdef0123456789abcdef0123456789abcd')"); |
|
| 3195 | + break; |
|
| 3196 | + case "UPDATE": |
|
| 3197 | + $this->query("UPDATE temp SET id = '100000000000000000000000000000000000' WHERE id = 'abcdef0123456789abcdef0123456789abcd'"); |
|
| 3198 | + break; |
|
| 3199 | + case 'SELECT': |
|
| 3200 | + return $this->getOne('SELECT id FROM temp WHERE id=\'100000000000000000000000000000000000\'', false); |
|
| 3201 | + case 'DELETE': |
|
| 3202 | + $this->query("DELETE FROM temp WHERE id = '100000000000000000000000000000000000'"); |
|
| 3203 | + break; |
|
| 3204 | + case "ADD COLUMN": |
|
| 3205 | + $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 50)); |
|
| 3206 | + $sql = $this->changeColumnSQL("temp", $test, "add"); |
|
| 3207 | + $this->query($sql); |
|
| 3208 | + break; |
|
| 3209 | + case "CHANGE COLUMN": |
|
| 3210 | + $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100)); |
|
| 3211 | + $sql = $this->changeColumnSQL("temp", $test, "modify"); |
|
| 3212 | + $this->query($sql); |
|
| 3213 | + break; |
|
| 3214 | + case "DROP COLUMN": |
|
| 3215 | + $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100)); |
|
| 3216 | + $sql = $this->changeColumnSQL("temp", $test, "drop"); |
|
| 3217 | + $this->query($sql); |
|
| 3218 | + break; |
|
| 3219 | + default: |
|
| 3220 | + return false; |
|
| 3221 | + } |
|
| 3222 | + if($this->checkError("Checking privileges")) { |
|
| 3223 | + return false; |
|
| 3224 | + } |
|
| 3225 | + return true; |
|
| 3226 | + } |
|
| 3227 | + |
|
| 3228 | + /** |
|
| 3229 | + * Check if the query is a select query |
|
| 3230 | + * @param string $query |
|
| 3231 | 3231 | * @return bool Is query SELECT? |
| 3232 | 3232 | */ |
| 3233 | - protected function isSelect($query) |
|
| 3234 | - { |
|
| 3235 | - $query = trim($query); |
|
| 3236 | - $select_check = strpos(strtolower($query), strtolower("SELECT")); |
|
| 3237 | - //Checks to see if there is union select which is valid |
|
| 3238 | - $select_check2 = strpos(strtolower($query), strtolower("(SELECT")); |
|
| 3239 | - if($select_check==0 || $select_check2==0){ |
|
| 3240 | - //Returning false means query is ok! |
|
| 3241 | - return true; |
|
| 3242 | - } |
|
| 3243 | - return false; |
|
| 3244 | - } |
|
| 3245 | - |
|
| 3246 | - /** |
|
| 3247 | - * Parse fulltext search query with mysql syntax: |
|
| 3248 | - * terms quoted by "" |
|
| 3249 | - * + means the term must be included |
|
| 3250 | - * - means the term must be excluded |
|
| 3251 | - * * or % at the end means wildcard |
|
| 3252 | - * @param string $query |
|
| 3253 | - * @return array of 3 elements - query terms, mandatory terms and excluded terms |
|
| 3254 | - */ |
|
| 3255 | - public function parseFulltextQuery($query) |
|
| 3256 | - { |
|
| 3257 | - /* split on space or comma, double quotes with \ for escape */ |
|
| 3258 | - if(strpbrk($query, " ,")) { |
|
| 3259 | - // ("([^"]*?)"|[^" ,]+)((, )+)? |
|
| 3260 | - // '/([^" ,]+|".*?[^\\\\]")(,|\s)\s*/' |
|
| 3261 | - if(!preg_match_all('/("([^"]*?)"|[^"\s,]+)((,\s)+)?/', $query, $m)) { |
|
| 3262 | - return false; |
|
| 3263 | - } |
|
| 3264 | - $qterms = $m[1]; |
|
| 3265 | - } else { |
|
| 3266 | - $qterms = array($query); |
|
| 3267 | - } |
|
| 3268 | - $terms = $must_terms = $not_terms = array(); |
|
| 3269 | - foreach($qterms as $item) { |
|
| 3270 | - if($item[0] == '"') { |
|
| 3271 | - $item = trim($item, '"'); |
|
| 3272 | - } |
|
| 3273 | - if($item[0] == '+') { |
|
| 3233 | + protected function isSelect($query) |
|
| 3234 | + { |
|
| 3235 | + $query = trim($query); |
|
| 3236 | + $select_check = strpos(strtolower($query), strtolower("SELECT")); |
|
| 3237 | + //Checks to see if there is union select which is valid |
|
| 3238 | + $select_check2 = strpos(strtolower($query), strtolower("(SELECT")); |
|
| 3239 | + if($select_check==0 || $select_check2==0){ |
|
| 3240 | + //Returning false means query is ok! |
|
| 3241 | + return true; |
|
| 3242 | + } |
|
| 3243 | + return false; |
|
| 3244 | + } |
|
| 3245 | + |
|
| 3246 | + /** |
|
| 3247 | + * Parse fulltext search query with mysql syntax: |
|
| 3248 | + * terms quoted by "" |
|
| 3249 | + * + means the term must be included |
|
| 3250 | + * - means the term must be excluded |
|
| 3251 | + * * or % at the end means wildcard |
|
| 3252 | + * @param string $query |
|
| 3253 | + * @return array of 3 elements - query terms, mandatory terms and excluded terms |
|
| 3254 | + */ |
|
| 3255 | + public function parseFulltextQuery($query) |
|
| 3256 | + { |
|
| 3257 | + /* split on space or comma, double quotes with \ for escape */ |
|
| 3258 | + if(strpbrk($query, " ,")) { |
|
| 3259 | + // ("([^"]*?)"|[^" ,]+)((, )+)? |
|
| 3260 | + // '/([^" ,]+|".*?[^\\\\]")(,|\s)\s*/' |
|
| 3261 | + if(!preg_match_all('/("([^"]*?)"|[^"\s,]+)((,\s)+)?/', $query, $m)) { |
|
| 3262 | + return false; |
|
| 3263 | + } |
|
| 3264 | + $qterms = $m[1]; |
|
| 3265 | + } else { |
|
| 3266 | + $qterms = array($query); |
|
| 3267 | + } |
|
| 3268 | + $terms = $must_terms = $not_terms = array(); |
|
| 3269 | + foreach($qterms as $item) { |
|
| 3270 | + if($item[0] == '"') { |
|
| 3271 | + $item = trim($item, '"'); |
|
| 3272 | + } |
|
| 3273 | + if($item[0] == '+') { |
|
| 3274 | 3274 | if (strlen($item) > 1) { |
| 3275 | 3275 | $must_terms[] = substr($item, 1); |
| 3276 | 3276 | } |
| 3277 | 3277 | continue; |
| 3278 | - } |
|
| 3279 | - if($item[0] == '-') { |
|
| 3278 | + } |
|
| 3279 | + if($item[0] == '-') { |
|
| 3280 | 3280 | if (strlen($item) > 1) { |
| 3281 | - $not_terms[] = substr($item, 1); |
|
| 3281 | + $not_terms[] = substr($item, 1); |
|
| 3282 | 3282 | } |
| 3283 | 3283 | continue; |
| 3284 | - } |
|
| 3285 | - $terms[] = $item; |
|
| 3286 | - } |
|
| 3287 | - return array($terms, $must_terms, $not_terms); |
|
| 3288 | - } |
|
| 3284 | + } |
|
| 3285 | + $terms[] = $item; |
|
| 3286 | + } |
|
| 3287 | + return array($terms, $must_terms, $not_terms); |
|
| 3288 | + } |
|
| 3289 | 3289 | |
| 3290 | 3290 | // Methods to check respective queries |
| 3291 | - protected $standardQueries = array( |
|
| 3292 | - 'ALTER TABLE' => 'verifyAlterTable', |
|
| 3293 | - 'DROP TABLE' => 'verifyDropTable', |
|
| 3294 | - 'CREATE TABLE' => 'verifyCreateTable', |
|
| 3295 | - 'INSERT INTO' => 'verifyInsertInto', |
|
| 3296 | - 'UPDATE' => 'verifyUpdate', |
|
| 3297 | - 'DELETE FROM' => 'verifyDeleteFrom', |
|
| 3298 | - ); |
|
| 3291 | + protected $standardQueries = array( |
|
| 3292 | + 'ALTER TABLE' => 'verifyAlterTable', |
|
| 3293 | + 'DROP TABLE' => 'verifyDropTable', |
|
| 3294 | + 'CREATE TABLE' => 'verifyCreateTable', |
|
| 3295 | + 'INSERT INTO' => 'verifyInsertInto', |
|
| 3296 | + 'UPDATE' => 'verifyUpdate', |
|
| 3297 | + 'DELETE FROM' => 'verifyDeleteFrom', |
|
| 3298 | + ); |
|
| 3299 | 3299 | |
| 3300 | 3300 | |
| 3301 | 3301 | /** |
@@ -3303,8 +3303,8 @@ discard block |
||
| 3303 | 3303 | * @param string $query SQL query |
| 3304 | 3304 | * @return string |
| 3305 | 3305 | */ |
| 3306 | - protected function extractTableName($query) |
|
| 3307 | - { |
|
| 3306 | + protected function extractTableName($query) |
|
| 3307 | + { |
|
| 3308 | 3308 | $query = preg_replace('/[^A-Za-z0-9_\s]/', "", $query); |
| 3309 | 3309 | $query = trim(str_replace(array_keys($this->standardQueries), '', $query)); |
| 3310 | 3310 | |
@@ -3313,7 +3313,7 @@ discard block |
||
| 3313 | 3313 | $table = substr($query, 0, $end); |
| 3314 | 3314 | |
| 3315 | 3315 | return $table; |
| 3316 | - } |
|
| 3316 | + } |
|
| 3317 | 3317 | |
| 3318 | 3318 | /** |
| 3319 | 3319 | * Verify SQl statement using per-DB verification function |
@@ -3322,284 +3322,284 @@ discard block |
||
| 3322 | 3322 | * @param array $skipTables List of blacklisted tables that aren't checked |
| 3323 | 3323 | * @return string |
| 3324 | 3324 | */ |
| 3325 | - public function verifySQLStatement($query, $skipTables) |
|
| 3326 | - { |
|
| 3327 | - $query = trim($query); |
|
| 3328 | - foreach($this->standardQueries as $qstart => $check) { |
|
| 3329 | - if(strncasecmp($qstart, $query, strlen($qstart)) == 0) { |
|
| 3330 | - if(is_callable(array($this, $check))) { |
|
| 3331 | - $table = $this->extractTableName($query); |
|
| 3332 | - if(!in_array($table, $skipTables)) { |
|
| 3333 | - return call_user_func(array($this, $check), $table, $query); |
|
| 3334 | - } else { |
|
| 3335 | - $this->log->debug("Skipping table $table as blacklisted"); |
|
| 3336 | - } |
|
| 3337 | - } else { |
|
| 3338 | - $this->log->debug("No verification for $qstart on {$this->dbType}"); |
|
| 3339 | - } |
|
| 3340 | - break; |
|
| 3341 | - } |
|
| 3342 | - } |
|
| 3343 | - return ""; |
|
| 3344 | - } |
|
| 3345 | - |
|
| 3346 | - /** |
|
| 3347 | - * Tests an CREATE TABLE query |
|
| 3348 | - * @param string $table The table name to get DDL |
|
| 3349 | - * @param string $query The query to test. |
|
| 3350 | - * @return string Non-empty if error found |
|
| 3351 | - */ |
|
| 3352 | - protected function verifyCreateTable($table, $query) |
|
| 3353 | - { |
|
| 3354 | - $this->log->debug('verifying CREATE statement...'); |
|
| 3355 | - |
|
| 3356 | - // rewrite DDL with _temp name |
|
| 3357 | - $this->log->debug('testing query: ['.$query.']'); |
|
| 3358 | - $tempname = $table."__uw_temp"; |
|
| 3359 | - $tempTableQuery = str_replace("CREATE TABLE {$table}", "CREATE TABLE $tempname", $query); |
|
| 3360 | - |
|
| 3361 | - if(strpos($tempTableQuery, '__uw_temp') === false) { |
|
| 3362 | - return 'Could not use a temp table to test query!'; |
|
| 3363 | - } |
|
| 3364 | - |
|
| 3365 | - $this->query($tempTableQuery, false, "Preflight Failed for: {$query}"); |
|
| 3366 | - |
|
| 3367 | - $error = $this->lastError(); // empty on no-errors |
|
| 3368 | - if(!empty($error)) { |
|
| 3369 | - return $error; |
|
| 3370 | - } |
|
| 3371 | - |
|
| 3372 | - // check if table exists |
|
| 3373 | - $this->log->debug('testing for table: '.$table); |
|
| 3374 | - if(!$this->tableExists($tempname)) { |
|
| 3375 | - return "Failed to create temp table!"; |
|
| 3376 | - } |
|
| 3377 | - |
|
| 3378 | - $this->dropTableName($tempname); |
|
| 3379 | - return ''; |
|
| 3380 | - } |
|
| 3381 | - |
|
| 3382 | - /** |
|
| 3383 | - * Execute multiple queries one after another |
|
| 3384 | - * @param array $sqls Queries |
|
| 3385 | - * @param bool $dieOnError Die on error, passed to query() |
|
| 3386 | - * @param string $msg Error message, passed to query() |
|
| 3387 | - * @param bool $suppress Supress errors, passed to query() |
|
| 3388 | - * @return resource|bool result set or success/failure bool |
|
| 3389 | - */ |
|
| 3390 | - public function queryArray(array $sqls, $dieOnError = false, $msg = '', $suppress = false) |
|
| 3391 | - { |
|
| 3392 | - $last = true; |
|
| 3393 | - foreach($sqls as $sql) { |
|
| 3394 | - if(!($last = $this->query($sql, $dieOnError, $msg, $suppress))) { |
|
| 3395 | - break; |
|
| 3396 | - } |
|
| 3397 | - } |
|
| 3398 | - return $last; |
|
| 3399 | - } |
|
| 3400 | - |
|
| 3401 | - /** |
|
| 3402 | - * Fetches the next row in the query result into an associative array |
|
| 3403 | - * |
|
| 3404 | - * @param resource $result |
|
| 3405 | - * @param bool $encode Need to HTML-encode the result? |
|
| 3406 | - * @return array returns false if there are no more rows available to fetch |
|
| 3407 | - */ |
|
| 3408 | - public function fetchByAssoc($result, $encode = true) |
|
| 3409 | - { |
|
| 3410 | - if (empty($result)) return false; |
|
| 3411 | - |
|
| 3412 | - if(is_int($encode) && func_num_args() == 3) { |
|
| 3413 | - // old API: $result, $rowNum, $encode |
|
| 3414 | - $GLOBALS['log']->deprecated("Using row number in fetchByAssoc is not portable and no longer supported. Please fix your code."); |
|
| 3415 | - $encode = func_get_arg(2); |
|
| 3416 | - } |
|
| 3417 | - $row = $this->fetchRow($result); |
|
| 3418 | - if (!empty($row) && $encode && $this->encode) { |
|
| 3419 | - return array_map('to_html', $row); |
|
| 3420 | - } else { |
|
| 3421 | - return $row; |
|
| 3422 | - } |
|
| 3423 | - } |
|
| 3424 | - |
|
| 3425 | - /** |
|
| 3426 | - * Get DB driver name used for install/upgrade scripts |
|
| 3427 | - * @return string |
|
| 3428 | - */ |
|
| 3429 | - public function getScriptName() |
|
| 3430 | - { |
|
| 3431 | - // Usually the same name as dbType |
|
| 3432 | - return $this->dbType; |
|
| 3433 | - } |
|
| 3434 | - |
|
| 3435 | - /** |
|
| 3436 | - * Set database options |
|
| 3437 | - * Options are usually db-dependant and derive from $config['dbconfigoption'] |
|
| 3438 | - * @param array $options |
|
| 3439 | - * @return DBManager |
|
| 3440 | - */ |
|
| 3441 | - public function setOptions($options) |
|
| 3442 | - { |
|
| 3443 | - $this->options = $options; |
|
| 3444 | - return $this; |
|
| 3445 | - } |
|
| 3446 | - |
|
| 3447 | - /** |
|
| 3448 | - * Get DB options |
|
| 3449 | - * @return array |
|
| 3450 | - */ |
|
| 3451 | - public function getOptions() |
|
| 3452 | - { |
|
| 3453 | - return $this->options; |
|
| 3454 | - } |
|
| 3455 | - |
|
| 3456 | - /** |
|
| 3457 | - * Get DB option by name |
|
| 3458 | - * @param string $option Option name |
|
| 3459 | - * @return mixed Option value or null if doesn't exist |
|
| 3460 | - */ |
|
| 3461 | - public function getOption($option) |
|
| 3462 | - { |
|
| 3463 | - if(isset($this->options[$option])) { |
|
| 3464 | - return $this->options[$option]; |
|
| 3465 | - } |
|
| 3466 | - return null; |
|
| 3467 | - } |
|
| 3468 | - |
|
| 3469 | - /** |
|
| 3470 | - * Commits pending changes to the database when the driver is setup to support transactions. |
|
| 3471 | - * Note that the default implementation is applicable for transaction-less or auto commit scenarios. |
|
| 3472 | - * @abstract |
|
| 3473 | - * @return bool true if commit succeeded, false if it failed |
|
| 3474 | - */ |
|
| 3475 | - public function commit() |
|
| 3476 | - { |
|
| 3477 | - $this->log->info("DBManager.commit() stub"); |
|
| 3478 | - return true; |
|
| 3479 | - } |
|
| 3480 | - |
|
| 3481 | - /** |
|
| 3482 | - * Rollsback pending changes to the database when the driver is setup to support transactions. |
|
| 3483 | - * Note that the default implementation is applicable for transaction-less or auto commit scenarios. |
|
| 3484 | - * Since rollbacks cannot be done, this implementation always returns false. |
|
| 3485 | - * @abstract |
|
| 3486 | - * @return bool true if rollback succeeded, false if it failed |
|
| 3487 | - */ |
|
| 3488 | - public function rollback() |
|
| 3489 | - { |
|
| 3490 | - $this->log->info("DBManager.rollback() stub"); |
|
| 3491 | - return false; |
|
| 3492 | - } |
|
| 3493 | - |
|
| 3494 | - /** |
|
| 3495 | - * Check if this DB name is valid |
|
| 3496 | - * |
|
| 3497 | - * @param string $name |
|
| 3498 | - * @return bool |
|
| 3499 | - */ |
|
| 3500 | - public function isDatabaseNameValid($name) |
|
| 3501 | - { |
|
| 3502 | - // Generic case - no slashes, no dots |
|
| 3503 | - return preg_match('#[/.\\\\]#', $name)==0; |
|
| 3504 | - } |
|
| 3505 | - |
|
| 3506 | - /** |
|
| 3507 | - * Check special requirements for DB installation. |
|
| 3508 | - * @abstract |
|
| 3509 | - * If everything is OK, return true. |
|
| 3510 | - * If something's wrong, return array of error code and parameters |
|
| 3511 | - * @return mixed |
|
| 3512 | - */ |
|
| 3513 | - public function canInstall() |
|
| 3514 | - { |
|
| 3515 | - return true; |
|
| 3516 | - } |
|
| 3517 | - |
|
| 3518 | - /** |
|
| 3519 | - * @abstract |
|
| 3325 | + public function verifySQLStatement($query, $skipTables) |
|
| 3326 | + { |
|
| 3327 | + $query = trim($query); |
|
| 3328 | + foreach($this->standardQueries as $qstart => $check) { |
|
| 3329 | + if(strncasecmp($qstart, $query, strlen($qstart)) == 0) { |
|
| 3330 | + if(is_callable(array($this, $check))) { |
|
| 3331 | + $table = $this->extractTableName($query); |
|
| 3332 | + if(!in_array($table, $skipTables)) { |
|
| 3333 | + return call_user_func(array($this, $check), $table, $query); |
|
| 3334 | + } else { |
|
| 3335 | + $this->log->debug("Skipping table $table as blacklisted"); |
|
| 3336 | + } |
|
| 3337 | + } else { |
|
| 3338 | + $this->log->debug("No verification for $qstart on {$this->dbType}"); |
|
| 3339 | + } |
|
| 3340 | + break; |
|
| 3341 | + } |
|
| 3342 | + } |
|
| 3343 | + return ""; |
|
| 3344 | + } |
|
| 3345 | + |
|
| 3346 | + /** |
|
| 3347 | + * Tests an CREATE TABLE query |
|
| 3348 | + * @param string $table The table name to get DDL |
|
| 3349 | + * @param string $query The query to test. |
|
| 3350 | + * @return string Non-empty if error found |
|
| 3351 | + */ |
|
| 3352 | + protected function verifyCreateTable($table, $query) |
|
| 3353 | + { |
|
| 3354 | + $this->log->debug('verifying CREATE statement...'); |
|
| 3355 | + |
|
| 3356 | + // rewrite DDL with _temp name |
|
| 3357 | + $this->log->debug('testing query: ['.$query.']'); |
|
| 3358 | + $tempname = $table."__uw_temp"; |
|
| 3359 | + $tempTableQuery = str_replace("CREATE TABLE {$table}", "CREATE TABLE $tempname", $query); |
|
| 3360 | + |
|
| 3361 | + if(strpos($tempTableQuery, '__uw_temp') === false) { |
|
| 3362 | + return 'Could not use a temp table to test query!'; |
|
| 3363 | + } |
|
| 3364 | + |
|
| 3365 | + $this->query($tempTableQuery, false, "Preflight Failed for: {$query}"); |
|
| 3366 | + |
|
| 3367 | + $error = $this->lastError(); // empty on no-errors |
|
| 3368 | + if(!empty($error)) { |
|
| 3369 | + return $error; |
|
| 3370 | + } |
|
| 3371 | + |
|
| 3372 | + // check if table exists |
|
| 3373 | + $this->log->debug('testing for table: '.$table); |
|
| 3374 | + if(!$this->tableExists($tempname)) { |
|
| 3375 | + return "Failed to create temp table!"; |
|
| 3376 | + } |
|
| 3377 | + |
|
| 3378 | + $this->dropTableName($tempname); |
|
| 3379 | + return ''; |
|
| 3380 | + } |
|
| 3381 | + |
|
| 3382 | + /** |
|
| 3383 | + * Execute multiple queries one after another |
|
| 3384 | + * @param array $sqls Queries |
|
| 3385 | + * @param bool $dieOnError Die on error, passed to query() |
|
| 3386 | + * @param string $msg Error message, passed to query() |
|
| 3387 | + * @param bool $suppress Supress errors, passed to query() |
|
| 3388 | + * @return resource|bool result set or success/failure bool |
|
| 3389 | + */ |
|
| 3390 | + public function queryArray(array $sqls, $dieOnError = false, $msg = '', $suppress = false) |
|
| 3391 | + { |
|
| 3392 | + $last = true; |
|
| 3393 | + foreach($sqls as $sql) { |
|
| 3394 | + if(!($last = $this->query($sql, $dieOnError, $msg, $suppress))) { |
|
| 3395 | + break; |
|
| 3396 | + } |
|
| 3397 | + } |
|
| 3398 | + return $last; |
|
| 3399 | + } |
|
| 3400 | + |
|
| 3401 | + /** |
|
| 3402 | + * Fetches the next row in the query result into an associative array |
|
| 3403 | + * |
|
| 3404 | + * @param resource $result |
|
| 3405 | + * @param bool $encode Need to HTML-encode the result? |
|
| 3406 | + * @return array returns false if there are no more rows available to fetch |
|
| 3407 | + */ |
|
| 3408 | + public function fetchByAssoc($result, $encode = true) |
|
| 3409 | + { |
|
| 3410 | + if (empty($result)) return false; |
|
| 3411 | + |
|
| 3412 | + if(is_int($encode) && func_num_args() == 3) { |
|
| 3413 | + // old API: $result, $rowNum, $encode |
|
| 3414 | + $GLOBALS['log']->deprecated("Using row number in fetchByAssoc is not portable and no longer supported. Please fix your code."); |
|
| 3415 | + $encode = func_get_arg(2); |
|
| 3416 | + } |
|
| 3417 | + $row = $this->fetchRow($result); |
|
| 3418 | + if (!empty($row) && $encode && $this->encode) { |
|
| 3419 | + return array_map('to_html', $row); |
|
| 3420 | + } else { |
|
| 3421 | + return $row; |
|
| 3422 | + } |
|
| 3423 | + } |
|
| 3424 | + |
|
| 3425 | + /** |
|
| 3426 | + * Get DB driver name used for install/upgrade scripts |
|
| 3427 | + * @return string |
|
| 3428 | + */ |
|
| 3429 | + public function getScriptName() |
|
| 3430 | + { |
|
| 3431 | + // Usually the same name as dbType |
|
| 3432 | + return $this->dbType; |
|
| 3433 | + } |
|
| 3434 | + |
|
| 3435 | + /** |
|
| 3436 | + * Set database options |
|
| 3437 | + * Options are usually db-dependant and derive from $config['dbconfigoption'] |
|
| 3438 | + * @param array $options |
|
| 3439 | + * @return DBManager |
|
| 3440 | + */ |
|
| 3441 | + public function setOptions($options) |
|
| 3442 | + { |
|
| 3443 | + $this->options = $options; |
|
| 3444 | + return $this; |
|
| 3445 | + } |
|
| 3446 | + |
|
| 3447 | + /** |
|
| 3448 | + * Get DB options |
|
| 3449 | + * @return array |
|
| 3450 | + */ |
|
| 3451 | + public function getOptions() |
|
| 3452 | + { |
|
| 3453 | + return $this->options; |
|
| 3454 | + } |
|
| 3455 | + |
|
| 3456 | + /** |
|
| 3457 | + * Get DB option by name |
|
| 3458 | + * @param string $option Option name |
|
| 3459 | + * @return mixed Option value or null if doesn't exist |
|
| 3460 | + */ |
|
| 3461 | + public function getOption($option) |
|
| 3462 | + { |
|
| 3463 | + if(isset($this->options[$option])) { |
|
| 3464 | + return $this->options[$option]; |
|
| 3465 | + } |
|
| 3466 | + return null; |
|
| 3467 | + } |
|
| 3468 | + |
|
| 3469 | + /** |
|
| 3470 | + * Commits pending changes to the database when the driver is setup to support transactions. |
|
| 3471 | + * Note that the default implementation is applicable for transaction-less or auto commit scenarios. |
|
| 3472 | + * @abstract |
|
| 3473 | + * @return bool true if commit succeeded, false if it failed |
|
| 3474 | + */ |
|
| 3475 | + public function commit() |
|
| 3476 | + { |
|
| 3477 | + $this->log->info("DBManager.commit() stub"); |
|
| 3478 | + return true; |
|
| 3479 | + } |
|
| 3480 | + |
|
| 3481 | + /** |
|
| 3482 | + * Rollsback pending changes to the database when the driver is setup to support transactions. |
|
| 3483 | + * Note that the default implementation is applicable for transaction-less or auto commit scenarios. |
|
| 3484 | + * Since rollbacks cannot be done, this implementation always returns false. |
|
| 3485 | + * @abstract |
|
| 3486 | + * @return bool true if rollback succeeded, false if it failed |
|
| 3487 | + */ |
|
| 3488 | + public function rollback() |
|
| 3489 | + { |
|
| 3490 | + $this->log->info("DBManager.rollback() stub"); |
|
| 3491 | + return false; |
|
| 3492 | + } |
|
| 3493 | + |
|
| 3494 | + /** |
|
| 3495 | + * Check if this DB name is valid |
|
| 3496 | + * |
|
| 3497 | + * @param string $name |
|
| 3498 | + * @return bool |
|
| 3499 | + */ |
|
| 3500 | + public function isDatabaseNameValid($name) |
|
| 3501 | + { |
|
| 3502 | + // Generic case - no slashes, no dots |
|
| 3503 | + return preg_match('#[/.\\\\]#', $name)==0; |
|
| 3504 | + } |
|
| 3505 | + |
|
| 3506 | + /** |
|
| 3507 | + * Check special requirements for DB installation. |
|
| 3508 | + * @abstract |
|
| 3509 | + * If everything is OK, return true. |
|
| 3510 | + * If something's wrong, return array of error code and parameters |
|
| 3511 | + * @return mixed |
|
| 3512 | + */ |
|
| 3513 | + public function canInstall() |
|
| 3514 | + { |
|
| 3515 | + return true; |
|
| 3516 | + } |
|
| 3517 | + |
|
| 3518 | + /** |
|
| 3519 | + * @abstract |
|
| 3520 | 3520 | * Code run on new database before installing |
| 3521 | - */ |
|
| 3522 | - public function preInstall() |
|
| 3523 | - { |
|
| 3524 | - } |
|
| 3521 | + */ |
|
| 3522 | + public function preInstall() |
|
| 3523 | + { |
|
| 3524 | + } |
|
| 3525 | + |
|
| 3526 | + /** |
|
| 3527 | + * @abstract |
|
| 3528 | + * Code run on new database after installing |
|
| 3529 | + */ |
|
| 3530 | + public function postInstall() |
|
| 3531 | + { |
|
| 3532 | + } |
|
| 3533 | + |
|
| 3534 | + /** |
|
| 3535 | + * Disable keys on the table |
|
| 3536 | + * @abstract |
|
| 3537 | + * @param string $tableName |
|
| 3538 | + */ |
|
| 3539 | + public function disableKeys($tableName) |
|
| 3540 | + { |
|
| 3541 | + } |
|
| 3525 | 3542 | |
| 3526 | - /** |
|
| 3543 | + /** |
|
| 3544 | + * Re-enable keys on the table |
|
| 3527 | 3545 | * @abstract |
| 3528 | - * Code run on new database after installing |
|
| 3529 | - */ |
|
| 3530 | - public function postInstall() |
|
| 3531 | - { |
|
| 3532 | - } |
|
| 3533 | - |
|
| 3534 | - /** |
|
| 3535 | - * Disable keys on the table |
|
| 3536 | - * @abstract |
|
| 3537 | - * @param string $tableName |
|
| 3538 | - */ |
|
| 3539 | - public function disableKeys($tableName) |
|
| 3540 | - { |
|
| 3541 | - } |
|
| 3542 | - |
|
| 3543 | - /** |
|
| 3544 | - * Re-enable keys on the table |
|
| 3545 | - * @abstract |
|
| 3546 | - * @param string $tableName |
|
| 3547 | - */ |
|
| 3548 | - public function enableKeys($tableName) |
|
| 3549 | - { |
|
| 3550 | - } |
|
| 3551 | - |
|
| 3552 | - /** |
|
| 3553 | - * Quote string in DB-specific manner |
|
| 3554 | - * @param string $string |
|
| 3555 | - * @return string |
|
| 3556 | - */ |
|
| 3557 | - abstract public function quote($string); |
|
| 3546 | + * @param string $tableName |
|
| 3547 | + */ |
|
| 3548 | + public function enableKeys($tableName) |
|
| 3549 | + { |
|
| 3550 | + } |
|
| 3551 | + |
|
| 3552 | + /** |
|
| 3553 | + * Quote string in DB-specific manner |
|
| 3554 | + * @param string $string |
|
| 3555 | + * @return string |
|
| 3556 | + */ |
|
| 3557 | + abstract public function quote($string); |
|
| 3558 | 3558 | |
| 3559 | 3559 | abstract public function quoteIdentifier($string); |
| 3560 | 3560 | |
| 3561 | - /** |
|
| 3562 | - * Use when you need to convert a database string to a different value; this function does it in a |
|
| 3563 | - * database-backend aware way |
|
| 3564 | - * Supported conversions: |
|
| 3565 | - * today return current date |
|
| 3566 | - * left Take substring from the left |
|
| 3567 | - * date_format Format date as string, supports %Y-%m-%d, %Y-%m, %Y |
|
| 3561 | + /** |
|
| 3562 | + * Use when you need to convert a database string to a different value; this function does it in a |
|
| 3563 | + * database-backend aware way |
|
| 3564 | + * Supported conversions: |
|
| 3565 | + * today return current date |
|
| 3566 | + * left Take substring from the left |
|
| 3567 | + * date_format Format date as string, supports %Y-%m-%d, %Y-%m, %Y |
|
| 3568 | 3568 | * time_format Format time as string |
| 3569 | 3569 | * date Convert date string to datetime value |
| 3570 | 3570 | * time Convert time string to datetime value |
| 3571 | - * datetime Convert datetime string to datetime value |
|
| 3572 | - * ifnull If var is null, use default value |
|
| 3573 | - * concat Concatenate strings |
|
| 3574 | - * quarter Quarter number of the date |
|
| 3575 | - * length Length of string |
|
| 3576 | - * month Month number of the date |
|
| 3577 | - * add_date Add specified interval to a date |
|
| 3571 | + * datetime Convert datetime string to datetime value |
|
| 3572 | + * ifnull If var is null, use default value |
|
| 3573 | + * concat Concatenate strings |
|
| 3574 | + * quarter Quarter number of the date |
|
| 3575 | + * length Length of string |
|
| 3576 | + * month Month number of the date |
|
| 3577 | + * add_date Add specified interval to a date |
|
| 3578 | 3578 | * add_time Add time interval to a date |
| 3579 | 3579 | * text2char Convert text field to varchar |
| 3580 | - * |
|
| 3581 | - * @param string $string database string to convert |
|
| 3582 | - * @param string $type type of conversion to do |
|
| 3583 | - * @param array $additional_parameters optional, additional parameters to pass to the db function |
|
| 3584 | - * @return string |
|
| 3585 | - */ |
|
| 3586 | - abstract public function convert($string, $type, array $additional_parameters = array()); |
|
| 3587 | - |
|
| 3588 | - /** |
|
| 3589 | - * Converts from Database data to app data |
|
| 3590 | - * |
|
| 3591 | - * Supported types |
|
| 3592 | - * - date |
|
| 3593 | - * - time |
|
| 3594 | - * - datetime |
|
| 3580 | + * |
|
| 3581 | + * @param string $string database string to convert |
|
| 3582 | + * @param string $type type of conversion to do |
|
| 3583 | + * @param array $additional_parameters optional, additional parameters to pass to the db function |
|
| 3584 | + * @return string |
|
| 3585 | + */ |
|
| 3586 | + abstract public function convert($string, $type, array $additional_parameters = array()); |
|
| 3587 | + |
|
| 3588 | + /** |
|
| 3589 | + * Converts from Database data to app data |
|
| 3590 | + * |
|
| 3591 | + * Supported types |
|
| 3592 | + * - date |
|
| 3593 | + * - time |
|
| 3594 | + * - datetime |
|
| 3595 | 3595 | * - datetimecombo |
| 3596 | 3596 | * - timestamp |
| 3597 | - * |
|
| 3598 | - * @param string $string database string to convert |
|
| 3599 | - * @param string $type type of conversion to do |
|
| 3600 | - * @return string |
|
| 3601 | - */ |
|
| 3602 | - abstract public function fromConvert($string, $type); |
|
| 3597 | + * |
|
| 3598 | + * @param string $string database string to convert |
|
| 3599 | + * @param string $type type of conversion to do |
|
| 3600 | + * @return string |
|
| 3601 | + */ |
|
| 3602 | + abstract public function fromConvert($string, $type); |
|
| 3603 | 3603 | |
| 3604 | 3604 | /** |
| 3605 | 3605 | * Parses and runs queries |
@@ -3611,7 +3611,7 @@ discard block |
||
| 3611 | 3611 | * @param bool $keepResult Keep query result in the object? |
| 3612 | 3612 | * @return resource|bool result set or success/failure bool |
| 3613 | 3613 | */ |
| 3614 | - abstract public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false); |
|
| 3614 | + abstract public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false); |
|
| 3615 | 3615 | |
| 3616 | 3616 | /** |
| 3617 | 3617 | * Runs a limit query: one where we specify where to start getting records and how many to get |
@@ -3624,173 +3624,173 @@ discard block |
||
| 3624 | 3624 | * @param bool $execute Execute or return SQL? |
| 3625 | 3625 | * @return resource query result |
| 3626 | 3626 | */ |
| 3627 | - abstract function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true); |
|
| 3628 | - |
|
| 3629 | - |
|
| 3630 | - /** |
|
| 3631 | - * Free Database result |
|
| 3632 | - * @param resource $dbResult |
|
| 3633 | - */ |
|
| 3634 | - abstract protected function freeDbResult($dbResult); |
|
| 3635 | - |
|
| 3636 | - /** |
|
| 3637 | - * Rename column in the DB |
|
| 3638 | - * @param string $tablename |
|
| 3639 | - * @param string $column |
|
| 3640 | - * @param string $newname |
|
| 3641 | - */ |
|
| 3642 | - abstract function renameColumnSQL($tablename, $column, $newname); |
|
| 3643 | - |
|
| 3644 | - /** |
|
| 3645 | - * Returns definitions of all indies for passed table. |
|
| 3646 | - * |
|
| 3647 | - * return will is a multi-dimensional array that |
|
| 3648 | - * categorizes the index definition by types, unique, primary and index. |
|
| 3649 | - * <code> |
|
| 3650 | - * <?php |
|
| 3651 | - * array( O |
|
| 3652 | - * 'index1'=> array ( |
|
| 3653 | - * 'name' => 'index1', |
|
| 3654 | - * 'type' => 'primary', |
|
| 3655 | - * 'fields' => array('field1','field2') |
|
| 3656 | - * ) |
|
| 3657 | - * ) |
|
| 3658 | - * ?> |
|
| 3659 | - * </code> |
|
| 3660 | - * This format is similar to how indicies are defined in vardef file. |
|
| 3661 | - * |
|
| 3662 | - * @param string $tablename |
|
| 3663 | - * @return array |
|
| 3664 | - */ |
|
| 3665 | - abstract public function get_indices($tablename); |
|
| 3666 | - |
|
| 3667 | - /** |
|
| 3668 | - * Returns definitions of all indies for passed table. |
|
| 3669 | - * |
|
| 3670 | - * return will is a multi-dimensional array that |
|
| 3671 | - * categorizes the index definition by types, unique, primary and index. |
|
| 3672 | - * <code> |
|
| 3673 | - * <?php |
|
| 3674 | - * array( |
|
| 3675 | - * 'field1'=> array ( |
|
| 3676 | - * 'name' => 'field1', |
|
| 3677 | - * 'type' => 'varchar', |
|
| 3678 | - * 'len' => '200' |
|
| 3679 | - * ) |
|
| 3680 | - * ) |
|
| 3681 | - * ?> |
|
| 3682 | - * </code> |
|
| 3683 | - * This format is similar to how indicies are defined in vardef file. |
|
| 3684 | - * |
|
| 3685 | - * @param string $tablename |
|
| 3686 | - * @return array |
|
| 3687 | - */ |
|
| 3688 | - abstract public function get_columns($tablename); |
|
| 3689 | - |
|
| 3690 | - /** |
|
| 3691 | - * Generates alter constraint statement given a table name and vardef definition. |
|
| 3692 | - * |
|
| 3693 | - * Supports both adding and droping a constraint. |
|
| 3694 | - * |
|
| 3695 | - * @param string $table tablename |
|
| 3696 | - * @param array $definition field definition |
|
| 3697 | - * @param bool $drop true if we are dropping the constraint, false if we are adding it |
|
| 3698 | - * @return string SQL statement |
|
| 3699 | - */ |
|
| 3700 | - abstract public function add_drop_constraint($table, $definition, $drop = false); |
|
| 3701 | - |
|
| 3702 | - /** |
|
| 3703 | - * Returns the description of fields based on the result |
|
| 3704 | - * |
|
| 3705 | - * @param resource $result |
|
| 3706 | - * @param boolean $make_lower_case |
|
| 3707 | - * @return array field array |
|
| 3708 | - */ |
|
| 3709 | - abstract public function getFieldsArray($result, $make_lower_case = false); |
|
| 3710 | - |
|
| 3711 | - /** |
|
| 3712 | - * Returns an array of tables for this database |
|
| 3713 | - * |
|
| 3714 | - * @return array|false an array of with table names, false if no tables found |
|
| 3715 | - */ |
|
| 3716 | - abstract public function getTablesArray(); |
|
| 3717 | - |
|
| 3718 | - /** |
|
| 3719 | - * Return's the version of the database |
|
| 3720 | - * |
|
| 3721 | - * @return string |
|
| 3722 | - */ |
|
| 3723 | - abstract public function version(); |
|
| 3724 | - |
|
| 3725 | - /** |
|
| 3726 | - * Checks if a table with the name $tableName exists |
|
| 3727 | - * and returns true if it does or false otherwise |
|
| 3728 | - * |
|
| 3729 | - * @param string $tableName |
|
| 3730 | - * @return bool |
|
| 3731 | - */ |
|
| 3732 | - abstract public function tableExists($tableName); |
|
| 3733 | - |
|
| 3734 | - /** |
|
| 3735 | - * Fetches the next row in the query result into an associative array |
|
| 3736 | - * |
|
| 3737 | - * @param resource $result |
|
| 3738 | - * @return array returns false if there are no more rows available to fetch |
|
| 3739 | - */ |
|
| 3740 | - abstract public function fetchRow($result); |
|
| 3741 | - |
|
| 3742 | - /** |
|
| 3743 | - * Connects to the database backend |
|
| 3744 | - * |
|
| 3745 | - * Takes in the database settings and opens a database connection based on those |
|
| 3746 | - * will open either a persistent or non-persistent connection. |
|
| 3747 | - * If a persistent connection is desired but not available it will defualt to non-persistent |
|
| 3748 | - * |
|
| 3749 | - * configOptions must include |
|
| 3750 | - * db_host_name - server ip |
|
| 3751 | - * db_user_name - database user name |
|
| 3752 | - * db_password - database password |
|
| 3753 | - * |
|
| 3754 | - * @param array $configOptions |
|
| 3755 | - * @param boolean $dieOnError |
|
| 3756 | - */ |
|
| 3757 | - abstract public function connect(array $configOptions = null, $dieOnError = false); |
|
| 3758 | - |
|
| 3759 | - /** |
|
| 3760 | - * Generates sql for create table statement for a bean. |
|
| 3761 | - * |
|
| 3762 | - * @param string $tablename |
|
| 3763 | - * @param array $fieldDefs |
|
| 3764 | - * @param array $indices |
|
| 3765 | - * @return string SQL Create Table statement |
|
| 3766 | - */ |
|
| 3767 | - abstract public function createTableSQLParams($tablename, $fieldDefs, $indices); |
|
| 3768 | - |
|
| 3769 | - /** |
|
| 3770 | - * Generates the SQL for changing columns |
|
| 3771 | - * |
|
| 3772 | - * @param string $tablename |
|
| 3773 | - * @param array $fieldDefs |
|
| 3774 | - * @param string $action |
|
| 3775 | - * @param bool $ignoreRequired Optional, true if we should ignor this being a required field |
|
| 3776 | - * @return string|array |
|
| 3777 | - */ |
|
| 3778 | - abstract protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false); |
|
| 3779 | - |
|
| 3780 | - /** |
|
| 3781 | - * Disconnects from the database |
|
| 3782 | - * |
|
| 3783 | - * Also handles any cleanup needed |
|
| 3784 | - */ |
|
| 3785 | - abstract public function disconnect(); |
|
| 3786 | - |
|
| 3787 | - /** |
|
| 3788 | - * Get last database error |
|
| 3789 | - * This function should return last error as reported by DB driver |
|
| 3790 | - * and should return false if no error condition happened |
|
| 3791 | - * @return string|false Error message or false if no error happened |
|
| 3792 | - */ |
|
| 3793 | - abstract public function lastDbError(); |
|
| 3627 | + abstract function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true); |
|
| 3628 | + |
|
| 3629 | + |
|
| 3630 | + /** |
|
| 3631 | + * Free Database result |
|
| 3632 | + * @param resource $dbResult |
|
| 3633 | + */ |
|
| 3634 | + abstract protected function freeDbResult($dbResult); |
|
| 3635 | + |
|
| 3636 | + /** |
|
| 3637 | + * Rename column in the DB |
|
| 3638 | + * @param string $tablename |
|
| 3639 | + * @param string $column |
|
| 3640 | + * @param string $newname |
|
| 3641 | + */ |
|
| 3642 | + abstract function renameColumnSQL($tablename, $column, $newname); |
|
| 3643 | + |
|
| 3644 | + /** |
|
| 3645 | + * Returns definitions of all indies for passed table. |
|
| 3646 | + * |
|
| 3647 | + * return will is a multi-dimensional array that |
|
| 3648 | + * categorizes the index definition by types, unique, primary and index. |
|
| 3649 | + * <code> |
|
| 3650 | + * <?php |
|
| 3651 | + * array( O |
|
| 3652 | + * 'index1'=> array ( |
|
| 3653 | + * 'name' => 'index1', |
|
| 3654 | + * 'type' => 'primary', |
|
| 3655 | + * 'fields' => array('field1','field2') |
|
| 3656 | + * ) |
|
| 3657 | + * ) |
|
| 3658 | + * ?> |
|
| 3659 | + * </code> |
|
| 3660 | + * This format is similar to how indicies are defined in vardef file. |
|
| 3661 | + * |
|
| 3662 | + * @param string $tablename |
|
| 3663 | + * @return array |
|
| 3664 | + */ |
|
| 3665 | + abstract public function get_indices($tablename); |
|
| 3666 | + |
|
| 3667 | + /** |
|
| 3668 | + * Returns definitions of all indies for passed table. |
|
| 3669 | + * |
|
| 3670 | + * return will is a multi-dimensional array that |
|
| 3671 | + * categorizes the index definition by types, unique, primary and index. |
|
| 3672 | + * <code> |
|
| 3673 | + * <?php |
|
| 3674 | + * array( |
|
| 3675 | + * 'field1'=> array ( |
|
| 3676 | + * 'name' => 'field1', |
|
| 3677 | + * 'type' => 'varchar', |
|
| 3678 | + * 'len' => '200' |
|
| 3679 | + * ) |
|
| 3680 | + * ) |
|
| 3681 | + * ?> |
|
| 3682 | + * </code> |
|
| 3683 | + * This format is similar to how indicies are defined in vardef file. |
|
| 3684 | + * |
|
| 3685 | + * @param string $tablename |
|
| 3686 | + * @return array |
|
| 3687 | + */ |
|
| 3688 | + abstract public function get_columns($tablename); |
|
| 3689 | + |
|
| 3690 | + /** |
|
| 3691 | + * Generates alter constraint statement given a table name and vardef definition. |
|
| 3692 | + * |
|
| 3693 | + * Supports both adding and droping a constraint. |
|
| 3694 | + * |
|
| 3695 | + * @param string $table tablename |
|
| 3696 | + * @param array $definition field definition |
|
| 3697 | + * @param bool $drop true if we are dropping the constraint, false if we are adding it |
|
| 3698 | + * @return string SQL statement |
|
| 3699 | + */ |
|
| 3700 | + abstract public function add_drop_constraint($table, $definition, $drop = false); |
|
| 3701 | + |
|
| 3702 | + /** |
|
| 3703 | + * Returns the description of fields based on the result |
|
| 3704 | + * |
|
| 3705 | + * @param resource $result |
|
| 3706 | + * @param boolean $make_lower_case |
|
| 3707 | + * @return array field array |
|
| 3708 | + */ |
|
| 3709 | + abstract public function getFieldsArray($result, $make_lower_case = false); |
|
| 3710 | + |
|
| 3711 | + /** |
|
| 3712 | + * Returns an array of tables for this database |
|
| 3713 | + * |
|
| 3714 | + * @return array|false an array of with table names, false if no tables found |
|
| 3715 | + */ |
|
| 3716 | + abstract public function getTablesArray(); |
|
| 3717 | + |
|
| 3718 | + /** |
|
| 3719 | + * Return's the version of the database |
|
| 3720 | + * |
|
| 3721 | + * @return string |
|
| 3722 | + */ |
|
| 3723 | + abstract public function version(); |
|
| 3724 | + |
|
| 3725 | + /** |
|
| 3726 | + * Checks if a table with the name $tableName exists |
|
| 3727 | + * and returns true if it does or false otherwise |
|
| 3728 | + * |
|
| 3729 | + * @param string $tableName |
|
| 3730 | + * @return bool |
|
| 3731 | + */ |
|
| 3732 | + abstract public function tableExists($tableName); |
|
| 3733 | + |
|
| 3734 | + /** |
|
| 3735 | + * Fetches the next row in the query result into an associative array |
|
| 3736 | + * |
|
| 3737 | + * @param resource $result |
|
| 3738 | + * @return array returns false if there are no more rows available to fetch |
|
| 3739 | + */ |
|
| 3740 | + abstract public function fetchRow($result); |
|
| 3741 | + |
|
| 3742 | + /** |
|
| 3743 | + * Connects to the database backend |
|
| 3744 | + * |
|
| 3745 | + * Takes in the database settings and opens a database connection based on those |
|
| 3746 | + * will open either a persistent or non-persistent connection. |
|
| 3747 | + * If a persistent connection is desired but not available it will defualt to non-persistent |
|
| 3748 | + * |
|
| 3749 | + * configOptions must include |
|
| 3750 | + * db_host_name - server ip |
|
| 3751 | + * db_user_name - database user name |
|
| 3752 | + * db_password - database password |
|
| 3753 | + * |
|
| 3754 | + * @param array $configOptions |
|
| 3755 | + * @param boolean $dieOnError |
|
| 3756 | + */ |
|
| 3757 | + abstract public function connect(array $configOptions = null, $dieOnError = false); |
|
| 3758 | + |
|
| 3759 | + /** |
|
| 3760 | + * Generates sql for create table statement for a bean. |
|
| 3761 | + * |
|
| 3762 | + * @param string $tablename |
|
| 3763 | + * @param array $fieldDefs |
|
| 3764 | + * @param array $indices |
|
| 3765 | + * @return string SQL Create Table statement |
|
| 3766 | + */ |
|
| 3767 | + abstract public function createTableSQLParams($tablename, $fieldDefs, $indices); |
|
| 3768 | + |
|
| 3769 | + /** |
|
| 3770 | + * Generates the SQL for changing columns |
|
| 3771 | + * |
|
| 3772 | + * @param string $tablename |
|
| 3773 | + * @param array $fieldDefs |
|
| 3774 | + * @param string $action |
|
| 3775 | + * @param bool $ignoreRequired Optional, true if we should ignor this being a required field |
|
| 3776 | + * @return string|array |
|
| 3777 | + */ |
|
| 3778 | + abstract protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false); |
|
| 3779 | + |
|
| 3780 | + /** |
|
| 3781 | + * Disconnects from the database |
|
| 3782 | + * |
|
| 3783 | + * Also handles any cleanup needed |
|
| 3784 | + */ |
|
| 3785 | + abstract public function disconnect(); |
|
| 3786 | + |
|
| 3787 | + /** |
|
| 3788 | + * Get last database error |
|
| 3789 | + * This function should return last error as reported by DB driver |
|
| 3790 | + * and should return false if no error condition happened |
|
| 3791 | + * @return string|false Error message or false if no error happened |
|
| 3792 | + */ |
|
| 3793 | + abstract public function lastDbError(); |
|
| 3794 | 3794 | |
| 3795 | 3795 | /** |
| 3796 | 3796 | * Check if this query is valid |
@@ -3798,82 +3798,82 @@ discard block |
||
| 3798 | 3798 | * @param string $query |
| 3799 | 3799 | * @return bool |
| 3800 | 3800 | */ |
| 3801 | - abstract public function validateQuery($query); |
|
| 3802 | - |
|
| 3803 | - /** |
|
| 3804 | - * Check if this driver can be used |
|
| 3805 | - * @return bool |
|
| 3806 | - */ |
|
| 3807 | - abstract public function valid(); |
|
| 3808 | - |
|
| 3809 | - /** |
|
| 3810 | - * Check if certain database exists |
|
| 3811 | - * @param string $dbname |
|
| 3812 | - */ |
|
| 3813 | - abstract public function dbExists($dbname); |
|
| 3814 | - |
|
| 3815 | - /** |
|
| 3816 | - * Get tables like expression |
|
| 3817 | - * @param string $like Expression describing tables |
|
| 3818 | - * @return array |
|
| 3819 | - */ |
|
| 3820 | - abstract public function tablesLike($like); |
|
| 3821 | - |
|
| 3822 | - /** |
|
| 3823 | - * Create a database |
|
| 3824 | - * @param string $dbname |
|
| 3825 | - */ |
|
| 3826 | - abstract public function createDatabase($dbname); |
|
| 3827 | - |
|
| 3828 | - /** |
|
| 3829 | - * Drop a database |
|
| 3830 | - * @param string $dbname |
|
| 3831 | - */ |
|
| 3832 | - abstract public function dropDatabase($dbname); |
|
| 3833 | - |
|
| 3834 | - /** |
|
| 3835 | - * Get database configuration information (DB-dependent) |
|
| 3836 | - * @return array|null |
|
| 3837 | - */ |
|
| 3838 | - abstract public function getDbInfo(); |
|
| 3839 | - |
|
| 3840 | - /** |
|
| 3841 | - * Check if certain DB user exists |
|
| 3842 | - * @param string $username |
|
| 3843 | - */ |
|
| 3844 | - abstract public function userExists($username); |
|
| 3845 | - |
|
| 3846 | - /** |
|
| 3847 | - * Create DB user |
|
| 3848 | - * @param string $database_name |
|
| 3849 | - * @param string $host_name |
|
| 3850 | - * @param string $user |
|
| 3851 | - * @param string $password |
|
| 3852 | - */ |
|
| 3853 | - abstract public function createDbUser($database_name, $host_name, $user, $password); |
|
| 3854 | - |
|
| 3855 | - /** |
|
| 3856 | - * Check if the database supports fulltext indexing |
|
| 3857 | - * Note that database driver can be capable of supporting FT (see supports('fulltext)) |
|
| 3858 | - * but particular instance can still have it disabled |
|
| 3859 | - * @return bool |
|
| 3860 | - */ |
|
| 3861 | - abstract public function full_text_indexing_installed(); |
|
| 3862 | - |
|
| 3863 | - /** |
|
| 3864 | - * Generate fulltext query from set of terms |
|
| 3865 | - * @param string $field Field to search against |
|
| 3866 | - * @param array $terms Search terms that may be or not be in the result |
|
| 3867 | - * @param array $must_terms Search terms that have to be in the result |
|
| 3868 | - * @param array $exclude_terms Search terms that have to be not in the result |
|
| 3869 | - */ |
|
| 3870 | - abstract public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()); |
|
| 3871 | - |
|
| 3872 | - /** |
|
| 3873 | - * Get install configuration for this DB |
|
| 3874 | - * @return array |
|
| 3875 | - */ |
|
| 3876 | - abstract public function installConfig(); |
|
| 3801 | + abstract public function validateQuery($query); |
|
| 3802 | + |
|
| 3803 | + /** |
|
| 3804 | + * Check if this driver can be used |
|
| 3805 | + * @return bool |
|
| 3806 | + */ |
|
| 3807 | + abstract public function valid(); |
|
| 3808 | + |
|
| 3809 | + /** |
|
| 3810 | + * Check if certain database exists |
|
| 3811 | + * @param string $dbname |
|
| 3812 | + */ |
|
| 3813 | + abstract public function dbExists($dbname); |
|
| 3814 | + |
|
| 3815 | + /** |
|
| 3816 | + * Get tables like expression |
|
| 3817 | + * @param string $like Expression describing tables |
|
| 3818 | + * @return array |
|
| 3819 | + */ |
|
| 3820 | + abstract public function tablesLike($like); |
|
| 3821 | + |
|
| 3822 | + /** |
|
| 3823 | + * Create a database |
|
| 3824 | + * @param string $dbname |
|
| 3825 | + */ |
|
| 3826 | + abstract public function createDatabase($dbname); |
|
| 3827 | + |
|
| 3828 | + /** |
|
| 3829 | + * Drop a database |
|
| 3830 | + * @param string $dbname |
|
| 3831 | + */ |
|
| 3832 | + abstract public function dropDatabase($dbname); |
|
| 3833 | + |
|
| 3834 | + /** |
|
| 3835 | + * Get database configuration information (DB-dependent) |
|
| 3836 | + * @return array|null |
|
| 3837 | + */ |
|
| 3838 | + abstract public function getDbInfo(); |
|
| 3839 | + |
|
| 3840 | + /** |
|
| 3841 | + * Check if certain DB user exists |
|
| 3842 | + * @param string $username |
|
| 3843 | + */ |
|
| 3844 | + abstract public function userExists($username); |
|
| 3845 | + |
|
| 3846 | + /** |
|
| 3847 | + * Create DB user |
|
| 3848 | + * @param string $database_name |
|
| 3849 | + * @param string $host_name |
|
| 3850 | + * @param string $user |
|
| 3851 | + * @param string $password |
|
| 3852 | + */ |
|
| 3853 | + abstract public function createDbUser($database_name, $host_name, $user, $password); |
|
| 3854 | + |
|
| 3855 | + /** |
|
| 3856 | + * Check if the database supports fulltext indexing |
|
| 3857 | + * Note that database driver can be capable of supporting FT (see supports('fulltext)) |
|
| 3858 | + * but particular instance can still have it disabled |
|
| 3859 | + * @return bool |
|
| 3860 | + */ |
|
| 3861 | + abstract public function full_text_indexing_installed(); |
|
| 3862 | + |
|
| 3863 | + /** |
|
| 3864 | + * Generate fulltext query from set of terms |
|
| 3865 | + * @param string $field Field to search against |
|
| 3866 | + * @param array $terms Search terms that may be or not be in the result |
|
| 3867 | + * @param array $must_terms Search terms that have to be in the result |
|
| 3868 | + * @param array $exclude_terms Search terms that have to be not in the result |
|
| 3869 | + */ |
|
| 3870 | + abstract public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()); |
|
| 3871 | + |
|
| 3872 | + /** |
|
| 3873 | + * Get install configuration for this DB |
|
| 3874 | + * @return array |
|
| 3875 | + */ |
|
| 3876 | + abstract public function installConfig(); |
|
| 3877 | 3877 | |
| 3878 | 3878 | /** |
| 3879 | 3879 | * Returns a DB specific FROM clause which can be used to select against functions. |
@@ -3890,5 +3890,5 @@ discard block |
||
| 3890 | 3890 | * @abstract |
| 3891 | 3891 | * @return string |
| 3892 | 3892 | */ |
| 3893 | - abstract public function getGuidSQL(); |
|
| 3893 | + abstract public function getGuidSQL(); |
|
| 3894 | 3894 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | $dberror = $this->lastDbError(); |
| 317 | - if($dberror === false) { |
|
| 317 | + if ($dberror === false) { |
|
| 318 | 318 | $this->last_error = false; |
| 319 | 319 | return false; |
| 320 | 320 | } |
@@ -332,16 +332,16 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | protected function registerError($userMessage, $message, $dieOnError = false) |
| 334 | 334 | { |
| 335 | - if(!empty($message)) { |
|
| 336 | - if(!empty($userMessage)) { |
|
| 335 | + if (!empty($message)) { |
|
| 336 | + if (!empty($userMessage)) { |
|
| 337 | 337 | $message = "$userMessage: $message"; |
| 338 | 338 | } |
| 339 | - if(empty($message)) { |
|
| 339 | + if (empty($message)) { |
|
| 340 | 340 | $message = "Database error"; |
| 341 | 341 | } |
| 342 | 342 | $this->log->fatal($message); |
| 343 | 343 | if ($dieOnError || $this->dieOnError) { |
| 344 | - if(isset($GLOBALS['app_strings']['ERR_DB_FAIL'])) { |
|
| 344 | + if (isset($GLOBALS['app_strings']['ERR_DB_FAIL'])) { |
|
| 345 | 345 | sugar_die($GLOBALS['app_strings']['ERR_DB_FAIL']); |
| 346 | 346 | } else { |
| 347 | 347 | sugar_die("Database error. Please check suitecrm.log for details."); |
@@ -379,8 +379,8 @@ discard block |
||
| 379 | 379 | $slow_query_time_msec = isset($sugar_config['slow_query_time_msec']) |
| 380 | 380 | ? $sugar_config['slow_query_time_msec'] : 5000; |
| 381 | 381 | |
| 382 | - if($do_the_dump) { |
|
| 383 | - if($slow_query_time_msec < ($this->query_time * 1000)) { |
|
| 382 | + if ($do_the_dump) { |
|
| 383 | + if ($slow_query_time_msec < ($this->query_time * 1000)) { |
|
| 384 | 384 | // Then log both the query and the query time |
| 385 | 385 | $this->log->fatal('Slow Query (time:'.$this->query_time."\n".$query); |
| 386 | 386 | return true; |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
| 413 | 413 | |
| 414 | 414 | if (empty($indices)) { |
| 415 | - foreach ( $GLOBALS['dictionary'] as $current ) { |
|
| 416 | - if ($current['table'] == $table){ |
|
| 415 | + foreach ($GLOBALS['dictionary'] as $current) { |
|
| 416 | + if ($current['table'] == $table) { |
|
| 417 | 417 | $indices = $current['indices']; |
| 418 | 418 | break; |
| 419 | 419 | } |
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | if (empty($indices)) { |
| 423 | - $this->log->warn('CHECK QUERY: Could not find index definitions for table ' . $table); |
|
| 423 | + $this->log->warn('CHECK QUERY: Could not find index definitions for table '.$table); |
|
| 424 | 424 | return false; |
| 425 | 425 | } |
| 426 | 426 | if (!empty($match[2][0])) { |
| 427 | 427 | $orderBys = explode(' ', $match[2][0]); |
| 428 | - foreach ($orderBys as $orderBy){ |
|
| 428 | + foreach ($orderBys as $orderBy) { |
|
| 429 | 429 | $orderBy = trim($orderBy); |
| 430 | 430 | if (empty($orderBy)) |
| 431 | 431 | continue; |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | if ($orderBy == 'asc' || $orderBy == 'desc') |
| 434 | 434 | continue; |
| 435 | 435 | |
| 436 | - $orderBy = str_replace(array($table . '.', ','), '', $orderBy); |
|
| 436 | + $orderBy = str_replace(array($table.'.', ','), '', $orderBy); |
|
| 437 | 437 | |
| 438 | 438 | foreach ($indices as $index) |
| 439 | 439 | if (empty($index['db']) || $index['db'] == $this->dbType) |
@@ -441,11 +441,11 @@ discard block |
||
| 441 | 441 | if ($field == $orderBy) |
| 442 | 442 | return true; |
| 443 | 443 | |
| 444 | - $warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy ; |
|
| 444 | + $warning = 'Missing Index For Order By Table: '.$table.' Order By:'.$orderBy; |
|
| 445 | 445 | if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) |
| 446 | - $this->log->fatal('CHECK QUERY:' .$warning); |
|
| 446 | + $this->log->fatal('CHECK QUERY:'.$warning); |
|
| 447 | 447 | else |
| 448 | - $this->log->warn('CHECK QUERY:' .$warning); |
|
| 448 | + $this->log->warn('CHECK QUERY:'.$warning); |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | return false; |
@@ -491,9 +491,9 @@ discard block |
||
| 491 | 491 | public function insert(SugarBean $bean) |
| 492 | 492 | { |
| 493 | 493 | $sql = $this->insertSQL($bean); |
| 494 | - $tablename = $bean->getTableName(); |
|
| 494 | + $tablename = $bean->getTableName(); |
|
| 495 | 495 | $msg = "Error inserting into table: $tablename:"; |
| 496 | - return $this->query($sql,true,$msg); |
|
| 496 | + return $this->query($sql, true, $msg); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -512,13 +512,13 @@ discard block |
||
| 512 | 512 | { |
| 513 | 513 | if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
| 514 | 514 | //custom fields handle there save seperatley |
| 515 | - if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue; |
|
| 515 | + if (!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue; |
|
| 516 | 516 | |
| 517 | - if(isset($data[$field])) { |
|
| 517 | + if (isset($data[$field])) { |
|
| 518 | 518 | // clean the incoming value.. |
| 519 | 519 | $val = from_html($data[$field]); |
| 520 | 520 | } else { |
| 521 | - if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 521 | + if (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 522 | 522 | $val = $fieldDef['default']; |
| 523 | 523 | } else { |
| 524 | 524 | $val = null; |
@@ -528,26 +528,26 @@ discard block |
||
| 528 | 528 | //handle auto increment values here - we may have to do something like nextval for oracle |
| 529 | 529 | if (!empty($fieldDef['auto_increment'])) { |
| 530 | 530 | $auto = $this->getAutoIncrementSQL($table, $fieldDef['name']); |
| 531 | - if(!empty($auto)) { |
|
| 531 | + if (!empty($auto)) { |
|
| 532 | 532 | $values[$field] = $auto; |
| 533 | 533 | } |
| 534 | 534 | } elseif ($fieldDef['name'] == 'deleted') { |
| 535 | 535 | $values['deleted'] = (int)$val; |
| 536 | 536 | } else { |
| 537 | 537 | // need to do some thing about types of values |
| 538 | - if(!is_null($val) || !empty($fieldDef['required'])) { |
|
| 538 | + if (!is_null($val) || !empty($fieldDef['required'])) { |
|
| 539 | 539 | $values[$field] = $this->massageValue($val, $fieldDef); |
| 540 | 540 | } |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | if (empty($values)) |
| 545 | - return $execute?true:''; // no columns set |
|
| 545 | + return $execute ? true : ''; // no columns set |
|
| 546 | 546 | |
| 547 | 547 | // get the entire sql |
| 548 | 548 | $query = "INSERT INTO $table (".implode(",", array_keys($values)).") |
| 549 | 549 | VALUES (".implode(",", $values).")"; |
| 550 | - return $execute?$this->query($query):$query; |
|
| 550 | + return $execute ? $this->query($query) : $query; |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -565,7 +565,7 @@ discard block |
||
| 565 | 565 | $sql = $this->updateSQL($bean, $where); |
| 566 | 566 | $tablename = $bean->getTableName(); |
| 567 | 567 | $msg = "Error updating table: $tablename:"; |
| 568 | - return $this->query($sql,true,$msg); |
|
| 568 | + return $this->query($sql, true, $msg); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /** |
@@ -581,8 +581,8 @@ discard block |
||
| 581 | 581 | { |
| 582 | 582 | $sql = $this->deleteSQL($bean, $where); |
| 583 | 583 | $tableName = $bean->getTableName(); |
| 584 | - $msg = "Error deleting from table: ".$tableName. ":"; |
|
| 585 | - return $this->query($sql,true,$msg); |
|
| 584 | + $msg = "Error deleting from table: ".$tableName.":"; |
|
| 585 | + return $this->query($sql, true, $msg); |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | /** |
@@ -599,8 +599,8 @@ discard block |
||
| 599 | 599 | { |
| 600 | 600 | $sql = $this->retrieveSQL($bean, $where); |
| 601 | 601 | $tableName = $bean->getTableName(); |
| 602 | - $msg = "Error retriving values from table:".$tableName. ":"; |
|
| 603 | - return $this->query($sql,true,$msg); |
|
| 602 | + $msg = "Error retriving values from table:".$tableName.":"; |
|
| 603 | + return $this->query($sql, true, $msg); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | { |
| 624 | 624 | $sql = $this->retrieveViewSQL($beans, $cols, $where); |
| 625 | 625 | $msg = "Error retriving values from View Collection:"; |
| 626 | - return $this->query($sql,true,$msg); |
|
| 626 | + return $this->query($sql, true, $msg); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | $sql = $this->createTableSQL($bean); |
| 639 | 639 | $tablename = $bean->getTableName(); |
| 640 | 640 | $msg = "Error creating table: $tablename:"; |
| 641 | - $this->query($sql,true,$msg); |
|
| 642 | - if(!$this->supports("inline_keys")) { |
|
| 641 | + $this->query($sql, true, $msg); |
|
| 642 | + if (!$this->supports("inline_keys")) { |
|
| 643 | 643 | // handle constraints and indices |
| 644 | 644 | $indicesArr = $this->createConstraintSql($bean); |
| 645 | 645 | if (count($indicesArr) > 0) |
@@ -676,9 +676,9 @@ discard block |
||
| 676 | 676 | $res = true; |
| 677 | 677 | if ($sql) { |
| 678 | 678 | $msg = "Error creating table: $tablename"; |
| 679 | - $res = ($res and $this->query($sql,true,$msg)); |
|
| 679 | + $res = ($res and $this->query($sql, true, $msg)); |
|
| 680 | 680 | } |
| 681 | - if(!$this->supports("inline_keys")) { |
|
| 681 | + if (!$this->supports("inline_keys")) { |
|
| 682 | 682 | // handle constraints and indices |
| 683 | 683 | $indicesArr = $this->getConstraintSql($indices, $tablename); |
| 684 | 684 | if (count($indicesArr) > 0) |
@@ -705,20 +705,20 @@ discard block |
||
| 705 | 705 | |
| 706 | 706 | //Clean the indexes to prevent duplicate definitions |
| 707 | 707 | $new_index = array(); |
| 708 | - foreach($indices as $ind_def){ |
|
| 708 | + foreach ($indices as $ind_def) { |
|
| 709 | 709 | $new_index[$ind_def['name']] = $ind_def; |
| 710 | 710 | } |
| 711 | 711 | //jc: added this for beans that do not actually have a table, namely |
| 712 | 712 | //ForecastOpportunities |
| 713 | - if($tablename == 'does_not_exist' || $tablename == '') |
|
| 713 | + if ($tablename == 'does_not_exist' || $tablename == '') |
|
| 714 | 714 | return ''; |
| 715 | 715 | |
| 716 | 716 | global $dictionary; |
| 717 | - $engine=null; |
|
| 718 | - if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) |
|
| 717 | + $engine = null; |
|
| 718 | + if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine'])) |
|
| 719 | 719 | $engine = $dictionary[$bean->getObjectName()]['engine']; |
| 720 | 720 | |
| 721 | - return $this->repairTableParams($tablename, $fielddefs,$new_index,$execute,$engine); |
|
| 721 | + return $this->repairTableParams($tablename, $fielddefs, $new_index, $execute, $engine); |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -730,12 +730,12 @@ discard block |
||
| 730 | 730 | protected function isNullable($vardef) |
| 731 | 731 | { |
| 732 | 732 | |
| 733 | - if(isset($vardef['isnull']) && (strtolower($vardef['isnull']) == 'false' || $vardef['isnull'] === false) |
|
| 733 | + if (isset($vardef['isnull']) && (strtolower($vardef['isnull']) == 'false' || $vardef['isnull'] === false) |
|
| 734 | 734 | && !empty($vardef['required'])) { |
| 735 | 735 | /* required + is_null=false => not null */ |
| 736 | 736 | return false; |
| 737 | 737 | } |
| 738 | - if(empty($vardef['auto_increment']) && (empty($vardef['type']) || $vardef['type'] != 'id') |
|
| 738 | + if (empty($vardef['auto_increment']) && (empty($vardef['type']) || $vardef['type'] != 'id') |
|
| 739 | 739 | && (empty($vardef['dbType']) || $vardef['dbType'] != 'id') |
| 740 | 740 | && (empty($vardef['name']) || ($vardef['name'] != 'id' && $vardef['name'] != 'deleted')) |
| 741 | 741 | ) { |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | * @todo: refactor engine param to be more generic |
| 757 | 757 | * @return string |
| 758 | 758 | */ |
| 759 | - public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 759 | + public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 760 | 760 | { |
| 761 | 761 | //jc: had a bug when running the repair if the tablename is blank the repair will |
| 762 | 762 | //fail when it tries to create a repair table |
@@ -766,13 +766,13 @@ discard block |
||
| 766 | 766 | //if the table does not exist create it and we are done |
| 767 | 767 | $sql = "/* Table : $tablename */\n"; |
| 768 | 768 | if (!$this->tableExists($tablename)) { |
| 769 | - $createtablesql = $this->createTableSQLParams($tablename,$fielddefs,$indices,$engine); |
|
| 770 | - if($execute && $createtablesql){ |
|
| 771 | - $this->createTableParams($tablename,$fielddefs,$indices,$engine); |
|
| 769 | + $createtablesql = $this->createTableSQLParams($tablename, $fielddefs, $indices, $engine); |
|
| 770 | + if ($execute && $createtablesql) { |
|
| 771 | + $this->createTableParams($tablename, $fielddefs, $indices, $engine); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | $sql .= "/* MISSING TABLE: {$tablename} */\n"; |
| 775 | - $sql .= $createtablesql . "\n"; |
|
| 775 | + $sql .= $createtablesql."\n"; |
|
| 776 | 776 | return $sql; |
| 777 | 777 | } |
| 778 | 778 | |
@@ -782,7 +782,7 @@ discard block |
||
| 782 | 782 | $take_action = false; |
| 783 | 783 | |
| 784 | 784 | // do column comparisons |
| 785 | - $sql .= "/*COLUMNS*/\n"; |
|
| 785 | + $sql .= "/*COLUMNS*/\n"; |
|
| 786 | 786 | foreach ($fielddefs as $name => $value) { |
| 787 | 787 | if (isset($value['source']) && $value['source'] != 'db') |
| 788 | 788 | continue; |
@@ -801,9 +801,9 @@ discard block |
||
| 801 | 801 | |
| 802 | 802 | $name = strtolower($value['name']); |
| 803 | 803 | // add or fix the field defs per what the DB is expected to give us back |
| 804 | - $this->massageFieldDef($value,$tablename); |
|
| 804 | + $this->massageFieldDef($value, $tablename); |
|
| 805 | 805 | |
| 806 | - $ignorerequired=false; |
|
| 806 | + $ignorerequired = false; |
|
| 807 | 807 | |
| 808 | 808 | //Do not track requiredness in the DB, auto_increment, ID, |
| 809 | 809 | // and deleted fields are always required in the DB, so don't force those |
@@ -819,32 +819,32 @@ discard block |
||
| 819 | 819 | $value['required'] = $compareFieldDefs[$name]['required']; |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - if ( !isset($compareFieldDefs[$name]) ) { |
|
| 822 | + if (!isset($compareFieldDefs[$name])) { |
|
| 823 | 823 | // ok we need this field lets create it |
| 824 | - $sql .= "/*MISSING IN DATABASE - $name - ROW*/\n"; |
|
| 825 | - $sql .= $this->addColumnSQL($tablename, $value) . "\n"; |
|
| 824 | + $sql .= "/*MISSING IN DATABASE - $name - ROW*/\n"; |
|
| 825 | + $sql .= $this->addColumnSQL($tablename, $value)."\n"; |
|
| 826 | 826 | if ($execute) |
| 827 | 827 | $this->addColumn($tablename, $value); |
| 828 | 828 | $take_action = true; |
| 829 | - } elseif ( !$this->compareVarDefs($compareFieldDefs[$name],$value)) { |
|
| 829 | + } elseif (!$this->compareVarDefs($compareFieldDefs[$name], $value)) { |
|
| 830 | 830 | //fields are different lets alter it |
| 831 | - $sql .= "/*MISMATCH WITH DATABASE - $name - ROW "; |
|
| 832 | - foreach($compareFieldDefs[$name] as $rKey => $rValue) { |
|
| 833 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 831 | + $sql .= "/*MISMATCH WITH DATABASE - $name - ROW "; |
|
| 832 | + foreach ($compareFieldDefs[$name] as $rKey => $rValue) { |
|
| 833 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 834 | 834 | } |
| 835 | - $sql .= "*/\n"; |
|
| 836 | - $sql .= "/* VARDEF - $name - ROW"; |
|
| 837 | - foreach($value as $rKey => $rValue) { |
|
| 838 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 835 | + $sql .= "*/\n"; |
|
| 836 | + $sql .= "/* VARDEF - $name - ROW"; |
|
| 837 | + foreach ($value as $rKey => $rValue) { |
|
| 838 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 839 | 839 | } |
| 840 | - $sql .= "*/\n"; |
|
| 840 | + $sql .= "*/\n"; |
|
| 841 | 841 | |
| 842 | 842 | //jc: oracle will complain if you try to execute a statement that sets a column to (not) null |
| 843 | 843 | //when it is already (not) null |
| 844 | - if ( isset($value['isnull']) && isset($compareFieldDefs[$name]['isnull']) && |
|
| 844 | + if (isset($value['isnull']) && isset($compareFieldDefs[$name]['isnull']) && |
|
| 845 | 845 | $value['isnull'] === $compareFieldDefs[$name]['isnull']) { |
| 846 | 846 | unset($value['required']); |
| 847 | - $ignorerequired=true; |
|
| 847 | + $ignorerequired = true; |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | //dwheeler: Once a column has been defined as null, we cannot try to force it back to !null |
@@ -853,12 +853,12 @@ discard block |
||
| 853 | 853 | { |
| 854 | 854 | $ignorerequired = true; |
| 855 | 855 | } |
| 856 | - $altersql = $this->alterColumnSQL($tablename, $value,$ignorerequired); |
|
| 857 | - if(is_array($altersql)) { |
|
| 856 | + $altersql = $this->alterColumnSQL($tablename, $value, $ignorerequired); |
|
| 857 | + if (is_array($altersql)) { |
|
| 858 | 858 | $altersql = join("\n", $altersql); |
| 859 | 859 | } |
| 860 | - $sql .= $altersql . "\n"; |
|
| 861 | - if($execute){ |
|
| 860 | + $sql .= $altersql."\n"; |
|
| 861 | + if ($execute) { |
|
| 862 | 862 | $this->alterColumn($tablename, $value, $ignorerequired); |
| 863 | 863 | } |
| 864 | 864 | $take_action = true; |
@@ -866,13 +866,13 @@ discard block |
||
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | // do index comparisons |
| 869 | - $sql .= "/* INDEXES */\n"; |
|
| 869 | + $sql .= "/* INDEXES */\n"; |
|
| 870 | 870 | $correctedIndexs = array(); |
| 871 | 871 | |
| 872 | 872 | $compareIndices_case_insensitive = array(); |
| 873 | 873 | |
| 874 | 874 | // do indices comparisons case-insensitive |
| 875 | - foreach($compareIndices as $k => $value){ |
|
| 875 | + foreach ($compareIndices as $k => $value) { |
|
| 876 | 876 | $value['name'] = strtolower($value['name']); |
| 877 | 877 | $compareIndices_case_insensitive[strtolower($k)] = $value; |
| 878 | 878 | } |
@@ -899,59 +899,59 @@ discard block |
||
| 899 | 899 | continue; |
| 900 | 900 | |
| 901 | 901 | //database helpers do not know how to handle full text indices |
| 902 | - if ($value['type']=='fulltext') |
|
| 902 | + if ($value['type'] == 'fulltext') |
|
| 903 | 903 | continue; |
| 904 | 904 | |
| 905 | - if ( in_array($value['type'],array('alternate_key','foreign')) ) |
|
| 905 | + if (in_array($value['type'], array('alternate_key', 'foreign'))) |
|
| 906 | 906 | $value['type'] = 'index'; |
| 907 | 907 | |
| 908 | - if ( !isset($compareIndices[$name]) ) { |
|
| 908 | + if (!isset($compareIndices[$name])) { |
|
| 909 | 909 | //First check if an index exists that doesn't match our name, if so, try to rename it |
| 910 | 910 | $found = false; |
| 911 | 911 | foreach ($compareIndices as $ex_name => $ex_value) { |
| 912 | - if($this->compareVarDefs($ex_value, $value, true)) { |
|
| 912 | + if ($this->compareVarDefs($ex_value, $value, true)) { |
|
| 913 | 913 | $found = $ex_name; |
| 914 | 914 | break; |
| 915 | 915 | } |
| 916 | 916 | } |
| 917 | 917 | if ($found) { |
| 918 | - $sql .= "/*MISSNAMED INDEX IN DATABASE - $name - $ex_name */\n"; |
|
| 918 | + $sql .= "/*MISSNAMED INDEX IN DATABASE - $name - $ex_name */\n"; |
|
| 919 | 919 | $rename = $this->renameIndexDefs($ex_value, $value, $tablename); |
| 920 | - if($execute) { |
|
| 920 | + if ($execute) { |
|
| 921 | 921 | $this->query($rename, true, "Cannot rename index"); |
| 922 | 922 | } |
| 923 | - $sql .= is_array($rename)?join("\n", $rename). "\n":$rename."\n"; |
|
| 923 | + $sql .= is_array($rename) ? join("\n", $rename)."\n" : $rename."\n"; |
|
| 924 | 924 | |
| 925 | 925 | } else { |
| 926 | 926 | // ok we need this field lets create it |
| 927 | - $sql .= "/*MISSING INDEX IN DATABASE - $name -{$value['type']} ROW */\n"; |
|
| 928 | - $sql .= $this->addIndexes($tablename,array($value), $execute) . "\n"; |
|
| 927 | + $sql .= "/*MISSING INDEX IN DATABASE - $name -{$value['type']} ROW */\n"; |
|
| 928 | + $sql .= $this->addIndexes($tablename, array($value), $execute)."\n"; |
|
| 929 | 929 | } |
| 930 | 930 | $take_action = true; |
| 931 | 931 | $correctedIndexs[$name] = true; |
| 932 | - } elseif ( !$this->compareVarDefs($compareIndices[$name],$value) ) { |
|
| 932 | + } elseif (!$this->compareVarDefs($compareIndices[$name], $value)) { |
|
| 933 | 933 | // fields are different lets alter it |
| 934 | - $sql .= "/*INDEX MISMATCH WITH DATABASE - $name - ROW "; |
|
| 934 | + $sql .= "/*INDEX MISMATCH WITH DATABASE - $name - ROW "; |
|
| 935 | 935 | foreach ($compareIndices[$name] as $n1 => $t1) { |
| 936 | - $sql .= "<$n1>"; |
|
| 937 | - if ( $n1 == 'fields' ) |
|
| 938 | - foreach($t1 as $rKey => $rValue) |
|
| 936 | + $sql .= "<$n1>"; |
|
| 937 | + if ($n1 == 'fields') |
|
| 938 | + foreach ($t1 as $rKey => $rValue) |
|
| 939 | 939 | $sql .= "[$rKey] => '$rValue' "; |
| 940 | 940 | else |
| 941 | 941 | $sql .= " $t1 "; |
| 942 | 942 | } |
| 943 | - $sql .= "*/\n"; |
|
| 944 | - $sql .= "/* VARDEF - $name - ROW"; |
|
| 943 | + $sql .= "*/\n"; |
|
| 944 | + $sql .= "/* VARDEF - $name - ROW"; |
|
| 945 | 945 | foreach ($value as $n1 => $t1) { |
| 946 | - $sql .= "<$n1>"; |
|
| 947 | - if ( $n1 == 'fields' ) |
|
| 946 | + $sql .= "<$n1>"; |
|
| 947 | + if ($n1 == 'fields') |
|
| 948 | 948 | foreach ($t1 as $rKey => $rValue) |
| 949 | - $sql .= "[$rKey] => '$rValue' "; |
|
| 949 | + $sql .= "[$rKey] => '$rValue' "; |
|
| 950 | 950 | else |
| 951 | 951 | $sql .= " $t1 "; |
| 952 | 952 | } |
| 953 | - $sql .= "*/\n"; |
|
| 954 | - $sql .= $this->modifyIndexes($tablename,array($value), $execute) . "\n"; |
|
| 953 | + $sql .= "*/\n"; |
|
| 954 | + $sql .= $this->modifyIndexes($tablename, array($value), $execute)."\n"; |
|
| 955 | 955 | $take_action = true; |
| 956 | 956 | $correctedIndexs[$name] = true; |
| 957 | 957 | } |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | */ |
| 971 | 971 | public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
| 972 | 972 | { |
| 973 | - foreach ( $fielddef1 as $key => $value ) { |
|
| 973 | + foreach ($fielddef1 as $key => $value) { |
|
| 974 | 974 | if ($key == 'name' && $ignoreName) |
| 975 | 975 | continue; |
| 976 | 976 | if (isset($fielddef2[$key])) |
@@ -984,7 +984,7 @@ discard block |
||
| 984 | 984 | } |
| 985 | 985 | else |
| 986 | 986 | { |
| 987 | - if (array_map('strtolower', $fielddef1[$key]) == array_map('strtolower',$fielddef2[$key])) |
|
| 987 | + if (array_map('strtolower', $fielddef1[$key]) == array_map('strtolower', $fielddef2[$key])) |
|
| 988 | 988 | { |
| 989 | 989 | continue; |
| 990 | 990 | } |
@@ -1033,9 +1033,9 @@ discard block |
||
| 1033 | 1033 | } |
| 1034 | 1034 | else { |
| 1035 | 1035 | $returnArray['msg'] = 'match'; |
| 1036 | - foreach($row1 as $key => $value){ |
|
| 1036 | + foreach ($row1 as $key => $value) { |
|
| 1037 | 1037 | //ignore keys when checking we will check them when we do the index check |
| 1038 | - if( !isset($ignore_filter[$key]) && (!isset($row2[$key]) || $row1[$key] !== $row2[$key])){ |
|
| 1038 | + if (!isset($ignore_filter[$key]) && (!isset($row2[$key]) || $row1[$key] !== $row2[$key])) { |
|
| 1039 | 1039 | $returnArray['msg'] = 'no_match'; |
| 1040 | 1040 | } |
| 1041 | 1041 | } |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | $sql = $this->createIndexSQL($bean, $fieldDefs, $name, $unique); |
| 1112 | 1112 | $tablename = $bean->getTableName(); |
| 1113 | 1113 | $msg = "Error creating index $name on table: $tablename:"; |
| 1114 | - return $this->query($sql,true,$msg); |
|
| 1114 | + return $this->query($sql, true, $msg); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | /** |
@@ -1128,14 +1128,14 @@ discard block |
||
| 1128 | 1128 | $columns = array(); |
| 1129 | 1129 | |
| 1130 | 1130 | foreach ($indices as $index) { |
| 1131 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 1131 | + if (!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 1132 | 1132 | continue; |
| 1133 | 1133 | if (isset($index['source']) && $index['source'] != 'db') |
| 1134 | 1134 | continue; |
| 1135 | 1135 | |
| 1136 | 1136 | $sql = $this->add_drop_constraint($table, $index); |
| 1137 | 1137 | |
| 1138 | - if(!empty($sql)) { |
|
| 1138 | + if (!empty($sql)) { |
|
| 1139 | 1139 | $columns[] = $sql; |
| 1140 | 1140 | } |
| 1141 | 1141 | } |
@@ -1155,11 +1155,11 @@ discard block |
||
| 1155 | 1155 | { |
| 1156 | 1156 | $alters = $this->getConstraintSql($indexes, $tablename); |
| 1157 | 1157 | if ($execute) { |
| 1158 | - foreach($alters as $sql) { |
|
| 1158 | + foreach ($alters as $sql) { |
|
| 1159 | 1159 | $this->query($sql, true, "Error adding index: "); |
| 1160 | 1160 | } |
| 1161 | 1161 | } |
| 1162 | - if(!empty($alters)) { |
|
| 1162 | + if (!empty($alters)) { |
|
| 1163 | 1163 | $sql = join(";\n", $alters).";\n"; |
| 1164 | 1164 | } else { |
| 1165 | 1165 | $sql = ''; |
@@ -1179,17 +1179,17 @@ discard block |
||
| 1179 | 1179 | { |
| 1180 | 1180 | $sqls = array(); |
| 1181 | 1181 | foreach ($indexes as $index) { |
| 1182 | - $name =$index['name']; |
|
| 1183 | - $sqls[$name] = $this->add_drop_constraint($tablename,$index,true); |
|
| 1182 | + $name = $index['name']; |
|
| 1183 | + $sqls[$name] = $this->add_drop_constraint($tablename, $index, true); |
|
| 1184 | 1184 | } |
| 1185 | 1185 | if (!empty($sqls) && $execute) { |
| 1186 | - foreach($sqls as $name => $sql) { |
|
| 1186 | + foreach ($sqls as $name => $sql) { |
|
| 1187 | 1187 | unset(self::$index_descriptions[$tablename][$name]); |
| 1188 | 1188 | $this->query($sql); |
| 1189 | 1189 | } |
| 1190 | 1190 | } |
| 1191 | - if(!empty($sqls)) { |
|
| 1192 | - return join(";\n",$sqls).";"; |
|
| 1191 | + if (!empty($sqls)) { |
|
| 1192 | + return join(";\n", $sqls).";"; |
|
| 1193 | 1193 | } else { |
| 1194 | 1194 | return ''; |
| 1195 | 1195 | } |
@@ -1219,7 +1219,7 @@ discard block |
||
| 1219 | 1219 | public function addColumn($tablename, $fieldDefs) |
| 1220 | 1220 | { |
| 1221 | 1221 | $sql = $this->addColumnSQL($tablename, $fieldDefs); |
| 1222 | - if ($this->isFieldArray($fieldDefs)){ |
|
| 1222 | + if ($this->isFieldArray($fieldDefs)) { |
|
| 1223 | 1223 | $columns = array(); |
| 1224 | 1224 | foreach ($fieldDefs as $fieldDef) |
| 1225 | 1225 | $columns[] = $fieldDef['name']; |
@@ -1229,7 +1229,7 @@ discard block |
||
| 1229 | 1229 | $columns = $fieldDefs['name']; |
| 1230 | 1230 | } |
| 1231 | 1231 | $msg = "Error adding column(s) $columns on table: $tablename:"; |
| 1232 | - return $this->query($sql,true,$msg); |
|
| 1232 | + return $this->query($sql, true, $msg); |
|
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | /** |
@@ -1242,8 +1242,8 @@ discard block |
||
| 1242 | 1242 | */ |
| 1243 | 1243 | public function alterColumn($tablename, $newFieldDef, $ignoreRequired = false) |
| 1244 | 1244 | { |
| 1245 | - $sql = $this->alterColumnSQL($tablename, $newFieldDef,$ignoreRequired); |
|
| 1246 | - if ($this->isFieldArray($newFieldDef)){ |
|
| 1245 | + $sql = $this->alterColumnSQL($tablename, $newFieldDef, $ignoreRequired); |
|
| 1246 | + if ($this->isFieldArray($newFieldDef)) { |
|
| 1247 | 1247 | $columns = array(); |
| 1248 | 1248 | foreach ($newFieldDef as $fieldDef) { |
| 1249 | 1249 | $columns[] = $fieldDef['name']; |
@@ -1255,8 +1255,8 @@ discard block |
||
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | $msg = "Error altering column(s) $columns on table: $tablename:"; |
| 1258 | - $res = $this->query($sql,true,$msg); |
|
| 1259 | - if($res) { |
|
| 1258 | + $res = $this->query($sql, true, $msg); |
|
| 1259 | + if ($res) { |
|
| 1260 | 1260 | $this->getTableDescription($tablename, true); // reload table description after altering |
| 1261 | 1261 | } |
| 1262 | 1262 | return $res; |
@@ -1282,7 +1282,7 @@ discard block |
||
| 1282 | 1282 | public function dropTableName($name) |
| 1283 | 1283 | { |
| 1284 | 1284 | $sql = $this->dropTableNameSQL($name); |
| 1285 | - return $this->query($sql,true,"Error dropping table $name:"); |
|
| 1285 | + return $this->query($sql, true, "Error dropping table $name:"); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | $tablename = $bean->getTableName(); |
| 1298 | 1298 | $sql = $this->dropColumnSQL($tablename, $fieldDefs); |
| 1299 | 1299 | $msg = "Error deleting column(s) on table: $tablename:"; |
| 1300 | - return $this->query($sql,true,$msg); |
|
| 1300 | + return $this->query($sql, true, $msg); |
|
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | 1303 | /** |
@@ -1320,18 +1320,18 @@ discard block |
||
| 1320 | 1320 | |
| 1321 | 1321 | $rows_found = 0; |
| 1322 | 1322 | $count_query = $bean->create_list_count_query($select_query); |
| 1323 | - if(!empty($count_query)) |
|
| 1323 | + if (!empty($count_query)) |
|
| 1324 | 1324 | { |
| 1325 | 1325 | // We have a count query. Run it and get the results. |
| 1326 | 1326 | $result = $this->query($count_query, true, "Error running count query for $this->object_name List: "); |
| 1327 | 1327 | $assoc = $this->fetchByAssoc($result); |
| 1328 | - if(!empty($assoc['c'])) |
|
| 1328 | + if (!empty($assoc['c'])) |
|
| 1329 | 1329 | { |
| 1330 | 1330 | $rows_found = $assoc['c']; |
| 1331 | 1331 | } |
| 1332 | 1332 | } |
| 1333 | - if($count == -1){ |
|
| 1334 | - $count = $sugar_config['list_max_entries_per_page']; |
|
| 1333 | + if ($count == -1) { |
|
| 1334 | + $count = $sugar_config['list_max_entries_per_page']; |
|
| 1335 | 1335 | } |
| 1336 | 1336 | $next_offset = $start + $count; |
| 1337 | 1337 | |
@@ -1344,13 +1344,13 @@ discard block |
||
| 1344 | 1344 | $fields = $bean->getFieldDefinitions(); |
| 1345 | 1345 | $custom_fields = array(); |
| 1346 | 1346 | |
| 1347 | - if($bean->hasCustomFields()){ |
|
| 1348 | - foreach ($fields as $fieldDef){ |
|
| 1349 | - if($fieldDef['source'] == 'custom_fields'){ |
|
| 1347 | + if ($bean->hasCustomFields()) { |
|
| 1348 | + foreach ($fields as $fieldDef) { |
|
| 1349 | + if ($fieldDef['source'] == 'custom_fields') { |
|
| 1350 | 1350 | $custom_fields[$fieldDef['name']] = $fieldDef['name']; |
| 1351 | 1351 | } |
| 1352 | 1352 | } |
| 1353 | - if(!empty($custom_fields)){ |
|
| 1353 | + if (!empty($custom_fields)) { |
|
| 1354 | 1354 | $custom_fields['id_c'] = 'id_c'; |
| 1355 | 1355 | $id_field = array('name' => 'id_c', 'custom_type' => 'id',); |
| 1356 | 1356 | $fields[] = $id_field; |
@@ -1363,50 +1363,50 @@ discard block |
||
| 1363 | 1363 | $cstm_row_array = array(); |
| 1364 | 1364 | $cstm_columns = array(); |
| 1365 | 1365 | $built_columns = false; |
| 1366 | - while(($row = $this->fetchByAssoc($result)) != null) |
|
| 1366 | + while (($row = $this->fetchByAssoc($result)) != null) |
|
| 1367 | 1367 | { |
| 1368 | 1368 | $values = array(); |
| 1369 | 1369 | $cstm_values = array(); |
| 1370 | - if(!$is_related_query){ |
|
| 1370 | + if (!$is_related_query) { |
|
| 1371 | 1371 | foreach ($fields as $fieldDef) |
| 1372 | 1372 | { |
| 1373 | - if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue; |
|
| 1373 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue; |
|
| 1374 | 1374 | $val = $row[$fieldDef['name']]; |
| 1375 | 1375 | |
| 1376 | 1376 | //handle auto increment values here only need to do this on insert not create |
| 1377 | - if ($fieldDef['name'] == 'deleted'){ |
|
| 1377 | + if ($fieldDef['name'] == 'deleted') { |
|
| 1378 | 1378 | $values['deleted'] = $val; |
| 1379 | - if(!$built_columns){ |
|
| 1379 | + if (!$built_columns) { |
|
| 1380 | 1380 | $columns[] = 'deleted'; |
| 1381 | 1381 | } |
| 1382 | 1382 | } |
| 1383 | 1383 | else |
| 1384 | 1384 | { |
| 1385 | 1385 | $type = $fieldDef['type']; |
| 1386 | - if(!empty($fieldDef['custom_type'])){ |
|
| 1386 | + if (!empty($fieldDef['custom_type'])) { |
|
| 1387 | 1387 | $type = $fieldDef['custom_type']; |
| 1388 | 1388 | } |
| 1389 | 1389 | // need to do some thing about types of values |
| 1390 | - if($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')){ |
|
| 1391 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1390 | + if ($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')) { |
|
| 1391 | + if (!empty($custom_fields[$fieldDef['name']])) |
|
| 1392 | 1392 | $cstm_values[$fieldDef['name']] = 'null'; |
| 1393 | 1393 | else |
| 1394 | 1394 | $values[$fieldDef['name']] = 'null'; |
| 1395 | - }else{ |
|
| 1396 | - if(isset($type) && $type=='int') { |
|
| 1397 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1395 | + } else { |
|
| 1396 | + if (isset($type) && $type == 'int') { |
|
| 1397 | + if (!empty($custom_fields[$fieldDef['name']])) |
|
| 1398 | 1398 | $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
| 1399 | 1399 | else |
| 1400 | 1400 | $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
| 1401 | 1401 | } else { |
| 1402 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1402 | + if (!empty($custom_fields[$fieldDef['name']])) |
|
| 1403 | 1403 | $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
| 1404 | 1404 | else |
| 1405 | 1405 | $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
| 1406 | 1406 | } |
| 1407 | 1407 | } |
| 1408 | - if(!$built_columns){ |
|
| 1409 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1408 | + if (!$built_columns) { |
|
| 1409 | + if (!empty($custom_fields[$fieldDef['name']])) |
|
| 1410 | 1410 | $cstm_columns[] = $fieldDef['name']; |
| 1411 | 1411 | else |
| 1412 | 1412 | $columns[] = $fieldDef['name']; |
@@ -1417,19 +1417,19 @@ discard block |
||
| 1417 | 1417 | } else { |
| 1418 | 1418 | foreach ($row as $key=>$val) |
| 1419 | 1419 | { |
| 1420 | - if($key != 'orc_row'){ |
|
| 1420 | + if ($key != 'orc_row') { |
|
| 1421 | 1421 | $values[$key] = "'$val'"; |
| 1422 | - if(!$built_columns){ |
|
| 1422 | + if (!$built_columns) { |
|
| 1423 | 1423 | $columns[] = $key; |
| 1424 | 1424 | } |
| 1425 | 1425 | } |
| 1426 | 1426 | } |
| 1427 | 1427 | } |
| 1428 | 1428 | $built_columns = true; |
| 1429 | - if(!empty($values)){ |
|
| 1429 | + if (!empty($values)) { |
|
| 1430 | 1430 | $row_array[] = $values; |
| 1431 | 1431 | } |
| 1432 | - if(!empty($cstm_values) && !empty($cstm_values['id_c']) && (strlen($cstm_values['id_c']) > 7)){ |
|
| 1432 | + if (!empty($cstm_values) && !empty($cstm_values['id_c']) && (strlen($cstm_values['id_c']) > 7)) { |
|
| 1433 | 1433 | $cstm_row_array[] = $cstm_values; |
| 1434 | 1434 | } |
| 1435 | 1435 | } |
@@ -1439,9 +1439,9 @@ discard block |
||
| 1439 | 1439 | // get the entire sql |
| 1440 | 1440 | $sql .= "(".implode(",", $columns).") "; |
| 1441 | 1441 | $sql .= "VALUES"; |
| 1442 | - for($i = 0; $i < count($row_array); $i++){ |
|
| 1442 | + for ($i = 0; $i < count($row_array); $i++) { |
|
| 1443 | 1443 | $sql .= " (".implode(",", $row_array[$i]).")"; |
| 1444 | - if($i < (count($row_array) - 1)){ |
|
| 1444 | + if ($i < (count($row_array) - 1)) { |
|
| 1445 | 1445 | $sql .= ", "; |
| 1446 | 1446 | } |
| 1447 | 1447 | } |
@@ -1450,9 +1450,9 @@ discard block |
||
| 1450 | 1450 | $custom_sql .= "(".implode(",", $cstm_columns).") "; |
| 1451 | 1451 | $custom_sql .= "VALUES"; |
| 1452 | 1452 | |
| 1453 | - for($i = 0; $i < count($cstm_row_array); $i++){ |
|
| 1453 | + for ($i = 0; $i < count($cstm_row_array); $i++) { |
|
| 1454 | 1454 | $custom_sql .= " (".implode(",", $cstm_row_array[$i]).")"; |
| 1455 | - if($i < (count($cstm_row_array) - 1)){ |
|
| 1455 | + if ($i < (count($cstm_row_array) - 1)) { |
|
| 1456 | 1456 | $custom_sql .= ", "; |
| 1457 | 1457 | } |
| 1458 | 1458 | } |
@@ -1545,17 +1545,17 @@ discard block |
||
| 1545 | 1545 | */ |
| 1546 | 1546 | public function quoteType($type, $value) |
| 1547 | 1547 | { |
| 1548 | - if($type == 'date') { |
|
| 1548 | + if ($type == 'date') { |
|
| 1549 | 1549 | return $this->convert($this->quoted($value), "date"); |
| 1550 | 1550 | } |
| 1551 | - if($type == 'time') { |
|
| 1551 | + if ($type == 'time') { |
|
| 1552 | 1552 | return $this->convert($this->quoted($value), "time"); |
| 1553 | 1553 | } |
| 1554 | - if(isset($this->type_class[$type]) && $this->type_class[$type] == "date") { |
|
| 1554 | + if (isset($this->type_class[$type]) && $this->type_class[$type] == "date") { |
|
| 1555 | 1555 | return $this->convert($this->quoted($value), "datetime"); |
| 1556 | 1556 | } |
| 1557 | - if($this->isNumericType($type)) { |
|
| 1558 | - return 0+$value; // ensure it's numeric |
|
| 1557 | + if ($this->isNumericType($type)) { |
|
| 1558 | + return 0 + $value; // ensure it's numeric |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | return $this->quoted($value); |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | */ |
| 1572 | 1572 | public function arrayQuote(array &$array) |
| 1573 | 1573 | { |
| 1574 | - foreach($array as &$val) { |
|
| 1574 | + foreach ($array as &$val) { |
|
| 1575 | 1575 | $val = $this->quote($val); |
| 1576 | 1576 | } |
| 1577 | 1577 | return $array; |
@@ -1584,10 +1584,10 @@ discard block |
||
| 1584 | 1584 | */ |
| 1585 | 1585 | protected function freeResult($result = false) |
| 1586 | 1586 | { |
| 1587 | - if($result) { |
|
| 1587 | + if ($result) { |
|
| 1588 | 1588 | $this->freeDbResult($result); |
| 1589 | 1589 | } |
| 1590 | - if($this->lastResult) { |
|
| 1590 | + if ($this->lastResult) { |
|
| 1591 | 1591 | $this->freeDbResult($this->lastResult); |
| 1592 | 1592 | $this->lastResult = null; |
| 1593 | 1593 | } |
@@ -1616,17 +1616,17 @@ discard block |
||
| 1616 | 1616 | public function getOne($sql, $dieOnError = false, $msg = '') |
| 1617 | 1617 | { |
| 1618 | 1618 | $this->log->info("Get One: |$sql|"); |
| 1619 | - if(!$this->hasLimit($sql)) { |
|
| 1619 | + if (!$this->hasLimit($sql)) { |
|
| 1620 | 1620 | $queryresult = $this->limitQuery($sql, 0, 1, $dieOnError, $msg); |
| 1621 | 1621 | } else { |
| 1622 | 1622 | // support old code that passes LIMIT to sql |
| 1623 | 1623 | // works only for mysql, so do not rely on this |
| 1624 | 1624 | $queryresult = $this->query($sql, $dieOnError, $msg); |
| 1625 | 1625 | } |
| 1626 | - $this->checkError($msg.' Get One Failed:' . $sql, $dieOnError); |
|
| 1626 | + $this->checkError($msg.' Get One Failed:'.$sql, $dieOnError); |
|
| 1627 | 1627 | if (!$queryresult) return false; |
| 1628 | 1628 | $row = $this->fetchByAssoc($queryresult); |
| 1629 | - if(!empty($row)) { |
|
| 1629 | + if (!empty($row)) { |
|
| 1630 | 1630 | return array_shift($row); |
| 1631 | 1631 | } |
| 1632 | 1632 | return false; |
@@ -1646,12 +1646,12 @@ discard block |
||
| 1646 | 1646 | $this->log->info("Fetch One: |$sql|"); |
| 1647 | 1647 | $this->checkConnection(); |
| 1648 | 1648 | $queryresult = $this->query($sql, $dieOnError, $msg); |
| 1649 | - $this->checkError($msg.' Fetch One Failed:' . $sql, $dieOnError); |
|
| 1649 | + $this->checkError($msg.' Fetch One Failed:'.$sql, $dieOnError); |
|
| 1650 | 1650 | |
| 1651 | 1651 | if (!$queryresult) return false; |
| 1652 | 1652 | |
| 1653 | 1653 | $row = $this->fetchByAssoc($queryresult); |
| 1654 | - if ( !$row ) return false; |
|
| 1654 | + if (!$row) return false; |
|
| 1655 | 1655 | |
| 1656 | 1656 | $this->freeResult($queryresult); |
| 1657 | 1657 | return $row; |
@@ -1692,7 +1692,7 @@ discard block |
||
| 1692 | 1692 | */ |
| 1693 | 1693 | public function getTableDescription($tablename, $reload = false) |
| 1694 | 1694 | { |
| 1695 | - if($reload || empty(self::$table_descriptions[$tablename])) { |
|
| 1695 | + if ($reload || empty(self::$table_descriptions[$tablename])) { |
|
| 1696 | 1696 | self::$table_descriptions[$tablename] = $this->get_columns($tablename); |
| 1697 | 1697 | } |
| 1698 | 1698 | return self::$table_descriptions[$tablename]; |
@@ -1708,12 +1708,12 @@ discard block |
||
| 1708 | 1708 | protected function describeField($name, $tablename) |
| 1709 | 1709 | { |
| 1710 | 1710 | $table = $this->getTableDescription($tablename); |
| 1711 | - if(!empty($table) && isset($table[$name])) |
|
| 1711 | + if (!empty($table) && isset($table[$name])) |
|
| 1712 | 1712 | return $table[$name]; |
| 1713 | 1713 | |
| 1714 | 1714 | $table = $this->getTableDescription($tablename, true); |
| 1715 | 1715 | |
| 1716 | - if(isset($table[$name])) |
|
| 1716 | + if (isset($table[$name])) |
|
| 1717 | 1717 | return $table[$name]; |
| 1718 | 1718 | |
| 1719 | 1719 | return array(); |
@@ -1728,13 +1728,13 @@ discard block |
||
| 1728 | 1728 | */ |
| 1729 | 1729 | protected function describeIndex($name, $tablename) |
| 1730 | 1730 | { |
| 1731 | - if(isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename][$name])){ |
|
| 1731 | + if (isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename]) && isset(self::$index_descriptions[$tablename][$name])) { |
|
| 1732 | 1732 | return self::$index_descriptions[$tablename][$name]; |
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | 1735 | self::$index_descriptions[$tablename] = $this->get_indices($tablename); |
| 1736 | 1736 | |
| 1737 | - if(isset(self::$index_descriptions[$tablename][$name])){ |
|
| 1737 | + if (isset(self::$index_descriptions[$tablename][$name])) { |
|
| 1738 | 1738 | return self::$index_descriptions[$tablename][$name]; |
| 1739 | 1739 | } |
| 1740 | 1740 | |
@@ -1751,9 +1751,9 @@ discard block |
||
| 1751 | 1751 | */ |
| 1752 | 1752 | public function truncate($string, $len) |
| 1753 | 1753 | { |
| 1754 | - if ( is_numeric($len) && $len > 0) |
|
| 1754 | + if (is_numeric($len) && $len > 0) |
|
| 1755 | 1755 | { |
| 1756 | - $string = mb_substr($string,0,(int) $len, "UTF-8"); |
|
| 1756 | + $string = mb_substr($string, 0, (int)$len, "UTF-8"); |
|
| 1757 | 1757 | } |
| 1758 | 1758 | return $string; |
| 1759 | 1759 | } |
@@ -1768,11 +1768,11 @@ discard block |
||
| 1768 | 1768 | */ |
| 1769 | 1769 | public function concat($table, array $fields, $space = ' ') |
| 1770 | 1770 | { |
| 1771 | - if(empty($fields)) return ''; |
|
| 1771 | + if (empty($fields)) return ''; |
|
| 1772 | 1772 | $elems = array(); |
| 1773 | 1773 | $space = $this->quoted($space); |
| 1774 | - foreach ( $fields as $field ) { |
|
| 1775 | - if(!empty($elems)) $elems[] = $space; |
|
| 1774 | + foreach ($fields as $field) { |
|
| 1775 | + if (!empty($elems)) $elems[] = $space; |
|
| 1776 | 1776 | $elems[] = $this->convert("$table.$field", 'IFNULL', array("''")); |
| 1777 | 1777 | } |
| 1778 | 1778 | $first = array_shift($elems); |
@@ -1829,8 +1829,8 @@ discard block |
||
| 1829 | 1829 | */ |
| 1830 | 1830 | public function executePreparedQuery($stmt, $data = array()) |
| 1831 | 1831 | { |
| 1832 | - if(!empty($this->preparedTokens[$stmt])){ |
|
| 1833 | - if(!is_array($data)){ |
|
| 1832 | + if (!empty($this->preparedTokens[$stmt])) { |
|
| 1833 | + if (!is_array($data)) { |
|
| 1834 | 1834 | $data = array($data); |
| 1835 | 1835 | } |
| 1836 | 1836 | |
@@ -1838,7 +1838,7 @@ discard block |
||
| 1838 | 1838 | |
| 1839 | 1839 | //ensure that the number of data elements matches the number of replacement tokens |
| 1840 | 1840 | //we found in prepare(). |
| 1841 | - if(count($data) != $pTokens['tokenCount']){ |
|
| 1841 | + if (count($data) != $pTokens['tokenCount']) { |
|
| 1842 | 1842 | //error the data count did not match the token count |
| 1843 | 1843 | return false; |
| 1844 | 1844 | } |
@@ -1864,7 +1864,7 @@ discard block |
||
| 1864 | 1864 | }//switch |
| 1865 | 1865 | }//foreach |
| 1866 | 1866 | return $this->query($query); |
| 1867 | - }else{ |
|
| 1867 | + } else { |
|
| 1868 | 1868 | return false; |
| 1869 | 1869 | } |
| 1870 | 1870 | } |
@@ -1908,7 +1908,7 @@ discard block |
||
| 1908 | 1908 | { |
| 1909 | 1909 | // get column names and values |
| 1910 | 1910 | $sql = $this->insertParams($bean->getTableName(), $bean->getFieldDefinitions(), get_object_vars($bean), |
| 1911 | - isset($bean->field_name_map)?$bean->field_name_map:null, false); |
|
| 1911 | + isset($bean->field_name_map) ? $bean->field_name_map : null, false); |
|
| 1912 | 1912 | return $sql; |
| 1913 | 1913 | } |
| 1914 | 1914 | |
@@ -1936,48 +1936,48 @@ discard block |
||
| 1936 | 1936 | if (!empty($bean->field_name_map[$field]['auto_increment'])) continue; |
| 1937 | 1937 | |
| 1938 | 1938 | //custom fields handle their save separately |
| 1939 | - if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) continue; |
|
| 1939 | + if (isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) continue; |
|
| 1940 | 1940 | |
| 1941 | 1941 | // no need to clear deleted since we only update not deleted records anyway |
| 1942 | - if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue; |
|
| 1942 | + if ($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue; |
|
| 1943 | 1943 | |
| 1944 | - if(isset($bean->$field)) { |
|
| 1944 | + if (isset($bean->$field)) { |
|
| 1945 | 1945 | $val = from_html($bean->$field); |
| 1946 | 1946 | } else { |
| 1947 | 1947 | continue; |
| 1948 | 1948 | } |
| 1949 | 1949 | |
| 1950 | - if(!empty($fieldDef['type']) && $fieldDef['type'] == 'bool'){ |
|
| 1950 | + if (!empty($fieldDef['type']) && $fieldDef['type'] == 'bool') { |
|
| 1951 | 1951 | $val = $bean->getFieldValue($field); |
| 1952 | 1952 | } |
| 1953 | 1953 | |
| 1954 | - if(strlen($val) == 0) { |
|
| 1955 | - if(isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 1954 | + if (strlen($val) == 0) { |
|
| 1955 | + if (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) { |
|
| 1956 | 1956 | $val = $fieldDef['default']; |
| 1957 | 1957 | } else { |
| 1958 | 1958 | $val = null; |
| 1959 | 1959 | } |
| 1960 | 1960 | } |
| 1961 | 1961 | |
| 1962 | - if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 1962 | + if (!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 1963 | 1963 | $val = $this->truncate($val, $fieldDef['len']); |
| 1964 | 1964 | } |
| 1965 | 1965 | $columnName = $this->quoteIdentifier($fieldDef['name']); |
| 1966 | - if(!is_null($val) || !empty($fieldDef['required'])) { |
|
| 1966 | + if (!is_null($val) || !empty($fieldDef['required'])) { |
|
| 1967 | 1967 | $columns[] = "{$columnName}=".$this->massageValue($val, $fieldDef); |
| 1968 | - } elseif($this->isNullable($fieldDef)) { |
|
| 1968 | + } elseif ($this->isNullable($fieldDef)) { |
|
| 1969 | 1969 | $columns[] = "{$columnName}=NULL"; |
| 1970 | 1970 | } else { |
| 1971 | 1971 | $columns[] = "{$columnName}=".$this->emptyValue($fieldDef['type']); |
| 1972 | 1972 | } |
| 1973 | 1973 | } |
| 1974 | 1974 | |
| 1975 | - if ( sizeof($columns) == 0 ) |
|
| 1975 | + if (sizeof($columns) == 0) |
|
| 1976 | 1976 | return ""; // no columns set |
| 1977 | 1977 | |
| 1978 | 1978 | // build where clause |
| 1979 | 1979 | $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
| 1980 | - if(isset($fields['deleted'])) { |
|
| 1980 | + if (isset($fields['deleted'])) { |
|
| 1981 | 1981 | $where .= " AND deleted=0"; |
| 1982 | 1982 | } |
| 1983 | 1983 | |
@@ -2001,7 +2001,7 @@ discard block |
||
| 2001 | 2001 | $primaryColumn = $fieldDef['name']; |
| 2002 | 2002 | |
| 2003 | 2003 | $val = $bean->getFieldValue($fieldDef['name']); |
| 2004 | - if ($val != FALSE){ |
|
| 2004 | + if ($val != FALSE) { |
|
| 2005 | 2005 | $where[$primaryColumn] = $val; |
| 2006 | 2006 | } |
| 2007 | 2007 | } |
@@ -2027,7 +2027,7 @@ discard block |
||
| 2027 | 2027 | if (is_array($val)) { |
| 2028 | 2028 | $op = "IN"; |
| 2029 | 2029 | $temp = array(); |
| 2030 | - foreach ($val as $tval){ |
|
| 2030 | + foreach ($val as $tval) { |
|
| 2031 | 2031 | $temp[] = $this->quoted($tval); |
| 2032 | 2032 | } |
| 2033 | 2033 | $val = implode(",", $temp); |
@@ -2053,9 +2053,9 @@ discard block |
||
| 2053 | 2053 | * @param array $whereArray Optional, where conditions in an array |
| 2054 | 2054 | * @return string |
| 2055 | 2055 | */ |
| 2056 | - protected function getWhereClause(SugarBean $bean, array $whereArray=array()) |
|
| 2056 | + protected function getWhereClause(SugarBean $bean, array $whereArray = array()) |
|
| 2057 | 2057 | { |
| 2058 | - return " WHERE " . $this->getColumnWhereClause($bean->getTableName(), $whereArray); |
|
| 2058 | + return " WHERE ".$this->getColumnWhereClause($bean->getTableName(), $whereArray); |
|
| 2059 | 2059 | } |
| 2060 | 2060 | |
| 2061 | 2061 | /** |
@@ -2069,13 +2069,13 @@ discard block |
||
| 2069 | 2069 | { |
| 2070 | 2070 | $type = $this->getFieldType($fieldDef); |
| 2071 | 2071 | |
| 2072 | - if(isset($this->type_class[$type])) { |
|
| 2072 | + if (isset($this->type_class[$type])) { |
|
| 2073 | 2073 | // handle some known types |
| 2074 | - switch($this->type_class[$type]) { |
|
| 2074 | + switch ($this->type_class[$type]) { |
|
| 2075 | 2075 | case 'bool': |
| 2076 | 2076 | case 'int': |
| 2077 | - if (!empty($fieldDef['required']) && $val == ''){ |
|
| 2078 | - if (isset($fieldDef['default'])){ |
|
| 2077 | + if (!empty($fieldDef['required']) && $val == '') { |
|
| 2078 | + if (isset($fieldDef['default'])) { |
|
| 2079 | 2079 | return $fieldDef['default']; |
| 2080 | 2080 | } |
| 2081 | 2081 | return 0; |
@@ -2083,16 +2083,16 @@ discard block |
||
| 2083 | 2083 | return intval($val); |
| 2084 | 2084 | case 'bigint' : |
| 2085 | 2085 | $val = (float)$val; |
| 2086 | - if (!empty($fieldDef['required']) && $val == false){ |
|
| 2087 | - if (isset($fieldDef['default'])){ |
|
| 2086 | + if (!empty($fieldDef['required']) && $val == false) { |
|
| 2087 | + if (isset($fieldDef['default'])) { |
|
| 2088 | 2088 | return $fieldDef['default']; |
| 2089 | 2089 | } |
| 2090 | 2090 | return 0; |
| 2091 | 2091 | } |
| 2092 | 2092 | return $val; |
| 2093 | 2093 | case 'float': |
| 2094 | - if (!empty($fieldDef['required']) && $val == ''){ |
|
| 2095 | - if (isset($fieldDef['default'])){ |
|
| 2094 | + if (!empty($fieldDef['required']) && $val == '') { |
|
| 2095 | + if (isset($fieldDef['default'])) { |
|
| 2096 | 2096 | return $fieldDef['default']; |
| 2097 | 2097 | } |
| 2098 | 2098 | return 0; |
@@ -2101,7 +2101,7 @@ discard block |
||
| 2101 | 2101 | case 'time': |
| 2102 | 2102 | case 'date': |
| 2103 | 2103 | // empty date can't be '', so convert it to either NULL or empty date value |
| 2104 | - if($val == '') { |
|
| 2104 | + if ($val == '') { |
|
| 2105 | 2105 | if (!empty($fieldDef['required'])) { |
| 2106 | 2106 | if (isset($fieldDef['default'])) { |
| 2107 | 2107 | return $fieldDef['default']; |
@@ -2113,14 +2113,14 @@ discard block |
||
| 2113 | 2113 | break; |
| 2114 | 2114 | } |
| 2115 | 2115 | } else { |
| 2116 | - if(!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 2116 | + if (!empty($val) && !empty($fieldDef['len']) && strlen($val) > $fieldDef['len']) { |
|
| 2117 | 2117 | $val = $this->truncate($val, $fieldDef['len']); |
| 2118 | 2118 | } |
| 2119 | 2119 | } |
| 2120 | 2120 | |
| 2121 | - if ( is_null($val) ) { |
|
| 2122 | - if(!empty($fieldDef['required'])) { |
|
| 2123 | - if (isset($fieldDef['default'])){ |
|
| 2121 | + if (is_null($val)) { |
|
| 2122 | + if (!empty($fieldDef['required'])) { |
|
| 2123 | + if (isset($fieldDef['default'])) { |
|
| 2124 | 2124 | return $fieldDef['default']; |
| 2125 | 2125 | } |
| 2126 | 2126 | return $this->emptyValue($type); |
@@ -2128,7 +2128,7 @@ discard block |
||
| 2128 | 2128 | return "NULL"; |
| 2129 | 2129 | } |
| 2130 | 2130 | } |
| 2131 | - if($type == "datetimecombo") { |
|
| 2131 | + if ($type == "datetimecombo") { |
|
| 2132 | 2132 | $type = "datetime"; |
| 2133 | 2133 | } |
| 2134 | 2134 | return $this->convert($this->quoted($val), $type); |
@@ -2143,23 +2143,23 @@ discard block |
||
| 2143 | 2143 | */ |
| 2144 | 2144 | public function massageFieldDef(&$fieldDef, $tablename) |
| 2145 | 2145 | { |
| 2146 | - if ( !isset($fieldDef['dbType']) ) { |
|
| 2147 | - if ( isset($fieldDef['dbtype']) ) |
|
| 2146 | + if (!isset($fieldDef['dbType'])) { |
|
| 2147 | + if (isset($fieldDef['dbtype'])) |
|
| 2148 | 2148 | $fieldDef['dbType'] = $fieldDef['dbtype']; |
| 2149 | 2149 | else |
| 2150 | 2150 | $fieldDef['dbType'] = $fieldDef['type']; |
| 2151 | 2151 | } |
| 2152 | - $type = $this->getColumnType($fieldDef['dbType'],$fieldDef['name'],$tablename); |
|
| 2152 | + $type = $this->getColumnType($fieldDef['dbType'], $fieldDef['name'], $tablename); |
|
| 2153 | 2153 | $matches = array(); |
| 2154 | 2154 | // len can be a number or a string like 'max', for example, nvarchar(max) |
| 2155 | 2155 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*|\w+)\)|)/i', $type, $matches); |
| 2156 | - if ( isset($matches[1][0]) ) |
|
| 2156 | + if (isset($matches[1][0])) |
|
| 2157 | 2157 | $fieldDef['type'] = $matches[1][0]; |
| 2158 | - if ( isset($matches[2][0]) && empty($fieldDef['len']) ) |
|
| 2158 | + if (isset($matches[2][0]) && empty($fieldDef['len'])) |
|
| 2159 | 2159 | $fieldDef['len'] = $matches[2][0]; |
| 2160 | - if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) |
|
| 2160 | + if (!empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'], ',')) |
|
| 2161 | 2161 | $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
| 2162 | - if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required'])) ) { |
|
| 2162 | + if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required']))) { |
|
| 2163 | 2163 | $fieldDef['required'] = 'true'; |
| 2164 | 2164 | } |
| 2165 | 2165 | } |
@@ -2180,7 +2180,7 @@ discard block |
||
| 2180 | 2180 | $level = 0; |
| 2181 | 2181 | $selectField = ""; |
| 2182 | 2182 | $strLen = strlen($selectStatement); |
| 2183 | - for($i = 0; $i < $strLen; $i++) |
|
| 2183 | + for ($i = 0; $i < $strLen; $i++) |
|
| 2184 | 2184 | { |
| 2185 | 2185 | $char = $selectStatement[$i]; |
| 2186 | 2186 | |
@@ -2190,16 +2190,16 @@ discard block |
||
| 2190 | 2190 | $fields[$field] = $selectField; |
| 2191 | 2191 | $selectField = ""; |
| 2192 | 2192 | } |
| 2193 | - else if ($char == "("){ |
|
| 2193 | + else if ($char == "(") { |
|
| 2194 | 2194 | $level++; |
| 2195 | 2195 | $selectField .= $char; |
| 2196 | 2196 | } |
| 2197 | - else if($char == ")"){ |
|
| 2197 | + else if ($char == ")") { |
|
| 2198 | 2198 | $level--; |
| 2199 | 2199 | $selectField .= $char; |
| 2200 | 2200 | |
| 2201 | 2201 | |
| 2202 | - }else{ |
|
| 2202 | + } else { |
|
| 2203 | 2203 | $selectField .= $char; |
| 2204 | 2204 | } |
| 2205 | 2205 | |
@@ -2215,7 +2215,7 @@ discard block |
||
| 2215 | 2215 | */ |
| 2216 | 2216 | protected function getFieldNameFromSelect($string) |
| 2217 | 2217 | { |
| 2218 | - if(strncasecmp($string, "DISTINCT ", 9) == 0) { |
|
| 2218 | + if (strncasecmp($string, "DISTINCT ", 9) == 0) { |
|
| 2219 | 2219 | $string = substr($string, 9); |
| 2220 | 2220 | } |
| 2221 | 2221 | if (stripos($string, " as ") !== false) |
@@ -2293,14 +2293,14 @@ discard block |
||
| 2293 | 2293 | foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
| 2294 | 2294 | |
| 2295 | 2295 | // build part of where clause |
| 2296 | - if (is_array($whereClause[$beanID])){ |
|
| 2296 | + if (is_array($whereClause[$beanID])) { |
|
| 2297 | 2297 | $where[] = $this->getColumnWhereClause($table, $whereClause[$beanID]); |
| 2298 | 2298 | } |
| 2299 | 2299 | // initialize so that it can be used properly in form clause generation |
| 2300 | 2300 | $table_used_in_from[$table] = false; |
| 2301 | 2301 | |
| 2302 | 2302 | $indices = $bean->getIndices(); |
| 2303 | - foreach ($indices as $index){ |
|
| 2303 | + foreach ($indices as $index) { |
|
| 2304 | 2304 | if ($index['type'] == 'foreign') { |
| 2305 | 2305 | $relationship[$table][] = array('foreignTable'=> $index['foreignTable'] |
| 2306 | 2306 | ,'foreignColumn'=>$index['foreignField'] |
@@ -2321,12 +2321,12 @@ discard block |
||
| 2321 | 2321 | // table2 is assumed to joining through primary key called id |
| 2322 | 2322 | $separator = ""; |
| 2323 | 2323 | $from = ''; $table_used_in_from = array(); |
| 2324 | - foreach ($relations as $table1 => $rightsidearray){ |
|
| 2324 | + foreach ($relations as $table1 => $rightsidearray) { |
|
| 2325 | 2325 | if ($table_used_in_from[$table1]) continue; // table has been joined |
| 2326 | 2326 | |
| 2327 | 2327 | $from .= $separator." ".$table1; |
| 2328 | 2328 | $table_used_in_from[$table1] = true; |
| 2329 | - foreach ($rightsidearray as $tablearray){ |
|
| 2329 | + foreach ($rightsidearray as $tablearray) { |
|
| 2330 | 2330 | $table2 = $tablearray['foreignTable']; // get foreign table |
| 2331 | 2331 | $tableAlias = $aliases[$table2]; // get a list of aliases for this table |
| 2332 | 2332 | foreach ($tableAlias as $table2) { |
@@ -2386,9 +2386,9 @@ discard block |
||
| 2386 | 2386 | // we do not have change a lot of existing code |
| 2387 | 2387 | // and add dbtype where type is being used for some special |
| 2388 | 2388 | // purposes like referring to foreign table etc. |
| 2389 | - if(!empty($fieldDef['dbType'])) |
|
| 2389 | + if (!empty($fieldDef['dbType'])) |
|
| 2390 | 2390 | return $fieldDef['dbType']; |
| 2391 | - if(!empty($fieldDef['dbtype'])) |
|
| 2391 | + if (!empty($fieldDef['dbtype'])) |
|
| 2392 | 2392 | return $fieldDef['dbtype']; |
| 2393 | 2393 | if (!empty($fieldDef['type'])) |
| 2394 | 2394 | return $fieldDef['type']; |
@@ -2408,17 +2408,17 @@ discard block |
||
| 2408 | 2408 | */ |
| 2409 | 2409 | public function getTypeParts($type) |
| 2410 | 2410 | { |
| 2411 | - if(preg_match("#(?P<type>\w+)\s*(?P<arg>\((?P<len>\w+)\s*(,\s*(?P<scale>\d+))*\))*#", $type, $matches)) |
|
| 2411 | + if (preg_match("#(?P<type>\w+)\s*(?P<arg>\((?P<len>\w+)\s*(,\s*(?P<scale>\d+))*\))*#", $type, $matches)) |
|
| 2412 | 2412 | { |
| 2413 | - $return = array(); // Not returning matches array as such as we don't want to expose the regex make up on the interface |
|
| 2413 | + $return = array(); // Not returning matches array as such as we don't want to expose the regex make up on the interface |
|
| 2414 | 2414 | $return['baseType'] = $matches['type']; |
| 2415 | - if( isset($matches['arg'])) { |
|
| 2415 | + if (isset($matches['arg'])) { |
|
| 2416 | 2416 | $return['arg'] = $matches['arg']; |
| 2417 | 2417 | } |
| 2418 | - if( isset($matches['len'])) { |
|
| 2418 | + if (isset($matches['len'])) { |
|
| 2419 | 2419 | $return['len'] = $matches['len']; |
| 2420 | 2420 | } |
| 2421 | - if( isset($matches['scale'])) { |
|
| 2421 | + if (isset($matches['scale'])) { |
|
| 2422 | 2422 | $return['scale'] = $matches['scale']; |
| 2423 | 2423 | } |
| 2424 | 2424 | return $return; |
@@ -2442,28 +2442,28 @@ discard block |
||
| 2442 | 2442 | $type = $this->getFieldType($fieldDef); |
| 2443 | 2443 | $colType = $this->getColumnType($type); |
| 2444 | 2444 | |
| 2445 | - if($parts = $this->getTypeParts($colType)) |
|
| 2445 | + if ($parts = $this->getTypeParts($colType)) |
|
| 2446 | 2446 | { |
| 2447 | 2447 | $colBaseType = $parts['baseType']; |
| 2448 | - $defLen = isset($parts['len']) ? $parts['len'] : '255'; // Use the mappings length (precision) as default if it exists |
|
| 2448 | + $defLen = isset($parts['len']) ? $parts['len'] : '255'; // Use the mappings length (precision) as default if it exists |
|
| 2449 | 2449 | } |
| 2450 | 2450 | |
| 2451 | - if(!empty($fieldDef['len'])) { |
|
| 2452 | - if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char', |
|
| 2451 | + if (!empty($fieldDef['len'])) { |
|
| 2452 | + if (in_array($colBaseType, array('nvarchar', 'nchar', 'varchar', 'varchar2', 'char', |
|
| 2453 | 2453 | 'clob', 'blob', 'text'))) { |
| 2454 | 2454 | $colType = "$colBaseType(${fieldDef['len']})"; |
| 2455 | - } elseif(($colBaseType == 'decimal' || $colBaseType == 'float')){ |
|
| 2456 | - if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) |
|
| 2457 | - if(strpos($fieldDef['len'],',') === false){ |
|
| 2458 | - $colType = $colBaseType . "(".$fieldDef['len'].",".$fieldDef['precision'].")"; |
|
| 2459 | - }else{ |
|
| 2460 | - $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2455 | + } elseif (($colBaseType == 'decimal' || $colBaseType == 'float')) { |
|
| 2456 | + if (!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) |
|
| 2457 | + if (strpos($fieldDef['len'], ',') === false) { |
|
| 2458 | + $colType = $colBaseType."(".$fieldDef['len'].",".$fieldDef['precision'].")"; |
|
| 2459 | + } else { |
|
| 2460 | + $colType = $colBaseType."(".$fieldDef['len'].")"; |
|
| 2461 | 2461 | } |
| 2462 | 2462 | else |
| 2463 | - $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2463 | + $colType = $colBaseType."(".$fieldDef['len'].")"; |
|
| 2464 | 2464 | } |
| 2465 | 2465 | } else { |
| 2466 | - if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) { |
|
| 2466 | + if (in_array($colBaseType, array('nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) { |
|
| 2467 | 2467 | $colType = "$colBaseType($defLen)"; |
| 2468 | 2468 | } |
| 2469 | 2469 | } |
@@ -2485,29 +2485,29 @@ discard block |
||
| 2485 | 2485 | } |
| 2486 | 2486 | |
| 2487 | 2487 | $auto_increment = ''; |
| 2488 | - if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) |
|
| 2489 | - $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
| 2488 | + if (!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) |
|
| 2489 | + $auto_increment = $this->setAutoIncrement($table, $fieldDef['name']); |
|
| 2490 | 2490 | |
| 2491 | - $required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify |
|
| 2491 | + $required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify |
|
| 2492 | 2492 | //Starting in 6.0, only ID and auto_increment fields will be NOT NULL in the DB. |
| 2493 | 2493 | if ((empty($fieldDef['isnull']) || strtolower($fieldDef['isnull']) == 'false') && |
| 2494 | 2494 | (!empty($auto_increment) || $name == 'id' || ($fieldDef['type'] == 'id' && !empty($fieldDef['required'])))) { |
| 2495 | - $required = "NOT NULL"; |
|
| 2495 | + $required = "NOT NULL"; |
|
| 2496 | 2496 | } |
| 2497 | 2497 | // If the field is marked both required & isnull=>false - alwqys make it not null |
| 2498 | 2498 | // Use this to ensure primary key fields never defined as null |
| 2499 | - if(isset($fieldDef['isnull']) && (strtolower($fieldDef['isnull']) == 'false' || $fieldDef['isnull'] === false) |
|
| 2499 | + if (isset($fieldDef['isnull']) && (strtolower($fieldDef['isnull']) == 'false' || $fieldDef['isnull'] === false) |
|
| 2500 | 2500 | && !empty($fieldDef['required'])) { |
| 2501 | - $required = "NOT NULL"; |
|
| 2501 | + $required = "NOT NULL"; |
|
| 2502 | 2502 | } |
| 2503 | 2503 | if ($ignoreRequired) |
| 2504 | 2504 | $required = ""; |
| 2505 | 2505 | |
| 2506 | - if ( $return_as_array ) { |
|
| 2506 | + if ($return_as_array) { |
|
| 2507 | 2507 | return array( |
| 2508 | 2508 | 'name' => $name, |
| 2509 | 2509 | 'colType' => $colType, |
| 2510 | - 'colBaseType' => $colBaseType, // Adding base type for easier processing in derived classes |
|
| 2510 | + 'colBaseType' => $colBaseType, // Adding base type for easier processing in derived classes |
|
| 2511 | 2511 | 'default' => $default, |
| 2512 | 2512 | 'required' => $required, |
| 2513 | 2513 | 'auto_increment' => $auto_increment, |
@@ -2532,14 +2532,14 @@ discard block |
||
| 2532 | 2532 | |
| 2533 | 2533 | if ($this->isFieldArray($fieldDefs)) { |
| 2534 | 2534 | foreach ($fieldDefs as $fieldDef) { |
| 2535 | - if(!isset($fieldDef['source']) || $fieldDef['source'] == 'db') { |
|
| 2536 | - $columns[] = $this->oneColumnSQLRep($fieldDef,false, $tablename); |
|
| 2535 | + if (!isset($fieldDef['source']) || $fieldDef['source'] == 'db') { |
|
| 2536 | + $columns[] = $this->oneColumnSQLRep($fieldDef, false, $tablename); |
|
| 2537 | 2537 | } |
| 2538 | 2538 | } |
| 2539 | 2539 | $columns = implode(",", $columns); |
| 2540 | 2540 | } |
| 2541 | 2541 | else { |
| 2542 | - $columns = $this->oneColumnSQLRep($fieldDefs,$ignoreRequired, $tablename); |
|
| 2542 | + $columns = $this->oneColumnSQLRep($fieldDefs, $ignoreRequired, $tablename); |
|
| 2543 | 2543 | } |
| 2544 | 2544 | |
| 2545 | 2545 | return $columns; |
@@ -2701,40 +2701,40 @@ discard block |
||
| 2701 | 2701 | */ |
| 2702 | 2702 | public function getValidDBName($name, $ensureUnique = false, $type = 'column', $force = false) |
| 2703 | 2703 | { |
| 2704 | - if(is_array($name)) { |
|
| 2704 | + if (is_array($name)) { |
|
| 2705 | 2705 | $result = array(); |
| 2706 | - foreach($name as $field) { |
|
| 2706 | + foreach ($name as $field) { |
|
| 2707 | 2707 | $result[] = $this->getValidDBName($field, $ensureUnique, $type); |
| 2708 | 2708 | } |
| 2709 | 2709 | return $result; |
| 2710 | 2710 | } else { |
| 2711 | - if(strchr($name, ".")) { |
|
| 2711 | + if (strchr($name, ".")) { |
|
| 2712 | 2712 | // this is a compound name with dots, handle separately |
| 2713 | 2713 | $parts = explode(".", $name); |
| 2714 | - if(count($parts) > 2) { |
|
| 2714 | + if (count($parts) > 2) { |
|
| 2715 | 2715 | // some weird name, cut to table.name |
| 2716 | - array_splice($parts, 0, count($parts)-2); |
|
| 2716 | + array_splice($parts, 0, count($parts) - 2); |
|
| 2717 | 2717 | } |
| 2718 | 2718 | $parts = $this->getValidDBName($parts, $ensureUnique, $type, $force); |
| 2719 | 2719 | return join(".", $parts); |
| 2720 | 2720 | } |
| 2721 | 2721 | // first strip any invalid characters - all but word chars (which is alphanumeric and _) |
| 2722 | - $name = preg_replace( '/[^\w]+/i', '', $name ) ; |
|
| 2723 | - $len = strlen( $name ) ; |
|
| 2722 | + $name = preg_replace('/[^\w]+/i', '', $name); |
|
| 2723 | + $len = strlen($name); |
|
| 2724 | 2724 | $maxLen = empty($this->maxNameLengths[$type]) ? $this->maxNameLengths[$type]['column'] : $this->maxNameLengths[$type]; |
| 2725 | 2725 | if ($len <= $maxLen && !$force) { |
| 2726 | 2726 | return strtolower($name); |
| 2727 | 2727 | } |
| 2728 | 2728 | if ($ensureUnique) { |
| 2729 | 2729 | $md5str = md5($name); |
| 2730 | - $tail = substr ( $name, -11) ; |
|
| 2731 | - $temp = substr($md5str , strlen($md5str)-4 ); |
|
| 2732 | - $result = substr( $name, 0, 10) . $temp . $tail ; |
|
| 2730 | + $tail = substr($name, -11); |
|
| 2731 | + $temp = substr($md5str, strlen($md5str) - 4); |
|
| 2732 | + $result = substr($name, 0, 10).$temp.$tail; |
|
| 2733 | 2733 | } else { |
| 2734 | - $result = substr( $name, 0, 11) . substr( $name, 11 - $maxLen); |
|
| 2734 | + $result = substr($name, 0, 11).substr($name, 11 - $maxLen); |
|
| 2735 | 2735 | } |
| 2736 | 2736 | |
| 2737 | - return strtolower( $result ) ; |
|
| 2737 | + return strtolower($result); |
|
| 2738 | 2738 | } |
| 2739 | 2739 | } |
| 2740 | 2740 | |
@@ -2746,7 +2746,7 @@ discard block |
||
| 2746 | 2746 | */ |
| 2747 | 2747 | public function getColumnType($type) |
| 2748 | 2748 | { |
| 2749 | - return isset($this->type_map[$type])?$this->type_map[$type]:$type; |
|
| 2749 | + return isset($this->type_map[$type]) ? $this->type_map[$type] : $type; |
|
| 2750 | 2750 | } |
| 2751 | 2751 | |
| 2752 | 2752 | /** |
@@ -2760,10 +2760,10 @@ discard block |
||
| 2760 | 2760 | */ |
| 2761 | 2761 | public function isFieldArray($defArray) |
| 2762 | 2762 | { |
| 2763 | - if ( !is_array($defArray) ) |
|
| 2763 | + if (!is_array($defArray)) |
|
| 2764 | 2764 | return false; |
| 2765 | 2765 | |
| 2766 | - if ( isset($defArray['type']) ){ |
|
| 2766 | + if (isset($defArray['type'])) { |
|
| 2767 | 2767 | // type key exists. May be an array of defs or a simple definition |
| 2768 | 2768 | return is_array($defArray['type']); // type is not an array => definition else array |
| 2769 | 2769 | } |
@@ -2798,19 +2798,19 @@ discard block |
||
| 2798 | 2798 | require('metadata/audit_templateMetaData.php'); |
| 2799 | 2799 | $fieldDefs = $dictionary['audit']['fields']; |
| 2800 | 2800 | |
| 2801 | - $values=array(); |
|
| 2801 | + $values = array(); |
|
| 2802 | 2802 | $values['id'] = $this->massageValue(create_guid(), $fieldDefs['id']); |
| 2803 | - $values['parent_id']= $this->massageValue($bean->id, $fieldDefs['parent_id']); |
|
| 2804 | - $values['field_name']= $this->massageValue($changes['field_name'], $fieldDefs['field_name']); |
|
| 2803 | + $values['parent_id'] = $this->massageValue($bean->id, $fieldDefs['parent_id']); |
|
| 2804 | + $values['field_name'] = $this->massageValue($changes['field_name'], $fieldDefs['field_name']); |
|
| 2805 | 2805 | $values['data_type'] = $this->massageValue($changes['data_type'], $fieldDefs['data_type']); |
| 2806 | - if ($changes['data_type']=='text') { |
|
| 2806 | + if ($changes['data_type'] == 'text') { |
|
| 2807 | 2807 | $values['before_value_text'] = $this->massageValue($changes['before'], $fieldDefs['before_value_text']); |
| 2808 | 2808 | $values['after_value_text'] = $this->massageValue($changes['after'], $fieldDefs['after_value_text']); |
| 2809 | 2809 | } else { |
| 2810 | 2810 | $values['before_value_string'] = $this->massageValue($changes['before'], $fieldDefs['before_value_string']); |
| 2811 | 2811 | $values['after_value_string'] = $this->massageValue($changes['after'], $fieldDefs['after_value_string']); |
| 2812 | 2812 | } |
| 2813 | - $values['date_created'] = $this->massageValue(TimeDate::getInstance()->nowDb(), $fieldDefs['date_created'] ); |
|
| 2813 | + $values['date_created'] = $this->massageValue(TimeDate::getInstance()->nowDb(), $fieldDefs['date_created']); |
|
| 2814 | 2814 | $values['created_by'] = $this->massageValue($current_user->id, $fieldDefs['created_by']); |
| 2815 | 2815 | |
| 2816 | 2816 | $sql .= "(".implode(",", array_keys($values)).") "; |
@@ -2840,9 +2840,9 @@ discard block |
||
| 2840 | 2840 | * @param array|null $field_filter Array of filter names to be inspected (NULL means all fields) |
| 2841 | 2841 | * @return array |
| 2842 | 2842 | */ |
| 2843 | - public function getDataChanges(SugarBean &$bean, array $field_filter = null) |
|
| 2843 | + public function getDataChanges(SugarBean & $bean, array $field_filter = null) |
|
| 2844 | 2844 | { |
| 2845 | - $changed_values=array(); |
|
| 2845 | + $changed_values = array(); |
|
| 2846 | 2846 | |
| 2847 | 2847 | $fetched_row = array(); |
| 2848 | 2848 | if (is_array($bean->fetched_row)) |
@@ -2862,40 +2862,40 @@ discard block |
||
| 2862 | 2862 | $field_defs = array_intersect_key($field_defs, $fetched_row); |
| 2863 | 2863 | |
| 2864 | 2864 | // remove fields which do not exist as bean property |
| 2865 | - $field_defs = array_intersect_key($field_defs, (array) $bean); |
|
| 2865 | + $field_defs = array_intersect_key($field_defs, (array)$bean); |
|
| 2866 | 2866 | |
| 2867 | 2867 | foreach ($field_defs as $field => $properties) { |
| 2868 | 2868 | $before_value = $fetched_row[$field]; |
| 2869 | - $after_value=$bean->$field; |
|
| 2869 | + $after_value = $bean->$field; |
|
| 2870 | 2870 | if (isset($properties['type'])) { |
| 2871 | - $field_type=$properties['type']; |
|
| 2871 | + $field_type = $properties['type']; |
|
| 2872 | 2872 | } else { |
| 2873 | 2873 | if (isset($properties['dbType'])) { |
| 2874 | - $field_type=$properties['dbType']; |
|
| 2874 | + $field_type = $properties['dbType']; |
|
| 2875 | 2875 | } |
| 2876 | - else if(isset($properties['data_type'])) { |
|
| 2877 | - $field_type=$properties['data_type']; |
|
| 2876 | + else if (isset($properties['data_type'])) { |
|
| 2877 | + $field_type = $properties['data_type']; |
|
| 2878 | 2878 | } |
| 2879 | 2879 | else { |
| 2880 | - $field_type=$properties['dbtype']; |
|
| 2880 | + $field_type = $properties['dbtype']; |
|
| 2881 | 2881 | } |
| 2882 | 2882 | } |
| 2883 | 2883 | |
| 2884 | 2884 | //Because of bug #25078(sqlserver haven't 'date' type, trim extra "00:00:00" when insert into *_cstm table). |
| 2885 | 2885 | // so when we read the audit datetime field from sqlserver, we have to replace the extra "00:00:00" again. |
| 2886 | - if(!empty($field_type) && $field_type == 'date'){ |
|
| 2887 | - $before_value = $this->fromConvert($before_value , $field_type); |
|
| 2886 | + if (!empty($field_type) && $field_type == 'date') { |
|
| 2887 | + $before_value = $this->fromConvert($before_value, $field_type); |
|
| 2888 | 2888 | } |
| 2889 | 2889 | //if the type and values match, do nothing. |
| 2890 | - if (!($this->_emptyValue($before_value,$field_type) && $this->_emptyValue($after_value,$field_type))) { |
|
| 2890 | + if (!($this->_emptyValue($before_value, $field_type) && $this->_emptyValue($after_value, $field_type))) { |
|
| 2891 | 2891 | $change = false; |
| 2892 | 2892 | if (trim($before_value) !== trim($after_value)) { |
| 2893 | 2893 | // Bug #42475: Don't directly compare numeric values, instead do the subtract and see if the comparison comes out to be "close enough", it is necessary for floating point numbers. |
| 2894 | 2894 | // Manual merge of fix 95727f2eed44852f1b6bce9a9eccbe065fe6249f from DBHelper |
| 2895 | 2895 | // This fix also fixes Bug #44624 in a more generic way and therefore eliminates the need for fix 0a55125b281c4bee87eb347709af462715f33d2d in DBHelper |
| 2896 | 2896 | if ($this->isNumericType($field_type)) { |
| 2897 | - $numerator = abs(2*((trim($before_value)+0)-(trim($after_value)+0))); |
|
| 2898 | - $denominator = abs(((trim($before_value)+0)+(trim($after_value)+0))); |
|
| 2897 | + $numerator = abs(2 * ((trim($before_value) + 0) - (trim($after_value) + 0))); |
|
| 2898 | + $denominator = abs(((trim($before_value) + 0) + (trim($after_value) + 0))); |
|
| 2899 | 2899 | // detect whether to use absolute or relative error. use absolute if denominator is zero to avoid division by zero |
| 2900 | 2900 | $error = ($denominator == 0) ? $numerator : $numerator / $denominator; |
| 2901 | 2901 | if ($error >= 0.0000000001) { // Smaller than 10E-10 |
@@ -2911,7 +2911,7 @@ discard block |
||
| 2911 | 2911 | $change = true; |
| 2912 | 2912 | } |
| 2913 | 2913 | if ($change) { |
| 2914 | - $changed_values[$field]=array('field_name'=>$field, |
|
| 2914 | + $changed_values[$field] = array('field_name'=>$field, |
|
| 2915 | 2915 | 'data_type'=>$field_type, |
| 2916 | 2916 | 'before'=>$before_value, |
| 2917 | 2917 | 'after'=>$after_value); |
@@ -2982,8 +2982,8 @@ discard block |
||
| 2982 | 2982 | */ |
| 2983 | 2983 | public function renameIndexDefs($old_definition, $new_definition, $table_name) |
| 2984 | 2984 | { |
| 2985 | - return array($this->add_drop_constraint($table_name,$old_definition,true), |
|
| 2986 | - $this->add_drop_constraint($table_name,$new_definition), false); |
|
| 2985 | + return array($this->add_drop_constraint($table_name, $old_definition, true), |
|
| 2986 | + $this->add_drop_constraint($table_name, $new_definition), false); |
|
| 2987 | 2987 | } |
| 2988 | 2988 | |
| 2989 | 2989 | /** |
@@ -3005,7 +3005,7 @@ discard block |
||
| 3005 | 3005 | protected function _getBooleanValue($val) |
| 3006 | 3006 | { |
| 3007 | 3007 | //need to put the === sign here otherwise true == 'non empty string' |
| 3008 | - if (empty($val) or $val==='off') |
|
| 3008 | + if (empty($val) or $val === 'off') |
|
| 3009 | 3009 | return false; |
| 3010 | 3010 | |
| 3011 | 3011 | return true; |
@@ -3018,7 +3018,7 @@ discard block |
||
| 3018 | 3018 | */ |
| 3019 | 3019 | public function isNumericType($type) |
| 3020 | 3020 | { |
| 3021 | - if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3021 | + if (isset($this->type_class[$type]) && ($this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3022 | 3022 | return true; |
| 3023 | 3023 | } |
| 3024 | 3024 | return false; |
@@ -3035,7 +3035,7 @@ discard block |
||
| 3035 | 3035 | if (empty($val)) |
| 3036 | 3036 | return true; |
| 3037 | 3037 | |
| 3038 | - if($this->emptyValue($type) == $val) { |
|
| 3038 | + if ($this->emptyValue($type) == $val) { |
|
| 3039 | 3039 | return true; |
| 3040 | 3040 | } |
| 3041 | 3041 | switch ($type) { |
@@ -3094,7 +3094,7 @@ discard block |
||
| 3094 | 3094 | $i = 0; |
| 3095 | 3095 | $order_by_arr = array(); |
| 3096 | 3096 | foreach ($values as $key => $value) { |
| 3097 | - if($key == '') { |
|
| 3097 | + if ($key == '') { |
|
| 3098 | 3098 | $order_by_arr[] = "WHEN ($order_by='' OR $order_by IS NULL) THEN $i"; |
| 3099 | 3099 | } else { |
| 3100 | 3100 | $order_by_arr[] = "WHEN $order_by=".$this->quoted($key)." THEN $i"; |
@@ -3112,7 +3112,7 @@ discard block |
||
| 3112 | 3112 | */ |
| 3113 | 3113 | public function emptyValue($type) |
| 3114 | 3114 | { |
| 3115 | - if(isset($this->type_class[$type]) && ($this->type_class[$type] == 'bool' || $this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3115 | + if (isset($this->type_class[$type]) && ($this->type_class[$type] == 'bool' || $this->type_class[$type] == 'int' || $this->type_class[$type] == 'float')) { |
|
| 3116 | 3116 | return 0; |
| 3117 | 3117 | } |
| 3118 | 3118 | |
@@ -3161,9 +3161,9 @@ discard block |
||
| 3161 | 3161 | * @return resource|bool query result |
| 3162 | 3162 | * @see DBManager::limitQuery() |
| 3163 | 3163 | */ |
| 3164 | - public function limitQuerySql($sql, $start, $count, $dieOnError=false, $msg='') |
|
| 3164 | + public function limitQuerySql($sql, $start, $count, $dieOnError = false, $msg = '') |
|
| 3165 | 3165 | { |
| 3166 | - return $this->limitQuery($sql,$start,$count,$dieOnError,$msg,false); |
|
| 3166 | + return $this->limitQuery($sql, $start, $count, $dieOnError, $msg, false); |
|
| 3167 | 3167 | } |
| 3168 | 3168 | |
| 3169 | 3169 | /** |
@@ -3182,7 +3182,7 @@ discard block |
||
| 3182 | 3182 | */ |
| 3183 | 3183 | public function checkPrivilege($privilege) |
| 3184 | 3184 | { |
| 3185 | - switch($privilege) { |
|
| 3185 | + switch ($privilege) { |
|
| 3186 | 3186 | case "CREATE TABLE": |
| 3187 | 3187 | $this->query("CREATE TABLE temp (id varchar(36))"); |
| 3188 | 3188 | break; |
@@ -3203,23 +3203,23 @@ discard block |
||
| 3203 | 3203 | break; |
| 3204 | 3204 | case "ADD COLUMN": |
| 3205 | 3205 | $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 50)); |
| 3206 | - $sql = $this->changeColumnSQL("temp", $test, "add"); |
|
| 3206 | + $sql = $this->changeColumnSQL("temp", $test, "add"); |
|
| 3207 | 3207 | $this->query($sql); |
| 3208 | 3208 | break; |
| 3209 | 3209 | case "CHANGE COLUMN": |
| 3210 | 3210 | $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100)); |
| 3211 | - $sql = $this->changeColumnSQL("temp", $test, "modify"); |
|
| 3211 | + $sql = $this->changeColumnSQL("temp", $test, "modify"); |
|
| 3212 | 3212 | $this->query($sql); |
| 3213 | 3213 | break; |
| 3214 | 3214 | case "DROP COLUMN": |
| 3215 | 3215 | $test = array("test" => array("name" => "test", "type" => "varchar", "len" => 100)); |
| 3216 | - $sql = $this->changeColumnSQL("temp", $test, "drop"); |
|
| 3216 | + $sql = $this->changeColumnSQL("temp", $test, "drop"); |
|
| 3217 | 3217 | $this->query($sql); |
| 3218 | 3218 | break; |
| 3219 | 3219 | default: |
| 3220 | 3220 | return false; |
| 3221 | 3221 | } |
| 3222 | - if($this->checkError("Checking privileges")) { |
|
| 3222 | + if ($this->checkError("Checking privileges")) { |
|
| 3223 | 3223 | return false; |
| 3224 | 3224 | } |
| 3225 | 3225 | return true; |
@@ -3236,7 +3236,7 @@ discard block |
||
| 3236 | 3236 | $select_check = strpos(strtolower($query), strtolower("SELECT")); |
| 3237 | 3237 | //Checks to see if there is union select which is valid |
| 3238 | 3238 | $select_check2 = strpos(strtolower($query), strtolower("(SELECT")); |
| 3239 | - if($select_check==0 || $select_check2==0){ |
|
| 3239 | + if ($select_check == 0 || $select_check2 == 0) { |
|
| 3240 | 3240 | //Returning false means query is ok! |
| 3241 | 3241 | return true; |
| 3242 | 3242 | } |
@@ -3255,10 +3255,10 @@ discard block |
||
| 3255 | 3255 | public function parseFulltextQuery($query) |
| 3256 | 3256 | { |
| 3257 | 3257 | /* split on space or comma, double quotes with \ for escape */ |
| 3258 | - if(strpbrk($query, " ,")) { |
|
| 3258 | + if (strpbrk($query, " ,")) { |
|
| 3259 | 3259 | // ("([^"]*?)"|[^" ,]+)((, )+)? |
| 3260 | 3260 | // '/([^" ,]+|".*?[^\\\\]")(,|\s)\s*/' |
| 3261 | - if(!preg_match_all('/("([^"]*?)"|[^"\s,]+)((,\s)+)?/', $query, $m)) { |
|
| 3261 | + if (!preg_match_all('/("([^"]*?)"|[^"\s,]+)((,\s)+)?/', $query, $m)) { |
|
| 3262 | 3262 | return false; |
| 3263 | 3263 | } |
| 3264 | 3264 | $qterms = $m[1]; |
@@ -3266,17 +3266,17 @@ discard block |
||
| 3266 | 3266 | $qterms = array($query); |
| 3267 | 3267 | } |
| 3268 | 3268 | $terms = $must_terms = $not_terms = array(); |
| 3269 | - foreach($qterms as $item) { |
|
| 3270 | - if($item[0] == '"') { |
|
| 3269 | + foreach ($qterms as $item) { |
|
| 3270 | + if ($item[0] == '"') { |
|
| 3271 | 3271 | $item = trim($item, '"'); |
| 3272 | 3272 | } |
| 3273 | - if($item[0] == '+') { |
|
| 3273 | + if ($item[0] == '+') { |
|
| 3274 | 3274 | if (strlen($item) > 1) { |
| 3275 | 3275 | $must_terms[] = substr($item, 1); |
| 3276 | 3276 | } |
| 3277 | 3277 | continue; |
| 3278 | 3278 | } |
| 3279 | - if($item[0] == '-') { |
|
| 3279 | + if ($item[0] == '-') { |
|
| 3280 | 3280 | if (strlen($item) > 1) { |
| 3281 | 3281 | $not_terms[] = substr($item, 1); |
| 3282 | 3282 | } |
@@ -3325,11 +3325,11 @@ discard block |
||
| 3325 | 3325 | public function verifySQLStatement($query, $skipTables) |
| 3326 | 3326 | { |
| 3327 | 3327 | $query = trim($query); |
| 3328 | - foreach($this->standardQueries as $qstart => $check) { |
|
| 3329 | - if(strncasecmp($qstart, $query, strlen($qstart)) == 0) { |
|
| 3330 | - if(is_callable(array($this, $check))) { |
|
| 3328 | + foreach ($this->standardQueries as $qstart => $check) { |
|
| 3329 | + if (strncasecmp($qstart, $query, strlen($qstart)) == 0) { |
|
| 3330 | + if (is_callable(array($this, $check))) { |
|
| 3331 | 3331 | $table = $this->extractTableName($query); |
| 3332 | - if(!in_array($table, $skipTables)) { |
|
| 3332 | + if (!in_array($table, $skipTables)) { |
|
| 3333 | 3333 | return call_user_func(array($this, $check), $table, $query); |
| 3334 | 3334 | } else { |
| 3335 | 3335 | $this->log->debug("Skipping table $table as blacklisted"); |
@@ -3358,20 +3358,20 @@ discard block |
||
| 3358 | 3358 | $tempname = $table."__uw_temp"; |
| 3359 | 3359 | $tempTableQuery = str_replace("CREATE TABLE {$table}", "CREATE TABLE $tempname", $query); |
| 3360 | 3360 | |
| 3361 | - if(strpos($tempTableQuery, '__uw_temp') === false) { |
|
| 3361 | + if (strpos($tempTableQuery, '__uw_temp') === false) { |
|
| 3362 | 3362 | return 'Could not use a temp table to test query!'; |
| 3363 | 3363 | } |
| 3364 | 3364 | |
| 3365 | 3365 | $this->query($tempTableQuery, false, "Preflight Failed for: {$query}"); |
| 3366 | 3366 | |
| 3367 | 3367 | $error = $this->lastError(); // empty on no-errors |
| 3368 | - if(!empty($error)) { |
|
| 3368 | + if (!empty($error)) { |
|
| 3369 | 3369 | return $error; |
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | 3372 | // check if table exists |
| 3373 | 3373 | $this->log->debug('testing for table: '.$table); |
| 3374 | - if(!$this->tableExists($tempname)) { |
|
| 3374 | + if (!$this->tableExists($tempname)) { |
|
| 3375 | 3375 | return "Failed to create temp table!"; |
| 3376 | 3376 | } |
| 3377 | 3377 | |
@@ -3390,8 +3390,8 @@ discard block |
||
| 3390 | 3390 | public function queryArray(array $sqls, $dieOnError = false, $msg = '', $suppress = false) |
| 3391 | 3391 | { |
| 3392 | 3392 | $last = true; |
| 3393 | - foreach($sqls as $sql) { |
|
| 3394 | - if(!($last = $this->query($sql, $dieOnError, $msg, $suppress))) { |
|
| 3393 | + foreach ($sqls as $sql) { |
|
| 3394 | + if (!($last = $this->query($sql, $dieOnError, $msg, $suppress))) { |
|
| 3395 | 3395 | break; |
| 3396 | 3396 | } |
| 3397 | 3397 | } |
@@ -3409,7 +3409,7 @@ discard block |
||
| 3409 | 3409 | { |
| 3410 | 3410 | if (empty($result)) return false; |
| 3411 | 3411 | |
| 3412 | - if(is_int($encode) && func_num_args() == 3) { |
|
| 3412 | + if (is_int($encode) && func_num_args() == 3) { |
|
| 3413 | 3413 | // old API: $result, $rowNum, $encode |
| 3414 | 3414 | $GLOBALS['log']->deprecated("Using row number in fetchByAssoc is not portable and no longer supported. Please fix your code."); |
| 3415 | 3415 | $encode = func_get_arg(2); |
@@ -3460,7 +3460,7 @@ discard block |
||
| 3460 | 3460 | */ |
| 3461 | 3461 | public function getOption($option) |
| 3462 | 3462 | { |
| 3463 | - if(isset($this->options[$option])) { |
|
| 3463 | + if (isset($this->options[$option])) { |
|
| 3464 | 3464 | return $this->options[$option]; |
| 3465 | 3465 | } |
| 3466 | 3466 | return null; |
@@ -3500,7 +3500,7 @@ discard block |
||
| 3500 | 3500 | public function isDatabaseNameValid($name) |
| 3501 | 3501 | { |
| 3502 | 3502 | // Generic case - no slashes, no dots |
| 3503 | - return preg_match('#[/.\\\\]#', $name)==0; |
|
| 3503 | + return preg_match('#[/.\\\\]#', $name) == 0; |
|
| 3504 | 3504 | } |
| 3505 | 3505 | |
| 3506 | 3506 | /** |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -403,13 +405,15 @@ discard block |
||
| 403 | 405 | $match = array(); |
| 404 | 406 | preg_match_all("'.* FROM ([^ ]*).* ORDER BY (.*)'is", $sql, $match); |
| 405 | 407 | $indices = false; |
| 406 | - if (!empty($match[1][0])) |
|
| 407 | - $table = $match[1][0]; |
|
| 408 | - else |
|
| 409 | - return false; |
|
| 408 | + if (!empty($match[1][0])) { |
|
| 409 | + $table = $match[1][0]; |
|
| 410 | + } else { |
|
| 411 | + return false; |
|
| 412 | + } |
|
| 410 | 413 | |
| 411 | - if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) |
|
| 412 | - $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
|
| 414 | + if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) { |
|
| 415 | + $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
|
| 416 | + } |
|
| 413 | 417 | |
| 414 | 418 | if (empty($indices)) { |
| 415 | 419 | foreach ( $GLOBALS['dictionary'] as $current ) { |
@@ -427,25 +431,29 @@ discard block |
||
| 427 | 431 | $orderBys = explode(' ', $match[2][0]); |
| 428 | 432 | foreach ($orderBys as $orderBy){ |
| 429 | 433 | $orderBy = trim($orderBy); |
| 430 | - if (empty($orderBy)) |
|
| 431 | - continue; |
|
| 434 | + if (empty($orderBy)) { |
|
| 435 | + continue; |
|
| 436 | + } |
|
| 432 | 437 | $orderBy = strtolower($orderBy); |
| 433 | - if ($orderBy == 'asc' || $orderBy == 'desc') |
|
| 434 | - continue; |
|
| 438 | + if ($orderBy == 'asc' || $orderBy == 'desc') { |
|
| 439 | + continue; |
|
| 440 | + } |
|
| 435 | 441 | |
| 436 | 442 | $orderBy = str_replace(array($table . '.', ','), '', $orderBy); |
| 437 | 443 | |
| 438 | - foreach ($indices as $index) |
|
| 439 | - if (empty($index['db']) || $index['db'] == $this->dbType) |
|
| 444 | + foreach ($indices as $index) { |
|
| 445 | + if (empty($index['db']) || $index['db'] == $this->dbType) |
|
| 440 | 446 | foreach ($index['fields'] as $field) |
| 441 | 447 | if ($field == $orderBy) |
| 442 | 448 | return true; |
| 449 | + } |
|
| 443 | 450 | |
| 444 | 451 | $warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy ; |
| 445 | - if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) |
|
| 446 | - $this->log->fatal('CHECK QUERY:' .$warning); |
|
| 447 | - else |
|
| 448 | - $this->log->warn('CHECK QUERY:' .$warning); |
|
| 452 | + if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) { |
|
| 453 | + $this->log->fatal('CHECK QUERY:' .$warning); |
|
| 454 | + } else { |
|
| 455 | + $this->log->warn('CHECK QUERY:' .$warning); |
|
| 456 | + } |
|
| 449 | 457 | } |
| 450 | 458 | } |
| 451 | 459 | return false; |
@@ -467,8 +475,9 @@ discard block |
||
| 467 | 475 | public function checkConnection() |
| 468 | 476 | { |
| 469 | 477 | $this->last_error = ''; |
| 470 | - if (!isset($this->database)) |
|
| 471 | - $this->connect(); |
|
| 478 | + if (!isset($this->database)) { |
|
| 479 | + $this->connect(); |
|
| 480 | + } |
|
| 472 | 481 | } |
| 473 | 482 | |
| 474 | 483 | /** |
@@ -510,9 +519,13 @@ discard block |
||
| 510 | 519 | $values = array(); |
| 511 | 520 | foreach ($field_defs as $field => $fieldDef) |
| 512 | 521 | { |
| 513 | - if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
| 522 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') { |
|
| 523 | + continue; |
|
| 524 | + } |
|
| 514 | 525 | //custom fields handle there save seperatley |
| 515 | - if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue; |
|
| 526 | + if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) { |
|
| 527 | + continue; |
|
| 528 | + } |
|
| 516 | 529 | |
| 517 | 530 | if(isset($data[$field])) { |
| 518 | 531 | // clean the incoming value.. |
@@ -541,8 +554,10 @@ discard block |
||
| 541 | 554 | } |
| 542 | 555 | } |
| 543 | 556 | |
| 544 | - if (empty($values)) |
|
| 545 | - return $execute?true:''; // no columns set |
|
| 557 | + if (empty($values)) { |
|
| 558 | + return $execute?true:''; |
|
| 559 | + } |
|
| 560 | + // no columns set |
|
| 546 | 561 | |
| 547 | 562 | // get the entire sql |
| 548 | 563 | $query = "INSERT INTO $table (".implode(",", array_keys($values)).") |
@@ -642,9 +657,10 @@ discard block |
||
| 642 | 657 | if(!$this->supports("inline_keys")) { |
| 643 | 658 | // handle constraints and indices |
| 644 | 659 | $indicesArr = $this->createConstraintSql($bean); |
| 645 | - if (count($indicesArr) > 0) |
|
| 646 | - foreach ($indicesArr as $indexSql) |
|
| 660 | + if (count($indicesArr) > 0) { |
|
| 661 | + foreach ($indicesArr as $indexSql) |
|
| 647 | 662 | $this->query($indexSql, true, $msg); |
| 663 | + } |
|
| 648 | 664 | } |
| 649 | 665 | } |
| 650 | 666 | |
@@ -681,9 +697,10 @@ discard block |
||
| 681 | 697 | if(!$this->supports("inline_keys")) { |
| 682 | 698 | // handle constraints and indices |
| 683 | 699 | $indicesArr = $this->getConstraintSql($indices, $tablename); |
| 684 | - if (count($indicesArr) > 0) |
|
| 685 | - foreach ($indicesArr as $indexSql) |
|
| 700 | + if (count($indicesArr) > 0) { |
|
| 701 | + foreach ($indicesArr as $indexSql) |
|
| 686 | 702 | $res = ($res and $this->query($indexSql, true, "Error creating indexes")); |
| 703 | + } |
|
| 687 | 704 | } |
| 688 | 705 | return $res; |
| 689 | 706 | } |
@@ -710,13 +727,15 @@ discard block |
||
| 710 | 727 | } |
| 711 | 728 | //jc: added this for beans that do not actually have a table, namely |
| 712 | 729 | //ForecastOpportunities |
| 713 | - if($tablename == 'does_not_exist' || $tablename == '') |
|
| 714 | - return ''; |
|
| 730 | + if($tablename == 'does_not_exist' || $tablename == '') { |
|
| 731 | + return ''; |
|
| 732 | + } |
|
| 715 | 733 | |
| 716 | 734 | global $dictionary; |
| 717 | 735 | $engine=null; |
| 718 | - if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) |
|
| 719 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 736 | + if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) { |
|
| 737 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 738 | + } |
|
| 720 | 739 | |
| 721 | 740 | return $this->repairTableParams($tablename, $fielddefs,$new_index,$execute,$engine); |
| 722 | 741 | } |
@@ -760,8 +779,9 @@ discard block |
||
| 760 | 779 | { |
| 761 | 780 | //jc: had a bug when running the repair if the tablename is blank the repair will |
| 762 | 781 | //fail when it tries to create a repair table |
| 763 | - if ($tablename == '' || empty($fielddefs)) |
|
| 764 | - return ''; |
|
| 782 | + if ($tablename == '' || empty($fielddefs)) { |
|
| 783 | + return ''; |
|
| 784 | + } |
|
| 765 | 785 | |
| 766 | 786 | //if the table does not exist create it and we are done |
| 767 | 787 | $sql = "/* Table : $tablename */\n"; |
@@ -784,16 +804,16 @@ discard block |
||
| 784 | 804 | // do column comparisons |
| 785 | 805 | $sql .= "/*COLUMNS*/\n"; |
| 786 | 806 | foreach ($fielddefs as $name => $value) { |
| 787 | - if (isset($value['source']) && $value['source'] != 'db') |
|
| 788 | - continue; |
|
| 807 | + if (isset($value['source']) && $value['source'] != 'db') { |
|
| 808 | + continue; |
|
| 809 | + } |
|
| 789 | 810 | |
| 790 | 811 | // Bug #42406. Skipping breaked vardef without type or name |
| 791 | 812 | if (isset($value['name']) == false || $value['name'] == false) |
| 792 | 813 | { |
| 793 | 814 | $sql .= "/* NAME IS MISSING IN VARDEF $tablename::$name */\n"; |
| 794 | 815 | continue; |
| 795 | - } |
|
| 796 | - else if (isset($value['type']) == false || $value['type'] == false) |
|
| 816 | + } else if (isset($value['type']) == false || $value['type'] == false) |
|
| 797 | 817 | { |
| 798 | 818 | $sql .= "/* TYPE IS MISSING IN VARDEF $tablename::$name */\n"; |
| 799 | 819 | continue; |
@@ -823,8 +843,9 @@ discard block |
||
| 823 | 843 | // ok we need this field lets create it |
| 824 | 844 | $sql .= "/*MISSING IN DATABASE - $name - ROW*/\n"; |
| 825 | 845 | $sql .= $this->addColumnSQL($tablename, $value) . "\n"; |
| 826 | - if ($execute) |
|
| 827 | - $this->addColumn($tablename, $value); |
|
| 846 | + if ($execute) { |
|
| 847 | + $this->addColumn($tablename, $value); |
|
| 848 | + } |
|
| 828 | 849 | $take_action = true; |
| 829 | 850 | } elseif ( !$this->compareVarDefs($compareFieldDefs[$name],$value)) { |
| 830 | 851 | //fields are different lets alter it |
@@ -880,8 +901,9 @@ discard block |
||
| 880 | 901 | unset($compareIndices_case_insensitive); |
| 881 | 902 | |
| 882 | 903 | foreach ($indices as $value) { |
| 883 | - if (isset($value['source']) && $value['source'] != 'db') |
|
| 884 | - continue; |
|
| 904 | + if (isset($value['source']) && $value['source'] != 'db') { |
|
| 905 | + continue; |
|
| 906 | + } |
|
| 885 | 907 | |
| 886 | 908 | |
| 887 | 909 | $validDBName = $this->getValidDBName($value['name'], true, 'index', true); |
@@ -891,19 +913,23 @@ discard block |
||
| 891 | 913 | $name = strtolower($value['name']); |
| 892 | 914 | |
| 893 | 915 | //Don't attempt to fix the same index twice in one pass; |
| 894 | - if (isset($correctedIndexs[$name])) |
|
| 895 | - continue; |
|
| 916 | + if (isset($correctedIndexs[$name])) { |
|
| 917 | + continue; |
|
| 918 | + } |
|
| 896 | 919 | |
| 897 | 920 | //don't bother checking primary nothing we can do about them |
| 898 | - if (isset($value['type']) && $value['type'] == 'primary') |
|
| 899 | - continue; |
|
| 921 | + if (isset($value['type']) && $value['type'] == 'primary') { |
|
| 922 | + continue; |
|
| 923 | + } |
|
| 900 | 924 | |
| 901 | 925 | //database helpers do not know how to handle full text indices |
| 902 | - if ($value['type']=='fulltext') |
|
| 903 | - continue; |
|
| 926 | + if ($value['type']=='fulltext') { |
|
| 927 | + continue; |
|
| 928 | + } |
|
| 904 | 929 | |
| 905 | - if ( in_array($value['type'],array('alternate_key','foreign')) ) |
|
| 906 | - $value['type'] = 'index'; |
|
| 930 | + if ( in_array($value['type'],array('alternate_key','foreign')) ) { |
|
| 931 | + $value['type'] = 'index'; |
|
| 932 | + } |
|
| 907 | 933 | |
| 908 | 934 | if ( !isset($compareIndices[$name]) ) { |
| 909 | 935 | //First check if an index exists that doesn't match our name, if so, try to rename it |
@@ -934,21 +960,23 @@ discard block |
||
| 934 | 960 | $sql .= "/*INDEX MISMATCH WITH DATABASE - $name - ROW "; |
| 935 | 961 | foreach ($compareIndices[$name] as $n1 => $t1) { |
| 936 | 962 | $sql .= "<$n1>"; |
| 937 | - if ( $n1 == 'fields' ) |
|
| 938 | - foreach($t1 as $rKey => $rValue) |
|
| 963 | + if ( $n1 == 'fields' ) { |
|
| 964 | + foreach($t1 as $rKey => $rValue) |
|
| 939 | 965 | $sql .= "[$rKey] => '$rValue' "; |
| 940 | - else |
|
| 941 | - $sql .= " $t1 "; |
|
| 966 | + } else { |
|
| 967 | + $sql .= " $t1 "; |
|
| 968 | + } |
|
| 942 | 969 | } |
| 943 | 970 | $sql .= "*/\n"; |
| 944 | 971 | $sql .= "/* VARDEF - $name - ROW"; |
| 945 | 972 | foreach ($value as $n1 => $t1) { |
| 946 | 973 | $sql .= "<$n1>"; |
| 947 | - if ( $n1 == 'fields' ) |
|
| 948 | - foreach ($t1 as $rKey => $rValue) |
|
| 974 | + if ( $n1 == 'fields' ) { |
|
| 975 | + foreach ($t1 as $rKey => $rValue) |
|
| 949 | 976 | $sql .= "[$rKey] => '$rValue' "; |
| 950 | - else |
|
| 951 | - $sql .= " $t1 "; |
|
| 977 | + } else { |
|
| 978 | + $sql .= " $t1 "; |
|
| 979 | + } |
|
| 952 | 980 | } |
| 953 | 981 | $sql .= "*/\n"; |
| 954 | 982 | $sql .= $this->modifyIndexes($tablename,array($value), $execute) . "\n"; |
@@ -971,8 +999,9 @@ discard block |
||
| 971 | 999 | public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
| 972 | 1000 | { |
| 973 | 1001 | foreach ( $fielddef1 as $key => $value ) { |
| 974 | - if ($key == 'name' && $ignoreName) |
|
| 975 | - continue; |
|
| 1002 | + if ($key == 'name' && $ignoreName) { |
|
| 1003 | + continue; |
|
| 1004 | + } |
|
| 976 | 1005 | if (isset($fielddef2[$key])) |
| 977 | 1006 | { |
| 978 | 1007 | if (!is_array($fielddef1[$key]) && !is_array($fielddef2[$key])) |
@@ -981,8 +1010,7 @@ discard block |
||
| 981 | 1010 | { |
| 982 | 1011 | continue; |
| 983 | 1012 | } |
| 984 | - } |
|
| 985 | - else |
|
| 1013 | + } else |
|
| 986 | 1014 | { |
| 987 | 1015 | if (array_map('strtolower', $fielddef1[$key]) == array_map('strtolower',$fielddef2[$key])) |
| 988 | 1016 | { |
@@ -991,8 +1019,9 @@ discard block |
||
| 991 | 1019 | } |
| 992 | 1020 | } |
| 993 | 1021 | //Ignore len if its not set in the vardef |
| 994 | - if ($key == 'len' && empty($fielddef2[$key])) |
|
| 995 | - continue; |
|
| 1022 | + if ($key == 'len' && empty($fielddef2[$key])) { |
|
| 1023 | + continue; |
|
| 1024 | + } |
|
| 996 | 1025 | // if the length in db is greather than the vardef, ignore it |
| 997 | 1026 | if ($key == 'len' && ($fielddef1[$key] >= $fielddef2[$key])) { |
| 998 | 1027 | continue; |
@@ -1026,12 +1055,10 @@ discard block |
||
| 1026 | 1055 | if (!$row2) { |
| 1027 | 1056 | // Exists on table1 but not table2 |
| 1028 | 1057 | $returnArray['msg'] = 'not_exists_table2'; |
| 1029 | - } |
|
| 1030 | - else { |
|
| 1058 | + } else { |
|
| 1031 | 1059 | if (sizeof($row1) != sizeof($row2)) { |
| 1032 | 1060 | $returnArray['msg'] = 'no_match'; |
| 1033 | - } |
|
| 1034 | - else { |
|
| 1061 | + } else { |
|
| 1035 | 1062 | $returnArray['msg'] = 'match'; |
| 1036 | 1063 | foreach($row1 as $key => $value){ |
| 1037 | 1064 | //ignore keys when checking we will check them when we do the index check |
@@ -1041,8 +1068,7 @@ discard block |
||
| 1041 | 1068 | } |
| 1042 | 1069 | } |
| 1043 | 1070 | } |
| 1044 | - } |
|
| 1045 | - else { |
|
| 1071 | + } else { |
|
| 1046 | 1072 | $returnArray['msg'] = 'not_exists_table1'; |
| 1047 | 1073 | } |
| 1048 | 1074 | |
@@ -1122,16 +1148,19 @@ discard block |
||
| 1122 | 1148 | */ |
| 1123 | 1149 | public function getConstraintSql($indices, $table) |
| 1124 | 1150 | { |
| 1125 | - if (!$this->isFieldArray($indices)) |
|
| 1126 | - $indices = array($indices); |
|
| 1151 | + if (!$this->isFieldArray($indices)) { |
|
| 1152 | + $indices = array($indices); |
|
| 1153 | + } |
|
| 1127 | 1154 | |
| 1128 | 1155 | $columns = array(); |
| 1129 | 1156 | |
| 1130 | 1157 | foreach ($indices as $index) { |
| 1131 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 1132 | - continue; |
|
| 1133 | - if (isset($index['source']) && $index['source'] != 'db') |
|
| 1134 | - continue; |
|
| 1158 | + if(!empty($index['db']) && $index['db'] != $this->dbType) { |
|
| 1159 | + continue; |
|
| 1160 | + } |
|
| 1161 | + if (isset($index['source']) && $index['source'] != 'db') { |
|
| 1162 | + continue; |
|
| 1163 | + } |
|
| 1135 | 1164 | |
| 1136 | 1165 | $sql = $this->add_drop_constraint($table, $index); |
| 1137 | 1166 | |
@@ -1221,11 +1250,11 @@ discard block |
||
| 1221 | 1250 | $sql = $this->addColumnSQL($tablename, $fieldDefs); |
| 1222 | 1251 | if ($this->isFieldArray($fieldDefs)){ |
| 1223 | 1252 | $columns = array(); |
| 1224 | - foreach ($fieldDefs as $fieldDef) |
|
| 1225 | - $columns[] = $fieldDef['name']; |
|
| 1253 | + foreach ($fieldDefs as $fieldDef) { |
|
| 1254 | + $columns[] = $fieldDef['name']; |
|
| 1255 | + } |
|
| 1226 | 1256 | $columns = implode(",", $columns); |
| 1227 | - } |
|
| 1228 | - else { |
|
| 1257 | + } else { |
|
| 1229 | 1258 | $columns = $fieldDefs['name']; |
| 1230 | 1259 | } |
| 1231 | 1260 | $msg = "Error adding column(s) $columns on table: $tablename:"; |
@@ -1249,8 +1278,7 @@ discard block |
||
| 1249 | 1278 | $columns[] = $fieldDef['name']; |
| 1250 | 1279 | } |
| 1251 | 1280 | $columns = implode(",", $columns); |
| 1252 | - } |
|
| 1253 | - else { |
|
| 1281 | + } else { |
|
| 1254 | 1282 | $columns = $newFieldDef['name']; |
| 1255 | 1283 | } |
| 1256 | 1284 | |
@@ -1370,7 +1398,9 @@ discard block |
||
| 1370 | 1398 | if(!$is_related_query){ |
| 1371 | 1399 | foreach ($fields as $fieldDef) |
| 1372 | 1400 | { |
| 1373 | - if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue; |
|
| 1401 | + if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') { |
|
| 1402 | + continue; |
|
| 1403 | + } |
|
| 1374 | 1404 | $val = $row[$fieldDef['name']]; |
| 1375 | 1405 | |
| 1376 | 1406 | //handle auto increment values here only need to do this on insert not create |
@@ -1379,8 +1409,7 @@ discard block |
||
| 1379 | 1409 | if(!$built_columns){ |
| 1380 | 1410 | $columns[] = 'deleted'; |
| 1381 | 1411 | } |
| 1382 | - } |
|
| 1383 | - else |
|
| 1412 | + } else |
|
| 1384 | 1413 | { |
| 1385 | 1414 | $type = $fieldDef['type']; |
| 1386 | 1415 | if(!empty($fieldDef['custom_type'])){ |
@@ -1388,28 +1417,32 @@ discard block |
||
| 1388 | 1417 | } |
| 1389 | 1418 | // need to do some thing about types of values |
| 1390 | 1419 | if($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')){ |
| 1391 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1392 | - $cstm_values[$fieldDef['name']] = 'null'; |
|
| 1393 | - else |
|
| 1394 | - $values[$fieldDef['name']] = 'null'; |
|
| 1395 | - }else{ |
|
| 1420 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
| 1421 | + $cstm_values[$fieldDef['name']] = 'null'; |
|
| 1422 | + } else { |
|
| 1423 | + $values[$fieldDef['name']] = 'null'; |
|
| 1424 | + } |
|
| 1425 | + } else{ |
|
| 1396 | 1426 | if(isset($type) && $type=='int') { |
| 1397 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1398 | - $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1399 | - else |
|
| 1400 | - $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1427 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
| 1428 | + $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1429 | + } else { |
|
| 1430 | + $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
| 1431 | + } |
|
| 1401 | 1432 | } else { |
| 1402 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1403 | - $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1404 | - else |
|
| 1405 | - $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1433 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
| 1434 | + $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1435 | + } else { |
|
| 1436 | + $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
| 1437 | + } |
|
| 1406 | 1438 | } |
| 1407 | 1439 | } |
| 1408 | 1440 | if(!$built_columns){ |
| 1409 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
| 1410 | - $cstm_columns[] = $fieldDef['name']; |
|
| 1411 | - else |
|
| 1412 | - $columns[] = $fieldDef['name']; |
|
| 1441 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
| 1442 | + $cstm_columns[] = $fieldDef['name']; |
|
| 1443 | + } else { |
|
| 1444 | + $columns[] = $fieldDef['name']; |
|
| 1445 | + } |
|
| 1413 | 1446 | } |
| 1414 | 1447 | } |
| 1415 | 1448 | |
@@ -1624,7 +1657,9 @@ discard block |
||
| 1624 | 1657 | $queryresult = $this->query($sql, $dieOnError, $msg); |
| 1625 | 1658 | } |
| 1626 | 1659 | $this->checkError($msg.' Get One Failed:' . $sql, $dieOnError); |
| 1627 | - if (!$queryresult) return false; |
|
| 1660 | + if (!$queryresult) { |
|
| 1661 | + return false; |
|
| 1662 | + } |
|
| 1628 | 1663 | $row = $this->fetchByAssoc($queryresult); |
| 1629 | 1664 | if(!empty($row)) { |
| 1630 | 1665 | return array_shift($row); |
@@ -1648,10 +1683,14 @@ discard block |
||
| 1648 | 1683 | $queryresult = $this->query($sql, $dieOnError, $msg); |
| 1649 | 1684 | $this->checkError($msg.' Fetch One Failed:' . $sql, $dieOnError); |
| 1650 | 1685 | |
| 1651 | - if (!$queryresult) return false; |
|
| 1686 | + if (!$queryresult) { |
|
| 1687 | + return false; |
|
| 1688 | + } |
|
| 1652 | 1689 | |
| 1653 | 1690 | $row = $this->fetchByAssoc($queryresult); |
| 1654 | - if ( !$row ) return false; |
|
| 1691 | + if ( !$row ) { |
|
| 1692 | + return false; |
|
| 1693 | + } |
|
| 1655 | 1694 | |
| 1656 | 1695 | $this->freeResult($queryresult); |
| 1657 | 1696 | return $row; |
@@ -1708,13 +1747,15 @@ discard block |
||
| 1708 | 1747 | protected function describeField($name, $tablename) |
| 1709 | 1748 | { |
| 1710 | 1749 | $table = $this->getTableDescription($tablename); |
| 1711 | - if(!empty($table) && isset($table[$name])) |
|
| 1712 | - return $table[$name]; |
|
| 1750 | + if(!empty($table) && isset($table[$name])) { |
|
| 1751 | + return $table[$name]; |
|
| 1752 | + } |
|
| 1713 | 1753 | |
| 1714 | 1754 | $table = $this->getTableDescription($tablename, true); |
| 1715 | 1755 | |
| 1716 | - if(isset($table[$name])) |
|
| 1717 | - return $table[$name]; |
|
| 1756 | + if(isset($table[$name])) { |
|
| 1757 | + return $table[$name]; |
|
| 1758 | + } |
|
| 1718 | 1759 | |
| 1719 | 1760 | return array(); |
| 1720 | 1761 | } |
@@ -1768,11 +1809,15 @@ discard block |
||
| 1768 | 1809 | */ |
| 1769 | 1810 | public function concat($table, array $fields, $space = ' ') |
| 1770 | 1811 | { |
| 1771 | - if(empty($fields)) return ''; |
|
| 1812 | + if(empty($fields)) { |
|
| 1813 | + return ''; |
|
| 1814 | + } |
|
| 1772 | 1815 | $elems = array(); |
| 1773 | 1816 | $space = $this->quoted($space); |
| 1774 | 1817 | foreach ( $fields as $field ) { |
| 1775 | - if(!empty($elems)) $elems[] = $space; |
|
| 1818 | + if(!empty($elems)) { |
|
| 1819 | + $elems[] = $space; |
|
| 1820 | + } |
|
| 1776 | 1821 | $elems[] = $this->convert("$table.$field", 'IFNULL', array("''")); |
| 1777 | 1822 | } |
| 1778 | 1823 | $first = array_shift($elems); |
@@ -1864,7 +1909,7 @@ discard block |
||
| 1864 | 1909 | }//switch |
| 1865 | 1910 | }//foreach |
| 1866 | 1911 | return $this->query($query); |
| 1867 | - }else{ |
|
| 1912 | + } else{ |
|
| 1868 | 1913 | return false; |
| 1869 | 1914 | } |
| 1870 | 1915 | } |
@@ -1926,20 +1971,30 @@ discard block |
||
| 1926 | 1971 | $fields = $bean->getFieldDefinitions(); |
| 1927 | 1972 | // get column names and values |
| 1928 | 1973 | foreach ($fields as $field => $fieldDef) { |
| 1929 | - if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
| 1974 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') { |
|
| 1975 | + continue; |
|
| 1976 | + } |
|
| 1930 | 1977 | // Do not write out the id field on the update statement. |
| 1931 | 1978 | // We are not allowed to change ids. |
| 1932 | - if ($fieldDef['name'] == $primaryField['name']) continue; |
|
| 1979 | + if ($fieldDef['name'] == $primaryField['name']) { |
|
| 1980 | + continue; |
|
| 1981 | + } |
|
| 1933 | 1982 | |
| 1934 | 1983 | // If the field is an auto_increment field, then we shouldn't be setting it. This was added |
| 1935 | 1984 | // specially for Bugs and Cases which have a number associated with them. |
| 1936 | - if (!empty($bean->field_name_map[$field]['auto_increment'])) continue; |
|
| 1985 | + if (!empty($bean->field_name_map[$field]['auto_increment'])) { |
|
| 1986 | + continue; |
|
| 1987 | + } |
|
| 1937 | 1988 | |
| 1938 | 1989 | //custom fields handle their save separately |
| 1939 | - if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) continue; |
|
| 1990 | + if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) { |
|
| 1991 | + continue; |
|
| 1992 | + } |
|
| 1940 | 1993 | |
| 1941 | 1994 | // no need to clear deleted since we only update not deleted records anyway |
| 1942 | - if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue; |
|
| 1995 | + if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) { |
|
| 1996 | + continue; |
|
| 1997 | + } |
|
| 1943 | 1998 | |
| 1944 | 1999 | if(isset($bean->$field)) { |
| 1945 | 2000 | $val = from_html($bean->$field); |
@@ -1972,8 +2027,10 @@ discard block |
||
| 1972 | 2027 | } |
| 1973 | 2028 | } |
| 1974 | 2029 | |
| 1975 | - if ( sizeof($columns) == 0 ) |
|
| 1976 | - return ""; // no columns set |
|
| 2030 | + if ( sizeof($columns) == 0 ) { |
|
| 2031 | + return ""; |
|
| 2032 | + } |
|
| 2033 | + // no columns set |
|
| 1977 | 2034 | |
| 1978 | 2035 | // build where clause |
| 1979 | 2036 | $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
@@ -2039,8 +2096,9 @@ discard block |
||
| 2039 | 2096 | $where[] = " $table.$name $op $val"; |
| 2040 | 2097 | } |
| 2041 | 2098 | |
| 2042 | - if (!empty($where)) |
|
| 2043 | - return implode(" AND ", $where); |
|
| 2099 | + if (!empty($where)) { |
|
| 2100 | + return implode(" AND ", $where); |
|
| 2101 | + } |
|
| 2044 | 2102 | |
| 2045 | 2103 | return ''; |
| 2046 | 2104 | } |
@@ -2144,21 +2202,25 @@ discard block |
||
| 2144 | 2202 | public function massageFieldDef(&$fieldDef, $tablename) |
| 2145 | 2203 | { |
| 2146 | 2204 | if ( !isset($fieldDef['dbType']) ) { |
| 2147 | - if ( isset($fieldDef['dbtype']) ) |
|
| 2148 | - $fieldDef['dbType'] = $fieldDef['dbtype']; |
|
| 2149 | - else |
|
| 2150 | - $fieldDef['dbType'] = $fieldDef['type']; |
|
| 2205 | + if ( isset($fieldDef['dbtype']) ) { |
|
| 2206 | + $fieldDef['dbType'] = $fieldDef['dbtype']; |
|
| 2207 | + } else { |
|
| 2208 | + $fieldDef['dbType'] = $fieldDef['type']; |
|
| 2209 | + } |
|
| 2151 | 2210 | } |
| 2152 | 2211 | $type = $this->getColumnType($fieldDef['dbType'],$fieldDef['name'],$tablename); |
| 2153 | 2212 | $matches = array(); |
| 2154 | 2213 | // len can be a number or a string like 'max', for example, nvarchar(max) |
| 2155 | 2214 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*|\w+)\)|)/i', $type, $matches); |
| 2156 | - if ( isset($matches[1][0]) ) |
|
| 2157 | - $fieldDef['type'] = $matches[1][0]; |
|
| 2158 | - if ( isset($matches[2][0]) && empty($fieldDef['len']) ) |
|
| 2159 | - $fieldDef['len'] = $matches[2][0]; |
|
| 2160 | - if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) |
|
| 2161 | - $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
|
| 2215 | + if ( isset($matches[1][0]) ) { |
|
| 2216 | + $fieldDef['type'] = $matches[1][0]; |
|
| 2217 | + } |
|
| 2218 | + if ( isset($matches[2][0]) && empty($fieldDef['len']) ) { |
|
| 2219 | + $fieldDef['len'] = $matches[2][0]; |
|
| 2220 | + } |
|
| 2221 | + if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) { |
|
| 2222 | + $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
|
| 2223 | + } |
|
| 2162 | 2224 | if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required'])) ) { |
| 2163 | 2225 | $fieldDef['required'] = 'true'; |
| 2164 | 2226 | } |
@@ -2172,8 +2234,9 @@ discard block |
||
| 2172 | 2234 | public function getSelectFieldsFromQuery($selectStatement) |
| 2173 | 2235 | { |
| 2174 | 2236 | $selectStatement = trim($selectStatement); |
| 2175 | - if (strtoupper(substr($selectStatement, 0, 6)) == "SELECT") |
|
| 2176 | - $selectStatement = trim(substr($selectStatement, 6)); |
|
| 2237 | + if (strtoupper(substr($selectStatement, 0, 6)) == "SELECT") { |
|
| 2238 | + $selectStatement = trim(substr($selectStatement, 6)); |
|
| 2239 | + } |
|
| 2177 | 2240 | |
| 2178 | 2241 | //Due to sql functions existing in many selects, we can't use php explode |
| 2179 | 2242 | $fields = array(); |
@@ -2189,17 +2252,15 @@ discard block |
||
| 2189 | 2252 | $field = $this->getFieldNameFromSelect(trim($selectField)); |
| 2190 | 2253 | $fields[$field] = $selectField; |
| 2191 | 2254 | $selectField = ""; |
| 2192 | - } |
|
| 2193 | - else if ($char == "("){ |
|
| 2255 | + } else if ($char == "("){ |
|
| 2194 | 2256 | $level++; |
| 2195 | 2257 | $selectField .= $char; |
| 2196 | - } |
|
| 2197 | - else if($char == ")"){ |
|
| 2258 | + } else if($char == ")"){ |
|
| 2198 | 2259 | $level--; |
| 2199 | 2260 | $selectField .= $char; |
| 2200 | 2261 | |
| 2201 | 2262 | |
| 2202 | - }else{ |
|
| 2263 | + } else{ |
|
| 2203 | 2264 | $selectField .= $char; |
| 2204 | 2265 | } |
| 2205 | 2266 | |
@@ -2218,18 +2279,19 @@ discard block |
||
| 2218 | 2279 | if(strncasecmp($string, "DISTINCT ", 9) == 0) { |
| 2219 | 2280 | $string = substr($string, 9); |
| 2220 | 2281 | } |
| 2221 | - if (stripos($string, " as ") !== false) |
|
| 2222 | - //"as" used for an alias |
|
| 2282 | + if (stripos($string, " as ") !== false) { |
|
| 2283 | + //"as" used for an alias |
|
| 2223 | 2284 | return trim(substr($string, strripos($string, " as ") + 4)); |
| 2224 | - else if (strrpos($string, " ") != 0) |
|
| 2225 | - //Space used as a delimiter for an alias |
|
| 2285 | + } else if (strrpos($string, " ") != 0) { |
|
| 2286 | + //Space used as a delimiter for an alias |
|
| 2226 | 2287 | return trim(substr($string, strrpos($string, " "))); |
| 2227 | - else if (strpos($string, ".") !== false) |
|
| 2228 | - //No alias, but a table.field format was used |
|
| 2288 | + } else if (strpos($string, ".") !== false) { |
|
| 2289 | + //No alias, but a table.field format was used |
|
| 2229 | 2290 | return substr($string, strpos($string, ".") + 1); |
| 2230 | - else |
|
| 2231 | - //Give up and assume the whole thing is the field name |
|
| 2291 | + } else { |
|
| 2292 | + //Give up and assume the whole thing is the field name |
|
| 2232 | 2293 | return $string; |
| 2294 | + } |
|
| 2233 | 2295 | } |
| 2234 | 2296 | |
| 2235 | 2297 | /** |
@@ -2289,8 +2351,9 @@ discard block |
||
| 2289 | 2351 | $aliases[$tableName][] = $table; |
| 2290 | 2352 | |
| 2291 | 2353 | // build part of select for this table |
| 2292 | - if (is_array($cols[$beanID])) |
|
| 2293 | - foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
|
| 2354 | + if (is_array($cols[$beanID])) { |
|
| 2355 | + foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
|
| 2356 | + } |
|
| 2294 | 2357 | |
| 2295 | 2358 | // build part of where clause |
| 2296 | 2359 | if (is_array($whereClause[$beanID])){ |
@@ -2322,7 +2385,10 @@ discard block |
||
| 2322 | 2385 | $separator = ""; |
| 2323 | 2386 | $from = ''; $table_used_in_from = array(); |
| 2324 | 2387 | foreach ($relations as $table1 => $rightsidearray){ |
| 2325 | - if ($table_used_in_from[$table1]) continue; // table has been joined |
|
| 2388 | + if ($table_used_in_from[$table1]) { |
|
| 2389 | + continue; |
|
| 2390 | + } |
|
| 2391 | + // table has been joined |
|
| 2326 | 2392 | |
| 2327 | 2393 | $from .= $separator." ".$table1; |
| 2328 | 2394 | $table_used_in_from[$table1] = true; |
@@ -2333,7 +2399,9 @@ discard block |
||
| 2333 | 2399 | //choose first alias that does not match |
| 2334 | 2400 | // we are doing this because of self joins. |
| 2335 | 2401 | // in case of self joins, the same table will have many aliases. |
| 2336 | - if ($table2 != $table1) break; |
|
| 2402 | + if ($table2 != $table1) { |
|
| 2403 | + break; |
|
| 2404 | + } |
|
| 2337 | 2405 | } |
| 2338 | 2406 | |
| 2339 | 2407 | $col = $tablearray['foreingColumn']; |
@@ -2362,11 +2430,13 @@ discard block |
||
| 2362 | 2430 | $tablename = $bean->getTableName(); |
| 2363 | 2431 | $columns = array(); |
| 2364 | 2432 | // get column names |
| 2365 | - foreach ($fields as $fieldDef) |
|
| 2366 | - $columns[] = $fieldDef['name']; |
|
| 2433 | + foreach ($fields as $fieldDef) { |
|
| 2434 | + $columns[] = $fieldDef['name']; |
|
| 2435 | + } |
|
| 2367 | 2436 | |
| 2368 | - if (empty($columns)) |
|
| 2369 | - return ""; |
|
| 2437 | + if (empty($columns)) { |
|
| 2438 | + return ""; |
|
| 2439 | + } |
|
| 2370 | 2440 | |
| 2371 | 2441 | $columns = implode(",", $columns); |
| 2372 | 2442 | |
@@ -2386,16 +2456,21 @@ discard block |
||
| 2386 | 2456 | // we do not have change a lot of existing code |
| 2387 | 2457 | // and add dbtype where type is being used for some special |
| 2388 | 2458 | // purposes like referring to foreign table etc. |
| 2389 | - if(!empty($fieldDef['dbType'])) |
|
| 2390 | - return $fieldDef['dbType']; |
|
| 2391 | - if(!empty($fieldDef['dbtype'])) |
|
| 2392 | - return $fieldDef['dbtype']; |
|
| 2393 | - if (!empty($fieldDef['type'])) |
|
| 2394 | - return $fieldDef['type']; |
|
| 2395 | - if (!empty($fieldDef['Type'])) |
|
| 2396 | - return $fieldDef['Type']; |
|
| 2397 | - if (!empty($fieldDef['data_type'])) |
|
| 2398 | - return $fieldDef['data_type']; |
|
| 2459 | + if(!empty($fieldDef['dbType'])) { |
|
| 2460 | + return $fieldDef['dbType']; |
|
| 2461 | + } |
|
| 2462 | + if(!empty($fieldDef['dbtype'])) { |
|
| 2463 | + return $fieldDef['dbtype']; |
|
| 2464 | + } |
|
| 2465 | + if (!empty($fieldDef['type'])) { |
|
| 2466 | + return $fieldDef['type']; |
|
| 2467 | + } |
|
| 2468 | + if (!empty($fieldDef['Type'])) { |
|
| 2469 | + return $fieldDef['Type']; |
|
| 2470 | + } |
|
| 2471 | + if (!empty($fieldDef['data_type'])) { |
|
| 2472 | + return $fieldDef['data_type']; |
|
| 2473 | + } |
|
| 2399 | 2474 | |
| 2400 | 2475 | return null; |
| 2401 | 2476 | } |
@@ -2453,14 +2528,15 @@ discard block |
||
| 2453 | 2528 | 'clob', 'blob', 'text'))) { |
| 2454 | 2529 | $colType = "$colBaseType(${fieldDef['len']})"; |
| 2455 | 2530 | } elseif(($colBaseType == 'decimal' || $colBaseType == 'float')){ |
| 2456 | - if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) |
|
| 2457 | - if(strpos($fieldDef['len'],',') === false){ |
|
| 2531 | + if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) { |
|
| 2532 | + if(strpos($fieldDef['len'],',') === false){ |
|
| 2458 | 2533 | $colType = $colBaseType . "(".$fieldDef['len'].",".$fieldDef['precision'].")"; |
| 2459 | - }else{ |
|
| 2460 | - $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2461 | - } |
|
| 2462 | - else |
|
| 2534 | + } |
|
| 2535 | + } else{ |
|
| 2463 | 2536 | $colType = $colBaseType . "(".$fieldDef['len'].")"; |
| 2537 | + } else { |
|
| 2538 | + $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
| 2539 | + } |
|
| 2464 | 2540 | } |
| 2465 | 2541 | } else { |
| 2466 | 2542 | if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) { |
@@ -2474,19 +2550,18 @@ discard block |
||
| 2474 | 2550 | if (!empty($fieldDef['no_default'])) |
| 2475 | 2551 | { |
| 2476 | 2552 | // nothing to do |
| 2477 | - } |
|
| 2478 | - elseif (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) |
|
| 2553 | + } elseif (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) |
|
| 2479 | 2554 | { |
| 2480 | 2555 | $default = " DEFAULT ".$this->quoted($fieldDef['default']); |
| 2481 | - } |
|
| 2482 | - elseif (!isset($default) && $type == 'bool') |
|
| 2556 | + } elseif (!isset($default) && $type == 'bool') |
|
| 2483 | 2557 | { |
| 2484 | 2558 | $default = " DEFAULT 0 "; |
| 2485 | 2559 | } |
| 2486 | 2560 | |
| 2487 | 2561 | $auto_increment = ''; |
| 2488 | - if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) |
|
| 2489 | - $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
| 2562 | + if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) { |
|
| 2563 | + $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
| 2564 | + } |
|
| 2490 | 2565 | |
| 2491 | 2566 | $required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify |
| 2492 | 2567 | //Starting in 6.0, only ID and auto_increment fields will be NOT NULL in the DB. |
@@ -2500,8 +2575,9 @@ discard block |
||
| 2500 | 2575 | && !empty($fieldDef['required'])) { |
| 2501 | 2576 | $required = "NOT NULL"; |
| 2502 | 2577 | } |
| 2503 | - if ($ignoreRequired) |
|
| 2504 | - $required = ""; |
|
| 2578 | + if ($ignoreRequired) { |
|
| 2579 | + $required = ""; |
|
| 2580 | + } |
|
| 2505 | 2581 | |
| 2506 | 2582 | if ( $return_as_array ) { |
| 2507 | 2583 | return array( |
@@ -2537,8 +2613,7 @@ discard block |
||
| 2537 | 2613 | } |
| 2538 | 2614 | } |
| 2539 | 2615 | $columns = implode(",", $columns); |
| 2540 | - } |
|
| 2541 | - else { |
|
| 2616 | + } else { |
|
| 2542 | 2617 | $columns = $this->oneColumnSQLRep($fieldDefs,$ignoreRequired, $tablename); |
| 2543 | 2618 | } |
| 2544 | 2619 | |
@@ -2760,8 +2835,9 @@ discard block |
||
| 2760 | 2835 | */ |
| 2761 | 2836 | public function isFieldArray($defArray) |
| 2762 | 2837 | { |
| 2763 | - if ( !is_array($defArray) ) |
|
| 2764 | - return false; |
|
| 2838 | + if ( !is_array($defArray) ) { |
|
| 2839 | + return false; |
|
| 2840 | + } |
|
| 2765 | 2841 | |
| 2766 | 2842 | if ( isset($defArray['type']) ){ |
| 2767 | 2843 | // type key exists. May be an array of defs or a simple definition |
@@ -2872,11 +2948,9 @@ discard block |
||
| 2872 | 2948 | } else { |
| 2873 | 2949 | if (isset($properties['dbType'])) { |
| 2874 | 2950 | $field_type=$properties['dbType']; |
| 2875 | - } |
|
| 2876 | - else if(isset($properties['data_type'])) { |
|
| 2951 | + } else if(isset($properties['data_type'])) { |
|
| 2877 | 2952 | $field_type=$properties['data_type']; |
| 2878 | - } |
|
| 2879 | - else { |
|
| 2953 | + } else { |
|
| 2880 | 2954 | $field_type=$properties['dbtype']; |
| 2881 | 2955 | } |
| 2882 | 2956 | } |
@@ -2901,13 +2975,11 @@ discard block |
||
| 2901 | 2975 | if ($error >= 0.0000000001) { // Smaller than 10E-10 |
| 2902 | 2976 | $change = true; |
| 2903 | 2977 | } |
| 2904 | - } |
|
| 2905 | - else if ($this->isBooleanType($field_type)) { |
|
| 2978 | + } else if ($this->isBooleanType($field_type)) { |
|
| 2906 | 2979 | if ($this->_getBooleanValue($before_value) != $this->_getBooleanValue($after_value)) { |
| 2907 | 2980 | $change = true; |
| 2908 | 2981 | } |
| 2909 | - } |
|
| 2910 | - else { |
|
| 2982 | + } else { |
|
| 2911 | 2983 | $change = true; |
| 2912 | 2984 | } |
| 2913 | 2985 | if ($change) { |
@@ -3005,8 +3077,9 @@ discard block |
||
| 3005 | 3077 | protected function _getBooleanValue($val) |
| 3006 | 3078 | { |
| 3007 | 3079 | //need to put the === sign here otherwise true == 'non empty string' |
| 3008 | - if (empty($val) or $val==='off') |
|
| 3009 | - return false; |
|
| 3080 | + if (empty($val) or $val==='off') { |
|
| 3081 | + return false; |
|
| 3082 | + } |
|
| 3010 | 3083 | |
| 3011 | 3084 | return true; |
| 3012 | 3085 | } |
@@ -3032,8 +3105,9 @@ discard block |
||
| 3032 | 3105 | */ |
| 3033 | 3106 | protected function _emptyValue($val, $type) |
| 3034 | 3107 | { |
| 3035 | - if (empty($val)) |
|
| 3036 | - return true; |
|
| 3108 | + if (empty($val)) { |
|
| 3109 | + return true; |
|
| 3110 | + } |
|
| 3037 | 3111 | |
| 3038 | 3112 | if($this->emptyValue($type) == $val) { |
| 3039 | 3113 | return true; |
@@ -3050,10 +3124,12 @@ discard block |
||
| 3050 | 3124 | case 'short': |
| 3051 | 3125 | return ($val == 0); |
| 3052 | 3126 | case 'date': |
| 3053 | - if ($val == '0000-00-00') |
|
| 3054 | - return true; |
|
| 3055 | - if ($val == 'NULL') |
|
| 3056 | - return true; |
|
| 3127 | + if ($val == '0000-00-00') { |
|
| 3128 | + return true; |
|
| 3129 | + } |
|
| 3130 | + if ($val == 'NULL') { |
|
| 3131 | + return true; |
|
| 3132 | + } |
|
| 3057 | 3133 | return false; |
| 3058 | 3134 | } |
| 3059 | 3135 | |
@@ -3407,7 +3483,9 @@ discard block |
||
| 3407 | 3483 | */ |
| 3408 | 3484 | public function fetchByAssoc($result, $encode = true) |
| 3409 | 3485 | { |
| 3410 | - if (empty($result)) return false; |
|
| 3486 | + if (empty($result)) { |
|
| 3487 | + return false; |
|
| 3488 | + } |
|
| 3411 | 3489 | |
| 3412 | 3490 | if(is_int($encode) && func_num_args() == 3) { |
| 3413 | 3491 | // old API: $result, $rowNum, $encode |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * Return DB error message for the last query executed |
| 357 | - * @return string Last error message |
|
| 357 | + * @return boolean Last error message |
|
| 358 | 358 | */ |
| 359 | 359 | public function lastError() |
| 360 | 360 | { |
@@ -1580,7 +1580,7 @@ discard block |
||
| 1580 | 1580 | /** |
| 1581 | 1581 | * Frees out previous results |
| 1582 | 1582 | * |
| 1583 | - * @param resource|bool $result optional, pass if you want to free a single result instead of all results |
|
| 1583 | + * @param boolean $result optional, pass if you want to free a single result instead of all results |
|
| 1584 | 1584 | */ |
| 1585 | 1585 | protected function freeResult($result = false) |
| 1586 | 1586 | { |
@@ -2697,7 +2697,7 @@ discard block |
||
| 2697 | 2697 | * @param bool|string $ensureUnique Ensure the name is unique |
| 2698 | 2698 | * @param string $type Name type (table, column) |
| 2699 | 2699 | * @param bool $force Force new name |
| 2700 | - * @return string|array Valid column name trimmed to right length and with invalid characters removed |
|
| 2700 | + * @return string Valid column name trimmed to right length and with invalid characters removed |
|
| 2701 | 2701 | */ |
| 2702 | 2702 | public function getValidDBName($name, $ensureUnique = false, $type = 'column', $force = false) |
| 2703 | 2703 | { |
@@ -3158,7 +3158,7 @@ discard block |
||
| 3158 | 3158 | * @param int $count |
| 3159 | 3159 | * @param bool $dieOnError |
| 3160 | 3160 | * @param string $msg |
| 3161 | - * @return resource|bool query result |
|
| 3161 | + * @return resource query result |
|
| 3162 | 3162 | * @see DBManager::limitQuery() |
| 3163 | 3163 | */ |
| 3164 | 3164 | public function limitQuerySql($sql, $start, $count, $dieOnError=false, $msg='') |
@@ -3385,7 +3385,7 @@ discard block |
||
| 3385 | 3385 | * @param bool $dieOnError Die on error, passed to query() |
| 3386 | 3386 | * @param string $msg Error message, passed to query() |
| 3387 | 3387 | * @param bool $suppress Supress errors, passed to query() |
| 3388 | - * @return resource|bool result set or success/failure bool |
|
| 3388 | + * @return boolean result set or success/failure bool |
|
| 3389 | 3389 | */ |
| 3390 | 3390 | public function queryArray(array $sqls, $dieOnError = false, $msg = '', $suppress = false) |
| 3391 | 3391 | { |
@@ -3508,7 +3508,7 @@ discard block |
||
| 3508 | 3508 | * @abstract |
| 3509 | 3509 | * If everything is OK, return true. |
| 3510 | 3510 | * If something's wrong, return array of error code and parameters |
| 3511 | - * @return mixed |
|
| 3511 | + * @return boolean |
|
| 3512 | 3512 | */ |
| 3513 | 3513 | public function canInstall() |
| 3514 | 3514 | { |
@@ -3773,7 +3773,7 @@ discard block |
||
| 3773 | 3773 | * @param array $fieldDefs |
| 3774 | 3774 | * @param string $action |
| 3775 | 3775 | * @param bool $ignoreRequired Optional, true if we should ignor this being a required field |
| 3776 | - * @return string|array |
|
| 3776 | + * @return string |
|
| 3777 | 3777 | */ |
| 3778 | 3778 | abstract protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false); |
| 3779 | 3779 | |
@@ -96,368 +96,368 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | class MysqlManager extends DBManager |
| 98 | 98 | { |
| 99 | - /** |
|
| 100 | - * @see DBManager::$dbType |
|
| 101 | - */ |
|
| 102 | - public $dbType = 'mysql'; |
|
| 103 | - public $variant = 'mysql'; |
|
| 104 | - public $dbName = 'MySQL'; |
|
| 105 | - public $label = 'LBL_MYSQL'; |
|
| 106 | - |
|
| 107 | - protected $maxNameLengths = array( |
|
| 108 | - 'table' => 64, |
|
| 109 | - 'column' => 64, |
|
| 110 | - 'index' => 64, |
|
| 111 | - 'alias' => 256 |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - protected $type_map = array( |
|
| 115 | - 'int' => 'int', |
|
| 116 | - 'double' => 'double', |
|
| 117 | - 'float' => 'float', |
|
| 118 | - 'uint' => 'int unsigned', |
|
| 119 | - 'ulong' => 'bigint unsigned', |
|
| 120 | - 'long' => 'bigint', |
|
| 121 | - 'short' => 'smallint', |
|
| 122 | - 'varchar' => 'varchar', |
|
| 123 | - 'text' => 'text', |
|
| 124 | - 'longtext' => 'longtext', |
|
| 125 | - 'date' => 'date', |
|
| 126 | - 'enum' => 'varchar', |
|
| 127 | - 'relate' => 'varchar', |
|
| 128 | - 'multienum'=> 'text', |
|
| 129 | - 'html' => 'text', |
|
| 130 | - 'longhtml' => 'longtext', |
|
| 131 | - 'datetime' => 'datetime', |
|
| 132 | - 'datetimecombo' => 'datetime', |
|
| 133 | - 'time' => 'time', |
|
| 134 | - 'bool' => 'bool', |
|
| 135 | - 'tinyint' => 'tinyint', |
|
| 136 | - 'char' => 'char', |
|
| 137 | - 'blob' => 'blob', |
|
| 138 | - 'longblob' => 'longblob', |
|
| 139 | - 'currency' => 'decimal(26,6)', |
|
| 140 | - 'decimal' => 'decimal', |
|
| 141 | - 'decimal2' => 'decimal', |
|
| 142 | - 'id' => 'char(36)', |
|
| 143 | - 'url' => 'varchar', |
|
| 144 | - 'encrypt' => 'varchar', |
|
| 145 | - 'file' => 'varchar', |
|
| 146 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
| 147 | - |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - protected $capabilities = array( |
|
| 151 | - "affected_rows" => true, |
|
| 152 | - "select_rows" => true, |
|
| 153 | - "inline_keys" => true, |
|
| 154 | - "create_user" => true, |
|
| 155 | - "fulltext" => true, |
|
| 156 | - "collation" => true, |
|
| 157 | - "create_db" => true, |
|
| 158 | - "disable_keys" => true, |
|
| 159 | - ); |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Parses and runs queries |
|
| 163 | - * |
|
| 164 | - * @param string $sql SQL Statement to execute |
|
| 165 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 166 | - * @param string $msg Message to log if error occurs |
|
| 167 | - * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
| 168 | - * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
| 169 | - * @return resource result set |
|
| 170 | - */ |
|
| 171 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
| 172 | - { |
|
| 173 | - if(is_array($sql)) { |
|
| 174 | - return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - parent::countQuery($sql); |
|
| 178 | - $GLOBALS['log']->info('Query:' . $sql); |
|
| 179 | - $this->checkConnection(); |
|
| 180 | - $this->query_time = microtime(true); |
|
| 181 | - $this->lastsql = $sql; |
|
| 182 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
| 183 | - |
|
| 184 | - $this->query_time = microtime(true) - $this->query_time; |
|
| 185 | - $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - if($keepResult) |
|
| 189 | - $this->lastResult = $result; |
|
| 190 | - |
|
| 191 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
| 192 | - return $result; |
|
| 193 | - } |
|
| 99 | + /** |
|
| 100 | + * @see DBManager::$dbType |
|
| 101 | + */ |
|
| 102 | + public $dbType = 'mysql'; |
|
| 103 | + public $variant = 'mysql'; |
|
| 104 | + public $dbName = 'MySQL'; |
|
| 105 | + public $label = 'LBL_MYSQL'; |
|
| 106 | + |
|
| 107 | + protected $maxNameLengths = array( |
|
| 108 | + 'table' => 64, |
|
| 109 | + 'column' => 64, |
|
| 110 | + 'index' => 64, |
|
| 111 | + 'alias' => 256 |
|
| 112 | + ); |
|
| 113 | + |
|
| 114 | + protected $type_map = array( |
|
| 115 | + 'int' => 'int', |
|
| 116 | + 'double' => 'double', |
|
| 117 | + 'float' => 'float', |
|
| 118 | + 'uint' => 'int unsigned', |
|
| 119 | + 'ulong' => 'bigint unsigned', |
|
| 120 | + 'long' => 'bigint', |
|
| 121 | + 'short' => 'smallint', |
|
| 122 | + 'varchar' => 'varchar', |
|
| 123 | + 'text' => 'text', |
|
| 124 | + 'longtext' => 'longtext', |
|
| 125 | + 'date' => 'date', |
|
| 126 | + 'enum' => 'varchar', |
|
| 127 | + 'relate' => 'varchar', |
|
| 128 | + 'multienum'=> 'text', |
|
| 129 | + 'html' => 'text', |
|
| 130 | + 'longhtml' => 'longtext', |
|
| 131 | + 'datetime' => 'datetime', |
|
| 132 | + 'datetimecombo' => 'datetime', |
|
| 133 | + 'time' => 'time', |
|
| 134 | + 'bool' => 'bool', |
|
| 135 | + 'tinyint' => 'tinyint', |
|
| 136 | + 'char' => 'char', |
|
| 137 | + 'blob' => 'blob', |
|
| 138 | + 'longblob' => 'longblob', |
|
| 139 | + 'currency' => 'decimal(26,6)', |
|
| 140 | + 'decimal' => 'decimal', |
|
| 141 | + 'decimal2' => 'decimal', |
|
| 142 | + 'id' => 'char(36)', |
|
| 143 | + 'url' => 'varchar', |
|
| 144 | + 'encrypt' => 'varchar', |
|
| 145 | + 'file' => 'varchar', |
|
| 146 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
| 147 | + |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + protected $capabilities = array( |
|
| 151 | + "affected_rows" => true, |
|
| 152 | + "select_rows" => true, |
|
| 153 | + "inline_keys" => true, |
|
| 154 | + "create_user" => true, |
|
| 155 | + "fulltext" => true, |
|
| 156 | + "collation" => true, |
|
| 157 | + "create_db" => true, |
|
| 158 | + "disable_keys" => true, |
|
| 159 | + ); |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Parses and runs queries |
|
| 163 | + * |
|
| 164 | + * @param string $sql SQL Statement to execute |
|
| 165 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 166 | + * @param string $msg Message to log if error occurs |
|
| 167 | + * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
| 168 | + * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
| 169 | + * @return resource result set |
|
| 170 | + */ |
|
| 171 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
| 172 | + { |
|
| 173 | + if(is_array($sql)) { |
|
| 174 | + return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + parent::countQuery($sql); |
|
| 178 | + $GLOBALS['log']->info('Query:' . $sql); |
|
| 179 | + $this->checkConnection(); |
|
| 180 | + $this->query_time = microtime(true); |
|
| 181 | + $this->lastsql = $sql; |
|
| 182 | + $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
| 183 | + |
|
| 184 | + $this->query_time = microtime(true) - $this->query_time; |
|
| 185 | + $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + if($keepResult) |
|
| 189 | + $this->lastResult = $result; |
|
| 190 | + |
|
| 191 | + $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
| 192 | + return $result; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | 196 | * Returns the number of rows affected by the last query |
| 197 | 197 | * @param $result |
| 198 | 198 | * @return int |
| 199 | 199 | */ |
| 200 | - public function getAffectedRowCount($result) |
|
| 201 | - { |
|
| 202 | - return mysql_affected_rows($this->getDatabase()); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Returns the number of rows returned by the result |
|
| 207 | - * |
|
| 208 | - * This function can't be reliably implemented on most DB, do not use it. |
|
| 209 | - * @abstract |
|
| 210 | - * @deprecated |
|
| 211 | - * @param resource $result |
|
| 212 | - * @return int |
|
| 213 | - */ |
|
| 214 | - public function getRowCount($result) |
|
| 215 | - { |
|
| 216 | - return mysql_num_rows($result); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Disconnects from the database |
|
| 221 | - * |
|
| 222 | - * Also handles any cleanup needed |
|
| 223 | - */ |
|
| 224 | - public function disconnect() |
|
| 225 | - { |
|
| 226 | - $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
| 227 | - if(!empty($this->database)){ |
|
| 228 | - $this->freeResult(); |
|
| 229 | - mysql_close($this->database); |
|
| 230 | - $this->database = null; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @see DBManager::freeDbResult() |
|
| 236 | - */ |
|
| 237 | - protected function freeDbResult($dbResult) |
|
| 238 | - { |
|
| 239 | - if(!empty($dbResult)) |
|
| 240 | - mysql_free_result($dbResult); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @abstract |
|
| 246 | - * Check if query has LIMIT clause |
|
| 247 | - * Relevant for now only for Mysql |
|
| 248 | - * @param string $sql |
|
| 249 | - * @return bool |
|
| 250 | - */ |
|
| 251 | - protected function hasLimit($sql) |
|
| 252 | - { |
|
| 253 | - return stripos($sql, " limit ") !== false; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @see DBManager::limitQuery() |
|
| 258 | - */ |
|
| 259 | - public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
| 260 | - { |
|
| 200 | + public function getAffectedRowCount($result) |
|
| 201 | + { |
|
| 202 | + return mysql_affected_rows($this->getDatabase()); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Returns the number of rows returned by the result |
|
| 207 | + * |
|
| 208 | + * This function can't be reliably implemented on most DB, do not use it. |
|
| 209 | + * @abstract |
|
| 210 | + * @deprecated |
|
| 211 | + * @param resource $result |
|
| 212 | + * @return int |
|
| 213 | + */ |
|
| 214 | + public function getRowCount($result) |
|
| 215 | + { |
|
| 216 | + return mysql_num_rows($result); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Disconnects from the database |
|
| 221 | + * |
|
| 222 | + * Also handles any cleanup needed |
|
| 223 | + */ |
|
| 224 | + public function disconnect() |
|
| 225 | + { |
|
| 226 | + $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
| 227 | + if(!empty($this->database)){ |
|
| 228 | + $this->freeResult(); |
|
| 229 | + mysql_close($this->database); |
|
| 230 | + $this->database = null; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @see DBManager::freeDbResult() |
|
| 236 | + */ |
|
| 237 | + protected function freeDbResult($dbResult) |
|
| 238 | + { |
|
| 239 | + if(!empty($dbResult)) |
|
| 240 | + mysql_free_result($dbResult); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @abstract |
|
| 246 | + * Check if query has LIMIT clause |
|
| 247 | + * Relevant for now only for Mysql |
|
| 248 | + * @param string $sql |
|
| 249 | + * @return bool |
|
| 250 | + */ |
|
| 251 | + protected function hasLimit($sql) |
|
| 252 | + { |
|
| 253 | + return stripos($sql, " limit ") !== false; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @see DBManager::limitQuery() |
|
| 258 | + */ |
|
| 259 | + public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
| 260 | + { |
|
| 261 | 261 | $start = (int)$start; |
| 262 | 262 | $count = (int)$count; |
| 263 | - if ($start < 0) |
|
| 264 | - $start = 0; |
|
| 265 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
| 266 | - |
|
| 267 | - $sql = "$sql LIMIT $start,$count"; |
|
| 268 | - $this->lastsql = $sql; |
|
| 269 | - |
|
| 270 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
| 271 | - $this->checkQuery($sql); |
|
| 272 | - } |
|
| 273 | - if(!$execute) { |
|
| 274 | - return $sql; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return $this->query($sql, $dieOnError, $msg); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @see DBManager::checkQuery() |
|
| 283 | - */ |
|
| 284 | - protected function checkQuery($sql, $object_name = false) |
|
| 285 | - { |
|
| 286 | - $result = $this->query('EXPLAIN ' . $sql); |
|
| 287 | - $badQuery = array(); |
|
| 288 | - while ($row = $this->fetchByAssoc($result)) { |
|
| 289 | - if (empty($row['table'])) |
|
| 290 | - continue; |
|
| 291 | - $badQuery[$row['table']] = ''; |
|
| 292 | - if (strtoupper($row['type']) == 'ALL') |
|
| 293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 294 | - if (empty($row['key'])) |
|
| 295 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 296 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
| 297 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 298 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
| 299 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - if ( empty($badQuery) ) |
|
| 303 | - return true; |
|
| 304 | - |
|
| 305 | - foreach($badQuery as $table=>$data ){ |
|
| 306 | - if(!empty($data)){ |
|
| 307 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
| 308 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
| 309 | - $GLOBALS['log']->fatal($sql); |
|
| 310 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
| 311 | - } |
|
| 312 | - else{ |
|
| 313 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - return false; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * @see DBManager::get_columns() |
|
| 323 | - */ |
|
| 324 | - public function get_columns($tablename) |
|
| 325 | - { |
|
| 326 | - //find all unique indexes and primary keys. |
|
| 327 | - $result = $this->query("DESCRIBE $tablename"); |
|
| 328 | - |
|
| 329 | - $columns = array(); |
|
| 330 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 331 | - $name = strtolower($row['Field']); |
|
| 332 | - $columns[$name]['name']=$name; |
|
| 333 | - $matches = array(); |
|
| 334 | - preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
| 335 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
| 336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
| 339 | - $columns[$name]['auto_increment'] = '1'; |
|
| 340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 341 | - $columns[$name]['required'] = 'true'; |
|
| 342 | - if (!empty($row['Default']) ) |
|
| 343 | - $columns[$name]['default'] = $row['Default']; |
|
| 344 | - } |
|
| 345 | - return $columns; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * @see DBManager::getFieldsArray() |
|
| 350 | - */ |
|
| 351 | - public function getFieldsArray($result, $make_lower_case=false) |
|
| 352 | - { |
|
| 353 | - $field_array = array(); |
|
| 354 | - |
|
| 355 | - if(empty($result)) |
|
| 356 | - return 0; |
|
| 357 | - |
|
| 358 | - $fields = mysql_num_fields($result); |
|
| 359 | - for ($i=0; $i < $fields; $i++) { |
|
| 360 | - $meta = mysql_fetch_field($result, $i); |
|
| 361 | - if (!$meta) |
|
| 362 | - return array(); |
|
| 363 | - |
|
| 364 | - if($make_lower_case == true) |
|
| 365 | - $meta->name = strtolower($meta->name); |
|
| 366 | - |
|
| 367 | - $field_array[] = $meta->name; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return $field_array; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * @see DBManager::fetchRow() |
|
| 375 | - */ |
|
| 376 | - public function fetchRow($result) |
|
| 377 | - { |
|
| 378 | - if (empty($result)) return false; |
|
| 379 | - |
|
| 380 | - return mysql_fetch_assoc($result); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @see DBManager::getTablesArray() |
|
| 385 | - */ |
|
| 386 | - public function getTablesArray() |
|
| 387 | - { |
|
| 388 | - $this->log->debug('Fetching table list'); |
|
| 389 | - |
|
| 390 | - if ($this->getDatabase()) { |
|
| 391 | - $tables = array(); |
|
| 392 | - $r = $this->query('SHOW TABLES'); |
|
| 393 | - if (!empty($r)) { |
|
| 394 | - while ($a = $this->fetchByAssoc($r)) { |
|
| 395 | - $row = array_values($a); |
|
| 396 | - $tables[]=$row[0]; |
|
| 397 | - } |
|
| 398 | - return $tables; |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - return false; // no database available |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @see DBManager::version() |
|
| 407 | - */ |
|
| 408 | - public function version() |
|
| 409 | - { |
|
| 410 | - return $this->getOne("SELECT version() version"); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * @see DBManager::tableExists() |
|
| 415 | - */ |
|
| 416 | - public function tableExists($tableName) |
|
| 417 | - { |
|
| 418 | - $this->log->info("tableExists: $tableName"); |
|
| 419 | - |
|
| 420 | - if ($this->getDatabase()) { |
|
| 421 | - $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
| 422 | - if(empty($result)) return false; |
|
| 423 | - $row = $this->fetchByAssoc($result); |
|
| 424 | - return !empty($row); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return false; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Get tables like expression |
|
| 432 | - * @param $like string |
|
| 433 | - * @return array |
|
| 434 | - */ |
|
| 435 | - public function tablesLike($like) |
|
| 436 | - { |
|
| 437 | - if ($this->getDatabase()) { |
|
| 438 | - $tables = array(); |
|
| 439 | - $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
| 440 | - if (!empty($r)) { |
|
| 441 | - while ($a = $this->fetchByAssoc($r)) { |
|
| 442 | - $row = array_values($a); |
|
| 443 | - $tables[]=$row[0]; |
|
| 444 | - } |
|
| 445 | - return $tables; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - return false; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @see DBManager::quote() |
|
| 453 | - */ |
|
| 454 | - public function quote($string) |
|
| 455 | - { |
|
| 456 | - if(is_array($string)) { |
|
| 457 | - return $this->arrayQuote($string); |
|
| 458 | - } |
|
| 459 | - return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
| 460 | - } |
|
| 263 | + if ($start < 0) |
|
| 264 | + $start = 0; |
|
| 265 | + $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
| 266 | + |
|
| 267 | + $sql = "$sql LIMIT $start,$count"; |
|
| 268 | + $this->lastsql = $sql; |
|
| 269 | + |
|
| 270 | + if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
| 271 | + $this->checkQuery($sql); |
|
| 272 | + } |
|
| 273 | + if(!$execute) { |
|
| 274 | + return $sql; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return $this->query($sql, $dieOnError, $msg); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @see DBManager::checkQuery() |
|
| 283 | + */ |
|
| 284 | + protected function checkQuery($sql, $object_name = false) |
|
| 285 | + { |
|
| 286 | + $result = $this->query('EXPLAIN ' . $sql); |
|
| 287 | + $badQuery = array(); |
|
| 288 | + while ($row = $this->fetchByAssoc($result)) { |
|
| 289 | + if (empty($row['table'])) |
|
| 290 | + continue; |
|
| 291 | + $badQuery[$row['table']] = ''; |
|
| 292 | + if (strtoupper($row['type']) == 'ALL') |
|
| 293 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 294 | + if (empty($row['key'])) |
|
| 295 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 296 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
| 297 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 298 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
| 299 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + if ( empty($badQuery) ) |
|
| 303 | + return true; |
|
| 304 | + |
|
| 305 | + foreach($badQuery as $table=>$data ){ |
|
| 306 | + if(!empty($data)){ |
|
| 307 | + $warning = ' Table:' . $table . ' Data:' . $data; |
|
| 308 | + if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
| 309 | + $GLOBALS['log']->fatal($sql); |
|
| 310 | + $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
| 311 | + } |
|
| 312 | + else{ |
|
| 313 | + $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + return false; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * @see DBManager::get_columns() |
|
| 323 | + */ |
|
| 324 | + public function get_columns($tablename) |
|
| 325 | + { |
|
| 326 | + //find all unique indexes and primary keys. |
|
| 327 | + $result = $this->query("DESCRIBE $tablename"); |
|
| 328 | + |
|
| 329 | + $columns = array(); |
|
| 330 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 331 | + $name = strtolower($row['Field']); |
|
| 332 | + $columns[$name]['name']=$name; |
|
| 333 | + $matches = array(); |
|
| 334 | + preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
| 335 | + $columns[$name]['type']=strtolower($matches[1][0]); |
|
| 336 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 337 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 338 | + if ( stristr($row['Extra'],'auto_increment') ) |
|
| 339 | + $columns[$name]['auto_increment'] = '1'; |
|
| 340 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 341 | + $columns[$name]['required'] = 'true'; |
|
| 342 | + if (!empty($row['Default']) ) |
|
| 343 | + $columns[$name]['default'] = $row['Default']; |
|
| 344 | + } |
|
| 345 | + return $columns; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * @see DBManager::getFieldsArray() |
|
| 350 | + */ |
|
| 351 | + public function getFieldsArray($result, $make_lower_case=false) |
|
| 352 | + { |
|
| 353 | + $field_array = array(); |
|
| 354 | + |
|
| 355 | + if(empty($result)) |
|
| 356 | + return 0; |
|
| 357 | + |
|
| 358 | + $fields = mysql_num_fields($result); |
|
| 359 | + for ($i=0; $i < $fields; $i++) { |
|
| 360 | + $meta = mysql_fetch_field($result, $i); |
|
| 361 | + if (!$meta) |
|
| 362 | + return array(); |
|
| 363 | + |
|
| 364 | + if($make_lower_case == true) |
|
| 365 | + $meta->name = strtolower($meta->name); |
|
| 366 | + |
|
| 367 | + $field_array[] = $meta->name; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return $field_array; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @see DBManager::fetchRow() |
|
| 375 | + */ |
|
| 376 | + public function fetchRow($result) |
|
| 377 | + { |
|
| 378 | + if (empty($result)) return false; |
|
| 379 | + |
|
| 380 | + return mysql_fetch_assoc($result); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @see DBManager::getTablesArray() |
|
| 385 | + */ |
|
| 386 | + public function getTablesArray() |
|
| 387 | + { |
|
| 388 | + $this->log->debug('Fetching table list'); |
|
| 389 | + |
|
| 390 | + if ($this->getDatabase()) { |
|
| 391 | + $tables = array(); |
|
| 392 | + $r = $this->query('SHOW TABLES'); |
|
| 393 | + if (!empty($r)) { |
|
| 394 | + while ($a = $this->fetchByAssoc($r)) { |
|
| 395 | + $row = array_values($a); |
|
| 396 | + $tables[]=$row[0]; |
|
| 397 | + } |
|
| 398 | + return $tables; |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + return false; // no database available |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @see DBManager::version() |
|
| 407 | + */ |
|
| 408 | + public function version() |
|
| 409 | + { |
|
| 410 | + return $this->getOne("SELECT version() version"); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * @see DBManager::tableExists() |
|
| 415 | + */ |
|
| 416 | + public function tableExists($tableName) |
|
| 417 | + { |
|
| 418 | + $this->log->info("tableExists: $tableName"); |
|
| 419 | + |
|
| 420 | + if ($this->getDatabase()) { |
|
| 421 | + $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
| 422 | + if(empty($result)) return false; |
|
| 423 | + $row = $this->fetchByAssoc($result); |
|
| 424 | + return !empty($row); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return false; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Get tables like expression |
|
| 432 | + * @param $like string |
|
| 433 | + * @return array |
|
| 434 | + */ |
|
| 435 | + public function tablesLike($like) |
|
| 436 | + { |
|
| 437 | + if ($this->getDatabase()) { |
|
| 438 | + $tables = array(); |
|
| 439 | + $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
| 440 | + if (!empty($r)) { |
|
| 441 | + while ($a = $this->fetchByAssoc($r)) { |
|
| 442 | + $row = array_values($a); |
|
| 443 | + $tables[]=$row[0]; |
|
| 444 | + } |
|
| 445 | + return $tables; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + return false; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @see DBManager::quote() |
|
| 453 | + */ |
|
| 454 | + public function quote($string) |
|
| 455 | + { |
|
| 456 | + if(is_array($string)) { |
|
| 457 | + return $this->arrayQuote($string); |
|
| 458 | + } |
|
| 459 | + return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
| 460 | + } |
|
| 461 | 461 | |
| 462 | 462 | /** |
| 463 | 463 | * @see DBManager::quoteIdentifier() |
@@ -467,272 +467,272 @@ discard block |
||
| 467 | 467 | return '`'.$string.'`'; |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - /** |
|
| 471 | - * @see DBManager::connect() |
|
| 472 | - */ |
|
| 473 | - public function connect(array $configOptions = null, $dieOnError = false) |
|
| 474 | - { |
|
| 475 | - global $sugar_config; |
|
| 476 | - |
|
| 477 | - if(is_null($configOptions)) |
|
| 478 | - $configOptions = $sugar_config['dbconfig']; |
|
| 479 | - |
|
| 480 | - if ($this->getOption('persistent')) { |
|
| 481 | - $this->database = @mysql_pconnect( |
|
| 482 | - $configOptions['db_host_name'], |
|
| 483 | - $configOptions['db_user_name'], |
|
| 484 | - $configOptions['db_password'] |
|
| 485 | - ); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - if (!$this->database) { |
|
| 489 | - $this->database = mysql_connect( |
|
| 490 | - $configOptions['db_host_name'], |
|
| 491 | - $configOptions['db_user_name'], |
|
| 492 | - $configOptions['db_password'] |
|
| 493 | - ); |
|
| 494 | - if(empty($this->database)) { |
|
| 495 | - $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
| 496 | - if($dieOnError) { |
|
| 497 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 498 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 499 | - } else { |
|
| 500 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 501 | - } |
|
| 502 | - } else { |
|
| 503 | - return false; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - // Do not pass connection information because we have not connected yet |
|
| 507 | - if($this->database && $this->getOption('persistent')){ |
|
| 508 | - $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
| 509 | - . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
| 510 | - . "in your config.php file</b>"; |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 514 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
| 515 | - if($dieOnError) { |
|
| 516 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 517 | - } else { |
|
| 518 | - return false; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - // cn: using direct calls to prevent this from spamming the Logs |
|
| 523 | - mysql_query("SET CHARACTER SET utf8", $this->database); |
|
| 524 | - $names = "SET NAMES 'utf8'"; |
|
| 525 | - $collation = $this->getOption('collation'); |
|
| 526 | - if(!empty($collation)) { |
|
| 527 | - $names .= " COLLATE '$collation'"; |
|
| 528 | - } |
|
| 529 | - mysql_query($names, $this->database); |
|
| 530 | - |
|
| 531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 532 | - $GLOBALS['log']->info("connected to db"); |
|
| 533 | - $this->connectOptions = $configOptions; |
|
| 534 | - |
|
| 535 | - $GLOBALS['log']->info("Connect:".$this->database); |
|
| 536 | - return true; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * @see DBManager::repairTableParams() |
|
| 541 | - * |
|
| 542 | - * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
| 543 | - * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
| 544 | - */ |
|
| 545 | - public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 546 | - { |
|
| 547 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
| 548 | - |
|
| 549 | - if ( $sql == '' ) |
|
| 550 | - return ''; |
|
| 551 | - |
|
| 552 | - if ( stristr($sql,'create table') ) |
|
| 553 | - { |
|
| 554 | - if ($execute) { |
|
| 555 | - $msg = "Error creating table: ".$tablename. ":"; |
|
| 556 | - $this->query($sql,true,$msg); |
|
| 557 | - } |
|
| 558 | - return $sql; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - // first, parse out all the comments |
|
| 562 | - $match = array(); |
|
| 563 | - preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
| 564 | - $commentBlocks = $match[0]; |
|
| 565 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
| 566 | - |
|
| 567 | - // now, we should only have alter table statements |
|
| 568 | - // let's replace the 'alter table name' part with a comma |
|
| 569 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
| 570 | - |
|
| 571 | - // re-add it at the beginning |
|
| 572 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
| 573 | - $sql = str_replace(";","",$sql); |
|
| 574 | - $sql = str_replace("\n","",$sql); |
|
| 575 | - $sql = "ALTER TABLE $tablename $sql"; |
|
| 576 | - |
|
| 577 | - if ( $execute ) |
|
| 578 | - $this->query($sql,'Error with MySQL repair table'); |
|
| 579 | - |
|
| 580 | - // and re-add the comments at the beginning |
|
| 581 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
| 582 | - |
|
| 583 | - return $sql; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * @see DBManager::convert() |
|
| 588 | - */ |
|
| 589 | - public function convert($string, $type, array $additional_parameters = array()) |
|
| 590 | - { |
|
| 591 | - $all_parameters = $additional_parameters; |
|
| 592 | - if(is_array($string)) { |
|
| 593 | - $all_parameters = array_merge($string, $all_parameters); |
|
| 594 | - } elseif (!is_null($string)) { |
|
| 595 | - array_unshift($all_parameters, $string); |
|
| 596 | - } |
|
| 597 | - $all_strings = implode(',', $all_parameters); |
|
| 598 | - |
|
| 599 | - switch (strtolower($type)) { |
|
| 600 | - case 'today': |
|
| 601 | - return "CURDATE()"; |
|
| 602 | - case 'left': |
|
| 603 | - return "LEFT($all_strings)"; |
|
| 604 | - case 'date_format': |
|
| 605 | - if(empty($additional_parameters)) { |
|
| 606 | - return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
| 607 | - } else { |
|
| 608 | - $format = $additional_parameters[0]; |
|
| 609 | - if($format[0] != "'") { |
|
| 610 | - $format = $this->quoted($format); |
|
| 611 | - } |
|
| 612 | - return "DATE_FORMAT($string,$format)"; |
|
| 613 | - } |
|
| 614 | - case 'ifnull': |
|
| 615 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 616 | - $all_strings .= ",''"; |
|
| 617 | - } |
|
| 618 | - return "IFNULL($all_strings)"; |
|
| 619 | - case 'concat': |
|
| 620 | - return "CONCAT($all_strings)"; |
|
| 621 | - case 'quarter': |
|
| 622 | - return "QUARTER($string)"; |
|
| 623 | - case "length": |
|
| 624 | - return "LENGTH($string)"; |
|
| 625 | - case 'month': |
|
| 626 | - return "MONTH($string)"; |
|
| 627 | - case 'add_date': |
|
| 628 | - return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
| 629 | - case 'add_time': |
|
| 630 | - return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
| 470 | + /** |
|
| 471 | + * @see DBManager::connect() |
|
| 472 | + */ |
|
| 473 | + public function connect(array $configOptions = null, $dieOnError = false) |
|
| 474 | + { |
|
| 475 | + global $sugar_config; |
|
| 476 | + |
|
| 477 | + if(is_null($configOptions)) |
|
| 478 | + $configOptions = $sugar_config['dbconfig']; |
|
| 479 | + |
|
| 480 | + if ($this->getOption('persistent')) { |
|
| 481 | + $this->database = @mysql_pconnect( |
|
| 482 | + $configOptions['db_host_name'], |
|
| 483 | + $configOptions['db_user_name'], |
|
| 484 | + $configOptions['db_password'] |
|
| 485 | + ); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + if (!$this->database) { |
|
| 489 | + $this->database = mysql_connect( |
|
| 490 | + $configOptions['db_host_name'], |
|
| 491 | + $configOptions['db_user_name'], |
|
| 492 | + $configOptions['db_password'] |
|
| 493 | + ); |
|
| 494 | + if(empty($this->database)) { |
|
| 495 | + $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
| 496 | + if($dieOnError) { |
|
| 497 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 498 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 499 | + } else { |
|
| 500 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 501 | + } |
|
| 502 | + } else { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + // Do not pass connection information because we have not connected yet |
|
| 507 | + if($this->database && $this->getOption('persistent')){ |
|
| 508 | + $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
| 509 | + . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
| 510 | + . "in your config.php file</b>"; |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 514 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
| 515 | + if($dieOnError) { |
|
| 516 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 517 | + } else { |
|
| 518 | + return false; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + // cn: using direct calls to prevent this from spamming the Logs |
|
| 523 | + mysql_query("SET CHARACTER SET utf8", $this->database); |
|
| 524 | + $names = "SET NAMES 'utf8'"; |
|
| 525 | + $collation = $this->getOption('collation'); |
|
| 526 | + if(!empty($collation)) { |
|
| 527 | + $names .= " COLLATE '$collation'"; |
|
| 528 | + } |
|
| 529 | + mysql_query($names, $this->database); |
|
| 530 | + |
|
| 531 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 532 | + $GLOBALS['log']->info("connected to db"); |
|
| 533 | + $this->connectOptions = $configOptions; |
|
| 534 | + |
|
| 535 | + $GLOBALS['log']->info("Connect:".$this->database); |
|
| 536 | + return true; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * @see DBManager::repairTableParams() |
|
| 541 | + * |
|
| 542 | + * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
| 543 | + * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
| 544 | + */ |
|
| 545 | + public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
| 546 | + { |
|
| 547 | + $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
| 548 | + |
|
| 549 | + if ( $sql == '' ) |
|
| 550 | + return ''; |
|
| 551 | + |
|
| 552 | + if ( stristr($sql,'create table') ) |
|
| 553 | + { |
|
| 554 | + if ($execute) { |
|
| 555 | + $msg = "Error creating table: ".$tablename. ":"; |
|
| 556 | + $this->query($sql,true,$msg); |
|
| 557 | + } |
|
| 558 | + return $sql; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + // first, parse out all the comments |
|
| 562 | + $match = array(); |
|
| 563 | + preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
| 564 | + $commentBlocks = $match[0]; |
|
| 565 | + $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
| 566 | + |
|
| 567 | + // now, we should only have alter table statements |
|
| 568 | + // let's replace the 'alter table name' part with a comma |
|
| 569 | + $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
| 570 | + |
|
| 571 | + // re-add it at the beginning |
|
| 572 | + $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
| 573 | + $sql = str_replace(";","",$sql); |
|
| 574 | + $sql = str_replace("\n","",$sql); |
|
| 575 | + $sql = "ALTER TABLE $tablename $sql"; |
|
| 576 | + |
|
| 577 | + if ( $execute ) |
|
| 578 | + $this->query($sql,'Error with MySQL repair table'); |
|
| 579 | + |
|
| 580 | + // and re-add the comments at the beginning |
|
| 581 | + $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
| 582 | + |
|
| 583 | + return $sql; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * @see DBManager::convert() |
|
| 588 | + */ |
|
| 589 | + public function convert($string, $type, array $additional_parameters = array()) |
|
| 590 | + { |
|
| 591 | + $all_parameters = $additional_parameters; |
|
| 592 | + if(is_array($string)) { |
|
| 593 | + $all_parameters = array_merge($string, $all_parameters); |
|
| 594 | + } elseif (!is_null($string)) { |
|
| 595 | + array_unshift($all_parameters, $string); |
|
| 596 | + } |
|
| 597 | + $all_strings = implode(',', $all_parameters); |
|
| 598 | + |
|
| 599 | + switch (strtolower($type)) { |
|
| 600 | + case 'today': |
|
| 601 | + return "CURDATE()"; |
|
| 602 | + case 'left': |
|
| 603 | + return "LEFT($all_strings)"; |
|
| 604 | + case 'date_format': |
|
| 605 | + if(empty($additional_parameters)) { |
|
| 606 | + return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
| 607 | + } else { |
|
| 608 | + $format = $additional_parameters[0]; |
|
| 609 | + if($format[0] != "'") { |
|
| 610 | + $format = $this->quoted($format); |
|
| 611 | + } |
|
| 612 | + return "DATE_FORMAT($string,$format)"; |
|
| 613 | + } |
|
| 614 | + case 'ifnull': |
|
| 615 | + if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 616 | + $all_strings .= ",''"; |
|
| 617 | + } |
|
| 618 | + return "IFNULL($all_strings)"; |
|
| 619 | + case 'concat': |
|
| 620 | + return "CONCAT($all_strings)"; |
|
| 621 | + case 'quarter': |
|
| 622 | + return "QUARTER($string)"; |
|
| 623 | + case "length": |
|
| 624 | + return "LENGTH($string)"; |
|
| 625 | + case 'month': |
|
| 626 | + return "MONTH($string)"; |
|
| 627 | + case 'add_date': |
|
| 628 | + return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
| 629 | + case 'add_time': |
|
| 630 | + return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
| 631 | 631 | case 'add_tz_offset' : |
| 632 | 632 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
| 633 | 633 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
| 634 | 634 | return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
| 635 | 635 | case 'avg': |
| 636 | 636 | return "avg($string)"; |
| 637 | - } |
|
| 638 | - |
|
| 639 | - return $string; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * (non-PHPdoc) |
|
| 644 | - * @see DBManager::fromConvert() |
|
| 645 | - */ |
|
| 646 | - public function fromConvert($string, $type) |
|
| 647 | - { |
|
| 648 | - return $string; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Returns the name of the engine to use or null if we are to use the default |
|
| 653 | - * |
|
| 654 | - * @param object $bean SugarBean instance |
|
| 655 | - * @return string |
|
| 656 | - */ |
|
| 657 | - protected function getEngine($bean) |
|
| 658 | - { |
|
| 659 | - global $dictionary; |
|
| 660 | - $engine = null; |
|
| 661 | - if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
| 662 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 663 | - } |
|
| 664 | - return $engine; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Returns true if the engine given is enabled in the backend |
|
| 669 | - * |
|
| 670 | - * @param string $engine |
|
| 671 | - * @return bool |
|
| 672 | - */ |
|
| 673 | - protected function isEngineEnabled($engine) |
|
| 674 | - { |
|
| 675 | - if(!is_string($engine)) return false; |
|
| 676 | - |
|
| 677 | - $engine = strtoupper($engine); |
|
| 678 | - |
|
| 679 | - $r = $this->query("SHOW ENGINES"); |
|
| 680 | - |
|
| 681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
| 682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
| 683 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
| 684 | - |
|
| 685 | - return false; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * @see DBManager::createTableSQL() |
|
| 690 | - */ |
|
| 691 | - public function createTableSQL(SugarBean $bean) |
|
| 692 | - { |
|
| 693 | - $tablename = $bean->getTableName(); |
|
| 694 | - $fieldDefs = $bean->getFieldDefinitions(); |
|
| 695 | - $indices = $bean->getIndices(); |
|
| 696 | - $engine = $this->getEngine($bean); |
|
| 697 | - return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Generates sql for create table statement for a bean. |
|
| 702 | - * |
|
| 703 | - * @param string $tablename |
|
| 704 | - * @param array $fieldDefs |
|
| 705 | - * @param array $indices |
|
| 706 | - * @param string $engine optional, MySQL engine to use |
|
| 707 | - * @return string SQL Create Table statement |
|
| 708 | - */ |
|
| 709 | - public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
| 710 | - { |
|
| 711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 712 | - $engine = $fieldDefs['engine']; |
|
| 713 | - if ( !$this->isEngineEnabled($engine) ) |
|
| 714 | - $engine = ''; |
|
| 715 | - |
|
| 716 | - $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
| 717 | - if (empty($columns)) |
|
| 718 | - return false; |
|
| 719 | - |
|
| 720 | - $keys = $this->keysSQL($indices); |
|
| 721 | - if (!empty($keys)) |
|
| 722 | - $keys = ",$keys"; |
|
| 723 | - |
|
| 724 | - // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
| 725 | - $collation = $this->getOption('collation'); |
|
| 726 | - if(empty($collation)) { |
|
| 727 | - $collation = 'utf8_general_ci'; |
|
| 728 | - } |
|
| 729 | - $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
| 730 | - |
|
| 731 | - if (!empty($engine)) |
|
| 732 | - $sql.= " ENGINE=$engine"; |
|
| 733 | - |
|
| 734 | - return $sql; |
|
| 735 | - } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + return $string; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * (non-PHPdoc) |
|
| 644 | + * @see DBManager::fromConvert() |
|
| 645 | + */ |
|
| 646 | + public function fromConvert($string, $type) |
|
| 647 | + { |
|
| 648 | + return $string; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Returns the name of the engine to use or null if we are to use the default |
|
| 653 | + * |
|
| 654 | + * @param object $bean SugarBean instance |
|
| 655 | + * @return string |
|
| 656 | + */ |
|
| 657 | + protected function getEngine($bean) |
|
| 658 | + { |
|
| 659 | + global $dictionary; |
|
| 660 | + $engine = null; |
|
| 661 | + if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
| 662 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
| 663 | + } |
|
| 664 | + return $engine; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Returns true if the engine given is enabled in the backend |
|
| 669 | + * |
|
| 670 | + * @param string $engine |
|
| 671 | + * @return bool |
|
| 672 | + */ |
|
| 673 | + protected function isEngineEnabled($engine) |
|
| 674 | + { |
|
| 675 | + if(!is_string($engine)) return false; |
|
| 676 | + |
|
| 677 | + $engine = strtoupper($engine); |
|
| 678 | + |
|
| 679 | + $r = $this->query("SHOW ENGINES"); |
|
| 680 | + |
|
| 681 | + while ( $row = $this->fetchByAssoc($r) ) |
|
| 682 | + if ( strtoupper($row['Engine']) == $engine ) |
|
| 683 | + return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
| 684 | + |
|
| 685 | + return false; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * @see DBManager::createTableSQL() |
|
| 690 | + */ |
|
| 691 | + public function createTableSQL(SugarBean $bean) |
|
| 692 | + { |
|
| 693 | + $tablename = $bean->getTableName(); |
|
| 694 | + $fieldDefs = $bean->getFieldDefinitions(); |
|
| 695 | + $indices = $bean->getIndices(); |
|
| 696 | + $engine = $this->getEngine($bean); |
|
| 697 | + return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Generates sql for create table statement for a bean. |
|
| 702 | + * |
|
| 703 | + * @param string $tablename |
|
| 704 | + * @param array $fieldDefs |
|
| 705 | + * @param array $indices |
|
| 706 | + * @param string $engine optional, MySQL engine to use |
|
| 707 | + * @return string SQL Create Table statement |
|
| 708 | + */ |
|
| 709 | + public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
| 710 | + { |
|
| 711 | + if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 712 | + $engine = $fieldDefs['engine']; |
|
| 713 | + if ( !$this->isEngineEnabled($engine) ) |
|
| 714 | + $engine = ''; |
|
| 715 | + |
|
| 716 | + $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
| 717 | + if (empty($columns)) |
|
| 718 | + return false; |
|
| 719 | + |
|
| 720 | + $keys = $this->keysSQL($indices); |
|
| 721 | + if (!empty($keys)) |
|
| 722 | + $keys = ",$keys"; |
|
| 723 | + |
|
| 724 | + // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
| 725 | + $collation = $this->getOption('collation'); |
|
| 726 | + if(empty($collation)) { |
|
| 727 | + $collation = 'utf8_general_ci'; |
|
| 728 | + } |
|
| 729 | + $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
| 730 | + |
|
| 731 | + if (!empty($engine)) |
|
| 732 | + $sql.= " ENGINE=$engine"; |
|
| 733 | + |
|
| 734 | + return $sql; |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | 737 | /** |
| 738 | 738 | * Does this type represent text (i.e., non-varchar) value? |
@@ -744,745 +744,745 @@ discard block |
||
| 744 | 744 | return in_array($type, array('blob','text','longblob', 'longtext')); |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - /** |
|
| 748 | - * @see DBManager::oneColumnSQLRep() |
|
| 749 | - */ |
|
| 750 | - protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
| 751 | - { |
|
| 752 | - // always return as array for post-processing |
|
| 753 | - $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
| 747 | + /** |
|
| 748 | + * @see DBManager::oneColumnSQLRep() |
|
| 749 | + */ |
|
| 750 | + protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
| 751 | + { |
|
| 752 | + // always return as array for post-processing |
|
| 753 | + $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
| 754 | 754 | |
| 755 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
| 756 | - $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
| 757 | - } |
|
| 755 | + if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
| 756 | + $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - // bug 22338 - don't set a default value on text or blob fields |
|
| 760 | - if ( isset($ref['default']) && |
|
| 759 | + // bug 22338 - don't set a default value on text or blob fields |
|
| 760 | + if ( isset($ref['default']) && |
|
| 761 | 761 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
| 762 | - $ref['default'] = ''; |
|
| 763 | - |
|
| 764 | - if ( $return_as_array ) |
|
| 765 | - return $ref; |
|
| 766 | - else |
|
| 767 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * @see DBManager::changeColumnSQL() |
|
| 772 | - */ |
|
| 773 | - protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
| 774 | - { |
|
| 775 | - $columns = array(); |
|
| 776 | - if ($this->isFieldArray($fieldDefs)){ |
|
| 777 | - foreach ($fieldDefs as $def){ |
|
| 778 | - if ($action == 'drop') |
|
| 779 | - $columns[] = $def['name']; |
|
| 780 | - else |
|
| 781 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 782 | - } |
|
| 783 | - } else { |
|
| 784 | - if ($action == 'drop') |
|
| 785 | - $columns[] = $fieldDefs['name']; |
|
| 786 | - else |
|
| 787 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Generates SQL for key specification inside CREATE TABLE statement |
|
| 795 | - * |
|
| 796 | - * The passes array is an array of field definitions or a field definition |
|
| 797 | - * itself. The keys generated will be either primary, foreign, unique, index |
|
| 798 | - * or none at all depending on the setting of the "key" parameter of a field definition |
|
| 799 | - * |
|
| 800 | - * @param array $indices |
|
| 801 | - * @param bool $alter_table |
|
| 802 | - * @param string $alter_action |
|
| 803 | - * @return string SQL Statement |
|
| 804 | - */ |
|
| 805 | - protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
| 806 | - { |
|
| 807 | - // check if the passed value is an array of fields. |
|
| 808 | - // if not, convert it into an array |
|
| 809 | - if (!$this->isFieldArray($indices)) |
|
| 810 | - $indices[] = $indices; |
|
| 811 | - |
|
| 812 | - $columns = array(); |
|
| 813 | - foreach ($indices as $index) { |
|
| 814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 815 | - continue; |
|
| 816 | - if (isset($index['source']) && $index['source'] != 'db') |
|
| 817 | - continue; |
|
| 818 | - |
|
| 819 | - $type = $index['type']; |
|
| 820 | - $name = $index['name']; |
|
| 821 | - |
|
| 822 | - if (is_array($index['fields'])) |
|
| 823 | - $fields = implode(", ", $index['fields']); |
|
| 824 | - else |
|
| 825 | - $fields = $index['fields']; |
|
| 826 | - |
|
| 827 | - switch ($type) { |
|
| 828 | - case 'unique': |
|
| 829 | - $columns[] = " UNIQUE $name ($fields)"; |
|
| 830 | - break; |
|
| 831 | - case 'primary': |
|
| 832 | - $columns[] = " PRIMARY KEY ($fields)"; |
|
| 833 | - break; |
|
| 834 | - case 'index': |
|
| 835 | - case 'foreign': |
|
| 836 | - case 'clustered': |
|
| 837 | - case 'alternate_key': |
|
| 838 | - /** |
|
| 839 | - * @todo here it is assumed that the primary key of the foreign |
|
| 840 | - * table will always be named 'id'. It must be noted though |
|
| 841 | - * that this can easily be fixed by referring to db dictionary |
|
| 842 | - * to find the correct primary field name |
|
| 843 | - */ |
|
| 844 | - if ( $alter_table ) |
|
| 845 | - $columns[] = " INDEX $name ($fields)"; |
|
| 846 | - else |
|
| 847 | - $columns[] = " KEY $name ($fields)"; |
|
| 848 | - break; |
|
| 849 | - case 'fulltext': |
|
| 850 | - if ($this->full_text_indexing_installed()) |
|
| 851 | - $columns[] = " FULLTEXT ($fields)"; |
|
| 852 | - else |
|
| 853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 854 | - break; |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - $columns = implode(", $alter_action ", $columns); |
|
| 858 | - if(!empty($alter_action)){ |
|
| 859 | - $columns = $alter_action . ' '. $columns; |
|
| 860 | - } |
|
| 861 | - return $columns; |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - /** |
|
| 865 | - * @see DBManager::setAutoIncrement() |
|
| 866 | - */ |
|
| 867 | - protected function setAutoIncrement($table, $field_name) |
|
| 868 | - { |
|
| 869 | - return "auto_increment"; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Sets the next auto-increment value of a column to a specific value. |
|
| 874 | - * |
|
| 875 | - * @param string $table tablename |
|
| 876 | - * @param string $field_name |
|
| 877 | - */ |
|
| 878 | - public function setAutoIncrementStart($table, $field_name, $start_value) |
|
| 879 | - { |
|
| 880 | - $start_value = (int)$start_value; |
|
| 881 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Returns the next value for an auto increment |
|
| 886 | - * |
|
| 887 | - * @param string $table tablename |
|
| 888 | - * @param string $field_name |
|
| 889 | - * @return string |
|
| 890 | - */ |
|
| 891 | - public function getAutoIncrement($table, $field_name) |
|
| 892 | - { |
|
| 893 | - $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
| 894 | - $row = $this->fetchByAssoc($result); |
|
| 895 | - if (!empty($row['Auto_increment'])) |
|
| 896 | - return $row['Auto_increment']; |
|
| 897 | - |
|
| 898 | - return ""; |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * @see DBManager::get_indices() |
|
| 903 | - */ |
|
| 904 | - public function get_indices($tablename) |
|
| 905 | - { |
|
| 906 | - //find all unique indexes and primary keys. |
|
| 907 | - $result = $this->query("SHOW INDEX FROM $tablename"); |
|
| 908 | - |
|
| 909 | - $indices = array(); |
|
| 910 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 911 | - $index_type='index'; |
|
| 912 | - if ($row['Key_name'] =='PRIMARY') { |
|
| 913 | - $index_type='primary'; |
|
| 914 | - } |
|
| 915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
| 916 | - $index_type='unique'; |
|
| 917 | - } |
|
| 918 | - $name = strtolower($row['Key_name']); |
|
| 919 | - $indices[$name]['name']=$name; |
|
| 920 | - $indices[$name]['type']=$index_type; |
|
| 921 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
| 922 | - } |
|
| 923 | - return $indices; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * @see DBManager::add_drop_constraint() |
|
| 928 | - */ |
|
| 929 | - public function add_drop_constraint($table, $definition, $drop = false) |
|
| 930 | - { |
|
| 931 | - $type = $definition['type']; |
|
| 932 | - $fields = implode(',',$definition['fields']); |
|
| 933 | - $name = $definition['name']; |
|
| 934 | - $sql = ''; |
|
| 935 | - |
|
| 936 | - switch ($type){ |
|
| 937 | - // generic indices |
|
| 938 | - case 'index': |
|
| 939 | - case 'alternate_key': |
|
| 940 | - case 'clustered': |
|
| 941 | - if ($drop) |
|
| 942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 943 | - else |
|
| 944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 945 | - break; |
|
| 946 | - // constraints as indices |
|
| 947 | - case 'unique': |
|
| 948 | - if ($drop) |
|
| 949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 950 | - else |
|
| 951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 952 | - break; |
|
| 953 | - case 'primary': |
|
| 954 | - if ($drop) |
|
| 955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 956 | - else |
|
| 957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 958 | - break; |
|
| 959 | - case 'foreign': |
|
| 960 | - if ($drop) |
|
| 961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 962 | - else |
|
| 963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 964 | - break; |
|
| 965 | - } |
|
| 966 | - return $sql; |
|
| 967 | - } |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * Runs a query and returns a single row |
|
| 971 | - * |
|
| 972 | - * @param string $sql SQL Statement to execute |
|
| 973 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 974 | - * @param string $msg Message to log if error occurs |
|
| 975 | - * @param bool $suppress Message to log if error occurs |
|
| 976 | - * @return array single row from the query |
|
| 977 | - */ |
|
| 978 | - public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
| 979 | - { |
|
| 980 | - if(stripos($sql, ' LIMIT ') === false) { |
|
| 981 | - // little optimization to just fetch one row |
|
| 982 | - $sql .= " LIMIT 0,1"; |
|
| 983 | - } |
|
| 984 | - return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - /** |
|
| 988 | - * @see DBManager::full_text_indexing_installed() |
|
| 989 | - */ |
|
| 990 | - public function full_text_indexing_installed($dbname = null) |
|
| 991 | - { |
|
| 992 | - return $this->isEngineEnabled('MyISAM'); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * @see DBManager::massageFieldDef() |
|
| 997 | - */ |
|
| 998 | - public function massageFieldDef(&$fieldDef, $tablename) |
|
| 999 | - { |
|
| 1000 | - parent::massageFieldDef($fieldDef,$tablename); |
|
| 1001 | - |
|
| 1002 | - if ( isset($fieldDef['default']) && |
|
| 1003 | - ($fieldDef['dbType'] == 'text' |
|
| 1004 | - || $fieldDef['dbType'] == 'blob' |
|
| 1005 | - || $fieldDef['dbType'] == 'longtext' |
|
| 1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
| 1007 | - unset($fieldDef['default']); |
|
| 1008 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1009 | - $fieldDef['len'] = '10'; |
|
| 1010 | - if ($fieldDef['dbType'] == 'ulong') |
|
| 1011 | - $fieldDef['len'] = '20'; |
|
| 1012 | - if ($fieldDef['dbType'] == 'bool') |
|
| 1013 | - $fieldDef['type'] = 'tinyint'; |
|
| 1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1015 | - $fieldDef['default'] = '0'; |
|
| 1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1017 | - $fieldDef['len'] = '255'; |
|
| 1018 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1019 | - $fieldDef['len'] = '10'; |
|
| 1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1021 | - $fieldDef['len'] = '11'; |
|
| 1022 | - |
|
| 1023 | - if($fieldDef['dbType'] == 'decimal') { |
|
| 1024 | - if(isset($fieldDef['len'])) { |
|
| 1025 | - if(strstr($fieldDef['len'], ",") === false) { |
|
| 1026 | - $fieldDef['len'] .= ",0"; |
|
| 1027 | - } |
|
| 1028 | - } else { |
|
| 1029 | - $fieldDef['len'] = '10,0'; |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - /** |
|
| 1035 | - * Generates SQL for dropping a table. |
|
| 1036 | - * |
|
| 1037 | - * @param string $name table name |
|
| 1038 | - * @return string SQL statement |
|
| 1039 | - */ |
|
| 1040 | - public function dropTableNameSQL($name) |
|
| 1041 | - { |
|
| 1042 | - return "DROP TABLE IF EXISTS ".$name; |
|
| 1043 | - } |
|
| 1044 | - |
|
| 1045 | - public function dropIndexes($tablename, $indexes, $execute = true) |
|
| 1046 | - { |
|
| 1047 | - $sql = array(); |
|
| 1048 | - foreach ($indexes as $index) { |
|
| 1049 | - $name =$index['name']; |
|
| 1050 | - if($execute) { |
|
| 1051 | - unset(self::$index_descriptions[$tablename][$name]); |
|
| 1052 | - } |
|
| 1053 | - if ($index['type'] == 'primary') { |
|
| 1054 | - $sql[] = 'DROP PRIMARY KEY'; |
|
| 1055 | - } else { |
|
| 1056 | - $sql[] = "DROP INDEX $name"; |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - if (!empty($sql)) { |
|
| 762 | + $ref['default'] = ''; |
|
| 763 | + |
|
| 764 | + if ( $return_as_array ) |
|
| 765 | + return $ref; |
|
| 766 | + else |
|
| 767 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * @see DBManager::changeColumnSQL() |
|
| 772 | + */ |
|
| 773 | + protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
| 774 | + { |
|
| 775 | + $columns = array(); |
|
| 776 | + if ($this->isFieldArray($fieldDefs)){ |
|
| 777 | + foreach ($fieldDefs as $def){ |
|
| 778 | + if ($action == 'drop') |
|
| 779 | + $columns[] = $def['name']; |
|
| 780 | + else |
|
| 781 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 782 | + } |
|
| 783 | + } else { |
|
| 784 | + if ($action == 'drop') |
|
| 785 | + $columns[] = $fieldDefs['name']; |
|
| 786 | + else |
|
| 787 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Generates SQL for key specification inside CREATE TABLE statement |
|
| 795 | + * |
|
| 796 | + * The passes array is an array of field definitions or a field definition |
|
| 797 | + * itself. The keys generated will be either primary, foreign, unique, index |
|
| 798 | + * or none at all depending on the setting of the "key" parameter of a field definition |
|
| 799 | + * |
|
| 800 | + * @param array $indices |
|
| 801 | + * @param bool $alter_table |
|
| 802 | + * @param string $alter_action |
|
| 803 | + * @return string SQL Statement |
|
| 804 | + */ |
|
| 805 | + protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
| 806 | + { |
|
| 807 | + // check if the passed value is an array of fields. |
|
| 808 | + // if not, convert it into an array |
|
| 809 | + if (!$this->isFieldArray($indices)) |
|
| 810 | + $indices[] = $indices; |
|
| 811 | + |
|
| 812 | + $columns = array(); |
|
| 813 | + foreach ($indices as $index) { |
|
| 814 | + if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 815 | + continue; |
|
| 816 | + if (isset($index['source']) && $index['source'] != 'db') |
|
| 817 | + continue; |
|
| 818 | + |
|
| 819 | + $type = $index['type']; |
|
| 820 | + $name = $index['name']; |
|
| 821 | + |
|
| 822 | + if (is_array($index['fields'])) |
|
| 823 | + $fields = implode(", ", $index['fields']); |
|
| 824 | + else |
|
| 825 | + $fields = $index['fields']; |
|
| 826 | + |
|
| 827 | + switch ($type) { |
|
| 828 | + case 'unique': |
|
| 829 | + $columns[] = " UNIQUE $name ($fields)"; |
|
| 830 | + break; |
|
| 831 | + case 'primary': |
|
| 832 | + $columns[] = " PRIMARY KEY ($fields)"; |
|
| 833 | + break; |
|
| 834 | + case 'index': |
|
| 835 | + case 'foreign': |
|
| 836 | + case 'clustered': |
|
| 837 | + case 'alternate_key': |
|
| 838 | + /** |
|
| 839 | + * @todo here it is assumed that the primary key of the foreign |
|
| 840 | + * table will always be named 'id'. It must be noted though |
|
| 841 | + * that this can easily be fixed by referring to db dictionary |
|
| 842 | + * to find the correct primary field name |
|
| 843 | + */ |
|
| 844 | + if ( $alter_table ) |
|
| 845 | + $columns[] = " INDEX $name ($fields)"; |
|
| 846 | + else |
|
| 847 | + $columns[] = " KEY $name ($fields)"; |
|
| 848 | + break; |
|
| 849 | + case 'fulltext': |
|
| 850 | + if ($this->full_text_indexing_installed()) |
|
| 851 | + $columns[] = " FULLTEXT ($fields)"; |
|
| 852 | + else |
|
| 853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 854 | + break; |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + $columns = implode(", $alter_action ", $columns); |
|
| 858 | + if(!empty($alter_action)){ |
|
| 859 | + $columns = $alter_action . ' '. $columns; |
|
| 860 | + } |
|
| 861 | + return $columns; |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + /** |
|
| 865 | + * @see DBManager::setAutoIncrement() |
|
| 866 | + */ |
|
| 867 | + protected function setAutoIncrement($table, $field_name) |
|
| 868 | + { |
|
| 869 | + return "auto_increment"; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Sets the next auto-increment value of a column to a specific value. |
|
| 874 | + * |
|
| 875 | + * @param string $table tablename |
|
| 876 | + * @param string $field_name |
|
| 877 | + */ |
|
| 878 | + public function setAutoIncrementStart($table, $field_name, $start_value) |
|
| 879 | + { |
|
| 880 | + $start_value = (int)$start_value; |
|
| 881 | + return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Returns the next value for an auto increment |
|
| 886 | + * |
|
| 887 | + * @param string $table tablename |
|
| 888 | + * @param string $field_name |
|
| 889 | + * @return string |
|
| 890 | + */ |
|
| 891 | + public function getAutoIncrement($table, $field_name) |
|
| 892 | + { |
|
| 893 | + $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
| 894 | + $row = $this->fetchByAssoc($result); |
|
| 895 | + if (!empty($row['Auto_increment'])) |
|
| 896 | + return $row['Auto_increment']; |
|
| 897 | + |
|
| 898 | + return ""; |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * @see DBManager::get_indices() |
|
| 903 | + */ |
|
| 904 | + public function get_indices($tablename) |
|
| 905 | + { |
|
| 906 | + //find all unique indexes and primary keys. |
|
| 907 | + $result = $this->query("SHOW INDEX FROM $tablename"); |
|
| 908 | + |
|
| 909 | + $indices = array(); |
|
| 910 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 911 | + $index_type='index'; |
|
| 912 | + if ($row['Key_name'] =='PRIMARY') { |
|
| 913 | + $index_type='primary'; |
|
| 914 | + } |
|
| 915 | + elseif ( $row['Non_unique'] == '0' ) { |
|
| 916 | + $index_type='unique'; |
|
| 917 | + } |
|
| 918 | + $name = strtolower($row['Key_name']); |
|
| 919 | + $indices[$name]['name']=$name; |
|
| 920 | + $indices[$name]['type']=$index_type; |
|
| 921 | + $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
| 922 | + } |
|
| 923 | + return $indices; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * @see DBManager::add_drop_constraint() |
|
| 928 | + */ |
|
| 929 | + public function add_drop_constraint($table, $definition, $drop = false) |
|
| 930 | + { |
|
| 931 | + $type = $definition['type']; |
|
| 932 | + $fields = implode(',',$definition['fields']); |
|
| 933 | + $name = $definition['name']; |
|
| 934 | + $sql = ''; |
|
| 935 | + |
|
| 936 | + switch ($type){ |
|
| 937 | + // generic indices |
|
| 938 | + case 'index': |
|
| 939 | + case 'alternate_key': |
|
| 940 | + case 'clustered': |
|
| 941 | + if ($drop) |
|
| 942 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 943 | + else |
|
| 944 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 945 | + break; |
|
| 946 | + // constraints as indices |
|
| 947 | + case 'unique': |
|
| 948 | + if ($drop) |
|
| 949 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 950 | + else |
|
| 951 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 952 | + break; |
|
| 953 | + case 'primary': |
|
| 954 | + if ($drop) |
|
| 955 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 956 | + else |
|
| 957 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 958 | + break; |
|
| 959 | + case 'foreign': |
|
| 960 | + if ($drop) |
|
| 961 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 962 | + else |
|
| 963 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 964 | + break; |
|
| 965 | + } |
|
| 966 | + return $sql; |
|
| 967 | + } |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * Runs a query and returns a single row |
|
| 971 | + * |
|
| 972 | + * @param string $sql SQL Statement to execute |
|
| 973 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
| 974 | + * @param string $msg Message to log if error occurs |
|
| 975 | + * @param bool $suppress Message to log if error occurs |
|
| 976 | + * @return array single row from the query |
|
| 977 | + */ |
|
| 978 | + public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
| 979 | + { |
|
| 980 | + if(stripos($sql, ' LIMIT ') === false) { |
|
| 981 | + // little optimization to just fetch one row |
|
| 982 | + $sql .= " LIMIT 0,1"; |
|
| 983 | + } |
|
| 984 | + return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + /** |
|
| 988 | + * @see DBManager::full_text_indexing_installed() |
|
| 989 | + */ |
|
| 990 | + public function full_text_indexing_installed($dbname = null) |
|
| 991 | + { |
|
| 992 | + return $this->isEngineEnabled('MyISAM'); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * @see DBManager::massageFieldDef() |
|
| 997 | + */ |
|
| 998 | + public function massageFieldDef(&$fieldDef, $tablename) |
|
| 999 | + { |
|
| 1000 | + parent::massageFieldDef($fieldDef,$tablename); |
|
| 1001 | + |
|
| 1002 | + if ( isset($fieldDef['default']) && |
|
| 1003 | + ($fieldDef['dbType'] == 'text' |
|
| 1004 | + || $fieldDef['dbType'] == 'blob' |
|
| 1005 | + || $fieldDef['dbType'] == 'longtext' |
|
| 1006 | + || $fieldDef['dbType'] == 'longblob' )) |
|
| 1007 | + unset($fieldDef['default']); |
|
| 1008 | + if ($fieldDef['dbType'] == 'uint') |
|
| 1009 | + $fieldDef['len'] = '10'; |
|
| 1010 | + if ($fieldDef['dbType'] == 'ulong') |
|
| 1011 | + $fieldDef['len'] = '20'; |
|
| 1012 | + if ($fieldDef['dbType'] == 'bool') |
|
| 1013 | + $fieldDef['type'] = 'tinyint'; |
|
| 1014 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1015 | + $fieldDef['default'] = '0'; |
|
| 1016 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1017 | + $fieldDef['len'] = '255'; |
|
| 1018 | + if ($fieldDef['dbType'] == 'uint') |
|
| 1019 | + $fieldDef['len'] = '10'; |
|
| 1020 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1021 | + $fieldDef['len'] = '11'; |
|
| 1022 | + |
|
| 1023 | + if($fieldDef['dbType'] == 'decimal') { |
|
| 1024 | + if(isset($fieldDef['len'])) { |
|
| 1025 | + if(strstr($fieldDef['len'], ",") === false) { |
|
| 1026 | + $fieldDef['len'] .= ",0"; |
|
| 1027 | + } |
|
| 1028 | + } else { |
|
| 1029 | + $fieldDef['len'] = '10,0'; |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * Generates SQL for dropping a table. |
|
| 1036 | + * |
|
| 1037 | + * @param string $name table name |
|
| 1038 | + * @return string SQL statement |
|
| 1039 | + */ |
|
| 1040 | + public function dropTableNameSQL($name) |
|
| 1041 | + { |
|
| 1042 | + return "DROP TABLE IF EXISTS ".$name; |
|
| 1043 | + } |
|
| 1044 | + |
|
| 1045 | + public function dropIndexes($tablename, $indexes, $execute = true) |
|
| 1046 | + { |
|
| 1047 | + $sql = array(); |
|
| 1048 | + foreach ($indexes as $index) { |
|
| 1049 | + $name =$index['name']; |
|
| 1050 | + if($execute) { |
|
| 1051 | + unset(self::$index_descriptions[$tablename][$name]); |
|
| 1052 | + } |
|
| 1053 | + if ($index['type'] == 'primary') { |
|
| 1054 | + $sql[] = 'DROP PRIMARY KEY'; |
|
| 1055 | + } else { |
|
| 1056 | + $sql[] = "DROP INDEX $name"; |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + if (!empty($sql)) { |
|
| 1060 | 1060 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
| 1061 | - if($execute) |
|
| 1062 | - $this->query($sql); |
|
| 1063 | - } else { |
|
| 1064 | - $sql = ''; |
|
| 1065 | - } |
|
| 1066 | - return $sql; |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - /** |
|
| 1070 | - * List of available collation settings |
|
| 1071 | - * @return string |
|
| 1072 | - */ |
|
| 1073 | - public function getDefaultCollation() |
|
| 1074 | - { |
|
| 1075 | - return "utf8_general_ci"; |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * List of available collation settings |
|
| 1080 | - * @return array |
|
| 1081 | - */ |
|
| 1082 | - public function getCollationList() |
|
| 1083 | - { |
|
| 1084 | - $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
| 1085 | - $r = $this->query($q); |
|
| 1086 | - $res = array(); |
|
| 1087 | - while($a = $this->fetchByAssoc($r)) { |
|
| 1088 | - $res[] = $a['Collation']; |
|
| 1089 | - } |
|
| 1090 | - return $res; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * (non-PHPdoc) |
|
| 1095 | - * @see DBManager::renameColumnSQL() |
|
| 1096 | - */ |
|
| 1097 | - public function renameColumnSQL($tablename, $column, $newname) |
|
| 1098 | - { |
|
| 1099 | - $field = $this->describeField($column, $tablename); |
|
| 1100 | - $field['name'] = $newname; |
|
| 1101 | - return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - public function emptyValue($type) |
|
| 1105 | - { |
|
| 1106 | - $ctype = $this->getColumnType($type); |
|
| 1107 | - if($ctype == "datetime") { |
|
| 1108 | - return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
|
| 1109 | - } |
|
| 1110 | - if($ctype == "date") { |
|
| 1111 | - return $this->convert($this->quoted("0000-00-00"), "date"); |
|
| 1112 | - } |
|
| 1113 | - if($ctype == "time") { |
|
| 1114 | - return $this->convert($this->quoted("00:00:00"), "time"); |
|
| 1115 | - } |
|
| 1116 | - return parent::emptyValue($type); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - /** |
|
| 1120 | - * (non-PHPdoc) |
|
| 1121 | - * @see DBManager::lastDbError() |
|
| 1122 | - */ |
|
| 1123 | - public function lastDbError() |
|
| 1124 | - { |
|
| 1125 | - if($this->database) { |
|
| 1126 | - if(mysql_errno($this->database)) { |
|
| 1127 | - return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
| 1128 | - } |
|
| 1129 | - } else { |
|
| 1130 | - $err = mysql_error(); |
|
| 1131 | - if($err) { |
|
| 1132 | - return $err; |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1061 | + if($execute) |
|
| 1062 | + $this->query($sql); |
|
| 1063 | + } else { |
|
| 1064 | + $sql = ''; |
|
| 1065 | + } |
|
| 1066 | + return $sql; |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + /** |
|
| 1070 | + * List of available collation settings |
|
| 1071 | + * @return string |
|
| 1072 | + */ |
|
| 1073 | + public function getDefaultCollation() |
|
| 1074 | + { |
|
| 1075 | + return "utf8_general_ci"; |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * List of available collation settings |
|
| 1080 | + * @return array |
|
| 1081 | + */ |
|
| 1082 | + public function getCollationList() |
|
| 1083 | + { |
|
| 1084 | + $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
| 1085 | + $r = $this->query($q); |
|
| 1086 | + $res = array(); |
|
| 1087 | + while($a = $this->fetchByAssoc($r)) { |
|
| 1088 | + $res[] = $a['Collation']; |
|
| 1089 | + } |
|
| 1090 | + return $res; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * (non-PHPdoc) |
|
| 1095 | + * @see DBManager::renameColumnSQL() |
|
| 1096 | + */ |
|
| 1097 | + public function renameColumnSQL($tablename, $column, $newname) |
|
| 1098 | + { |
|
| 1099 | + $field = $this->describeField($column, $tablename); |
|
| 1100 | + $field['name'] = $newname; |
|
| 1101 | + return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + public function emptyValue($type) |
|
| 1105 | + { |
|
| 1106 | + $ctype = $this->getColumnType($type); |
|
| 1107 | + if($ctype == "datetime") { |
|
| 1108 | + return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
|
| 1109 | + } |
|
| 1110 | + if($ctype == "date") { |
|
| 1111 | + return $this->convert($this->quoted("0000-00-00"), "date"); |
|
| 1112 | + } |
|
| 1113 | + if($ctype == "time") { |
|
| 1114 | + return $this->convert($this->quoted("00:00:00"), "time"); |
|
| 1115 | + } |
|
| 1116 | + return parent::emptyValue($type); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + /** |
|
| 1120 | + * (non-PHPdoc) |
|
| 1121 | + * @see DBManager::lastDbError() |
|
| 1122 | + */ |
|
| 1123 | + public function lastDbError() |
|
| 1124 | + { |
|
| 1125 | + if($this->database) { |
|
| 1126 | + if(mysql_errno($this->database)) { |
|
| 1127 | + return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
| 1128 | + } |
|
| 1129 | + } else { |
|
| 1130 | + $err = mysql_error(); |
|
| 1131 | + if($err) { |
|
| 1132 | + return $err; |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | 1135 | return false; |
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | - /** |
|
| 1139 | - * Quote MySQL search term |
|
| 1140 | - * @param unknown_type $term |
|
| 1141 | - */ |
|
| 1142 | - protected function quoteTerm($term) |
|
| 1143 | - { |
|
| 1144 | - if(strpos($term, ' ') !== false) { |
|
| 1145 | - return '"'.$term.'"'; |
|
| 1146 | - } |
|
| 1147 | - return $term; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Generate fulltext query from set of terms |
|
| 1152 | - * @param string $fields Field to search against |
|
| 1153 | - * @param array $terms Search terms that may be or not be in the result |
|
| 1154 | - * @param array $must_terms Search terms that have to be in the result |
|
| 1155 | - * @param array $exclude_terms Search terms that have to be not in the result |
|
| 1156 | - */ |
|
| 1157 | - public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
| 1158 | - { |
|
| 1159 | - $condition = array(); |
|
| 1160 | - foreach($terms as $term) { |
|
| 1161 | - $condition[] = $this->quoteTerm($term); |
|
| 1162 | - } |
|
| 1163 | - foreach($must_terms as $term) { |
|
| 1164 | - $condition[] = "+".$this->quoteTerm($term); |
|
| 1165 | - } |
|
| 1166 | - foreach($exclude_terms as $term) { |
|
| 1167 | - $condition[] = "-".$this->quoteTerm($term); |
|
| 1168 | - } |
|
| 1169 | - $condition = $this->quoted(join(" ",$condition)); |
|
| 1170 | - return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - /** |
|
| 1174 | - * Get list of all defined charsets |
|
| 1175 | - * @return array |
|
| 1176 | - */ |
|
| 1177 | - protected function getCharsetInfo() |
|
| 1178 | - { |
|
| 1179 | - $charsets = array(); |
|
| 1180 | - $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
| 1181 | - while($row = $this->fetchByAssoc($res)) { |
|
| 1182 | - $charsets[$row['Variable_name']] = $row['Value']; |
|
| 1183 | - } |
|
| 1184 | - return $charsets; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - public function getDbInfo() |
|
| 1188 | - { |
|
| 1189 | - $charsets = $this->getCharsetInfo(); |
|
| 1190 | - $charset_str = array(); |
|
| 1191 | - foreach($charsets as $name => $value) { |
|
| 1192 | - $charset_str[] = "$name = $value"; |
|
| 1193 | - } |
|
| 1194 | - return array( |
|
| 1195 | - "MySQL Version" => @mysql_get_client_info(), |
|
| 1196 | - "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
| 1197 | - "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
| 1198 | - "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
| 1199 | - "MySQL Character Set Settings" => join(", ", $charset_str), |
|
| 1200 | - ); |
|
| 1201 | - } |
|
| 1202 | - |
|
| 1203 | - public function validateQuery($query) |
|
| 1204 | - { |
|
| 1205 | - $res = $this->query("EXPLAIN $query"); |
|
| 1206 | - return !empty($res); |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - protected function makeTempTableCopy($table) |
|
| 1210 | - { |
|
| 1211 | - $this->log->debug("creating temp table for [$table]..."); |
|
| 1212 | - $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
| 1213 | - if(empty($result)) { |
|
| 1214 | - return false; |
|
| 1215 | - } |
|
| 1216 | - $row = $this->fetchByAssoc($result); |
|
| 1217 | - if(empty($row) || empty($row['Create Table'])) { |
|
| 1218 | - return false; |
|
| 1219 | - } |
|
| 1220 | - $create = $row['Create Table']; |
|
| 1221 | - // rewrite DDL with _temp name |
|
| 1222 | - $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
| 1223 | - $r2 = $this->query($tempTableQuery); |
|
| 1224 | - if(empty($r2)) { |
|
| 1225 | - return false; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - // get sample data into the temp table to test for data/constraint conflicts |
|
| 1229 | - $this->log->debug('inserting temp dataset...'); |
|
| 1230 | - $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
| 1231 | - $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
| 1232 | - return true; |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - /** |
|
| 1236 | - * Tests an ALTER TABLE query |
|
| 1237 | - * @param string table The table name to get DDL |
|
| 1238 | - * @param string query The query to test. |
|
| 1239 | - * @return string Non-empty if error found |
|
| 1240 | - */ |
|
| 1241 | - protected function verifyAlterTable($table, $query) |
|
| 1242 | - { |
|
| 1243 | - $this->log->debug("verifying ALTER TABLE"); |
|
| 1244 | - // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
| 1245 | - // over to the temp tables |
|
| 1246 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1247 | - $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
| 1248 | - return ''; |
|
| 1249 | - } |
|
| 1250 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1251 | - return 'Could not create temp table copy'; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - // test the query on the test table |
|
| 1255 | - $this->log->debug('testing query: ['.$query.']'); |
|
| 1256 | - $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
| 1257 | - if (strpos($tempTableTestQuery, 'idx') === false) { |
|
| 1258 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1259 | - return 'Could not use a temp table to test query!'; |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
| 1263 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1264 | - } else { |
|
| 1265 | - // test insertion of an index on a table |
|
| 1266 | - $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
| 1267 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
| 1268 | - $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
| 1269 | - } |
|
| 1270 | - $mysqlError = $this->getL(); |
|
| 1271 | - if(!empty($mysqlError)) { |
|
| 1272 | - return $mysqlError; |
|
| 1273 | - } |
|
| 1274 | - $this->dropTableName("{$table}__uw_temp"); |
|
| 1275 | - |
|
| 1276 | - return ''; |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
| 1280 | - { |
|
| 1281 | - $this->log->debug("verifying $querytype statement"); |
|
| 1282 | - |
|
| 1283 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1284 | - return 'Could not create temp table copy'; |
|
| 1285 | - } |
|
| 1286 | - // test the query on the test table |
|
| 1287 | - $this->log->debug('testing query: ['.$query.']'); |
|
| 1288 | - $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
| 1289 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1290 | - return 'Could not use a temp table to test query!'; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1294 | - $error = $this->lastError(); // empty on no-errors |
|
| 1295 | - $this->dropTableName("{$table}__uw_temp"); // just in case |
|
| 1296 | - return $error; |
|
| 1297 | - } |
|
| 1298 | - |
|
| 1299 | - /** |
|
| 1300 | - * Tests a DROP TABLE query |
|
| 1301 | - * @param string table The table name to get DDL |
|
| 1302 | - * @param string query The query to test. |
|
| 1303 | - * @return string Non-empty if error found |
|
| 1304 | - */ |
|
| 1305 | - public function verifyDropTable($table, $query) |
|
| 1306 | - { |
|
| 1307 | - return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * Tests an INSERT INTO query |
|
| 1312 | - * @param string table The table name to get DDL |
|
| 1313 | - * @param string query The query to test. |
|
| 1314 | - * @return string Non-empty if error found |
|
| 1315 | - */ |
|
| 1316 | - public function verifyInsertInto($table, $query) |
|
| 1317 | - { |
|
| 1318 | - return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - /** |
|
| 1322 | - * Tests an UPDATE query |
|
| 1323 | - * @param string table The table name to get DDL |
|
| 1324 | - * @param string query The query to test. |
|
| 1325 | - * @return string Non-empty if error found |
|
| 1326 | - */ |
|
| 1327 | - public function verifyUpdate($table, $query) |
|
| 1328 | - { |
|
| 1329 | - return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * Tests an DELETE FROM query |
|
| 1334 | - * @param string table The table name to get DDL |
|
| 1335 | - * @param string query The query to test. |
|
| 1336 | - * @return string Non-empty if error found |
|
| 1337 | - */ |
|
| 1338 | - public function verifyDeleteFrom($table, $query) |
|
| 1339 | - { |
|
| 1340 | - return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - /** |
|
| 1344 | - * Check if certain database exists |
|
| 1345 | - * @param string $dbname |
|
| 1346 | - */ |
|
| 1347 | - public function dbExists($dbname) |
|
| 1348 | - { |
|
| 1349 | - $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
| 1350 | - return !empty($db); |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * Select database |
|
| 1355 | - * @param string $dbname |
|
| 1356 | - */ |
|
| 1357 | - protected function selectDb($dbname) |
|
| 1358 | - { |
|
| 1359 | - return mysql_select_db($dbname); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Check if certain DB user exists |
|
| 1364 | - * @param string $username |
|
| 1365 | - */ |
|
| 1366 | - public function userExists($username) |
|
| 1367 | - { |
|
| 1368 | - $db = $this->getOne("SELECT DATABASE()"); |
|
| 1369 | - if(!$this->selectDb("mysql")) { |
|
| 1370 | - return false; |
|
| 1371 | - } |
|
| 1372 | - $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
| 1373 | - if(!$this->selectDb($db)) { |
|
| 1374 | - $this->checkError("Cannot select database $db", true); |
|
| 1375 | - } |
|
| 1376 | - return !empty($user); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * Create DB user |
|
| 1381 | - * @param string $database_name |
|
| 1382 | - * @param string $host_name |
|
| 1383 | - * @param string $user |
|
| 1384 | - * @param string $password |
|
| 1385 | - */ |
|
| 1386 | - public function createDbUser($database_name, $host_name, $user, $password) |
|
| 1387 | - { |
|
| 1388 | - $qpassword = $this->quote($password); |
|
| 1389 | - $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
| 1138 | + /** |
|
| 1139 | + * Quote MySQL search term |
|
| 1140 | + * @param unknown_type $term |
|
| 1141 | + */ |
|
| 1142 | + protected function quoteTerm($term) |
|
| 1143 | + { |
|
| 1144 | + if(strpos($term, ' ') !== false) { |
|
| 1145 | + return '"'.$term.'"'; |
|
| 1146 | + } |
|
| 1147 | + return $term; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Generate fulltext query from set of terms |
|
| 1152 | + * @param string $fields Field to search against |
|
| 1153 | + * @param array $terms Search terms that may be or not be in the result |
|
| 1154 | + * @param array $must_terms Search terms that have to be in the result |
|
| 1155 | + * @param array $exclude_terms Search terms that have to be not in the result |
|
| 1156 | + */ |
|
| 1157 | + public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
| 1158 | + { |
|
| 1159 | + $condition = array(); |
|
| 1160 | + foreach($terms as $term) { |
|
| 1161 | + $condition[] = $this->quoteTerm($term); |
|
| 1162 | + } |
|
| 1163 | + foreach($must_terms as $term) { |
|
| 1164 | + $condition[] = "+".$this->quoteTerm($term); |
|
| 1165 | + } |
|
| 1166 | + foreach($exclude_terms as $term) { |
|
| 1167 | + $condition[] = "-".$this->quoteTerm($term); |
|
| 1168 | + } |
|
| 1169 | + $condition = $this->quoted(join(" ",$condition)); |
|
| 1170 | + return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + /** |
|
| 1174 | + * Get list of all defined charsets |
|
| 1175 | + * @return array |
|
| 1176 | + */ |
|
| 1177 | + protected function getCharsetInfo() |
|
| 1178 | + { |
|
| 1179 | + $charsets = array(); |
|
| 1180 | + $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
| 1181 | + while($row = $this->fetchByAssoc($res)) { |
|
| 1182 | + $charsets[$row['Variable_name']] = $row['Value']; |
|
| 1183 | + } |
|
| 1184 | + return $charsets; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + public function getDbInfo() |
|
| 1188 | + { |
|
| 1189 | + $charsets = $this->getCharsetInfo(); |
|
| 1190 | + $charset_str = array(); |
|
| 1191 | + foreach($charsets as $name => $value) { |
|
| 1192 | + $charset_str[] = "$name = $value"; |
|
| 1193 | + } |
|
| 1194 | + return array( |
|
| 1195 | + "MySQL Version" => @mysql_get_client_info(), |
|
| 1196 | + "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
| 1197 | + "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
| 1198 | + "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
| 1199 | + "MySQL Character Set Settings" => join(", ", $charset_str), |
|
| 1200 | + ); |
|
| 1201 | + } |
|
| 1202 | + |
|
| 1203 | + public function validateQuery($query) |
|
| 1204 | + { |
|
| 1205 | + $res = $this->query("EXPLAIN $query"); |
|
| 1206 | + return !empty($res); |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + protected function makeTempTableCopy($table) |
|
| 1210 | + { |
|
| 1211 | + $this->log->debug("creating temp table for [$table]..."); |
|
| 1212 | + $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
| 1213 | + if(empty($result)) { |
|
| 1214 | + return false; |
|
| 1215 | + } |
|
| 1216 | + $row = $this->fetchByAssoc($result); |
|
| 1217 | + if(empty($row) || empty($row['Create Table'])) { |
|
| 1218 | + return false; |
|
| 1219 | + } |
|
| 1220 | + $create = $row['Create Table']; |
|
| 1221 | + // rewrite DDL with _temp name |
|
| 1222 | + $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
| 1223 | + $r2 = $this->query($tempTableQuery); |
|
| 1224 | + if(empty($r2)) { |
|
| 1225 | + return false; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + // get sample data into the temp table to test for data/constraint conflicts |
|
| 1229 | + $this->log->debug('inserting temp dataset...'); |
|
| 1230 | + $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
| 1231 | + $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
| 1232 | + return true; |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + /** |
|
| 1236 | + * Tests an ALTER TABLE query |
|
| 1237 | + * @param string table The table name to get DDL |
|
| 1238 | + * @param string query The query to test. |
|
| 1239 | + * @return string Non-empty if error found |
|
| 1240 | + */ |
|
| 1241 | + protected function verifyAlterTable($table, $query) |
|
| 1242 | + { |
|
| 1243 | + $this->log->debug("verifying ALTER TABLE"); |
|
| 1244 | + // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
| 1245 | + // over to the temp tables |
|
| 1246 | + if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1247 | + $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
| 1248 | + return ''; |
|
| 1249 | + } |
|
| 1250 | + if(!$this->makeTempTableCopy($table)) { |
|
| 1251 | + return 'Could not create temp table copy'; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // test the query on the test table |
|
| 1255 | + $this->log->debug('testing query: ['.$query.']'); |
|
| 1256 | + $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
| 1257 | + if (strpos($tempTableTestQuery, 'idx') === false) { |
|
| 1258 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1259 | + return 'Could not use a temp table to test query!'; |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
| 1263 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1264 | + } else { |
|
| 1265 | + // test insertion of an index on a table |
|
| 1266 | + $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
| 1267 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
| 1268 | + $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
| 1269 | + } |
|
| 1270 | + $mysqlError = $this->getL(); |
|
| 1271 | + if(!empty($mysqlError)) { |
|
| 1272 | + return $mysqlError; |
|
| 1273 | + } |
|
| 1274 | + $this->dropTableName("{$table}__uw_temp"); |
|
| 1275 | + |
|
| 1276 | + return ''; |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
| 1280 | + { |
|
| 1281 | + $this->log->debug("verifying $querytype statement"); |
|
| 1282 | + |
|
| 1283 | + if(!$this->makeTempTableCopy($table)) { |
|
| 1284 | + return 'Could not create temp table copy'; |
|
| 1285 | + } |
|
| 1286 | + // test the query on the test table |
|
| 1287 | + $this->log->debug('testing query: ['.$query.']'); |
|
| 1288 | + $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
| 1289 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1290 | + return 'Could not use a temp table to test query!'; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
| 1294 | + $error = $this->lastError(); // empty on no-errors |
|
| 1295 | + $this->dropTableName("{$table}__uw_temp"); // just in case |
|
| 1296 | + return $error; |
|
| 1297 | + } |
|
| 1298 | + |
|
| 1299 | + /** |
|
| 1300 | + * Tests a DROP TABLE query |
|
| 1301 | + * @param string table The table name to get DDL |
|
| 1302 | + * @param string query The query to test. |
|
| 1303 | + * @return string Non-empty if error found |
|
| 1304 | + */ |
|
| 1305 | + public function verifyDropTable($table, $query) |
|
| 1306 | + { |
|
| 1307 | + return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * Tests an INSERT INTO query |
|
| 1312 | + * @param string table The table name to get DDL |
|
| 1313 | + * @param string query The query to test. |
|
| 1314 | + * @return string Non-empty if error found |
|
| 1315 | + */ |
|
| 1316 | + public function verifyInsertInto($table, $query) |
|
| 1317 | + { |
|
| 1318 | + return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + /** |
|
| 1322 | + * Tests an UPDATE query |
|
| 1323 | + * @param string table The table name to get DDL |
|
| 1324 | + * @param string query The query to test. |
|
| 1325 | + * @return string Non-empty if error found |
|
| 1326 | + */ |
|
| 1327 | + public function verifyUpdate($table, $query) |
|
| 1328 | + { |
|
| 1329 | + return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * Tests an DELETE FROM query |
|
| 1334 | + * @param string table The table name to get DDL |
|
| 1335 | + * @param string query The query to test. |
|
| 1336 | + * @return string Non-empty if error found |
|
| 1337 | + */ |
|
| 1338 | + public function verifyDeleteFrom($table, $query) |
|
| 1339 | + { |
|
| 1340 | + return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + /** |
|
| 1344 | + * Check if certain database exists |
|
| 1345 | + * @param string $dbname |
|
| 1346 | + */ |
|
| 1347 | + public function dbExists($dbname) |
|
| 1348 | + { |
|
| 1349 | + $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
| 1350 | + return !empty($db); |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * Select database |
|
| 1355 | + * @param string $dbname |
|
| 1356 | + */ |
|
| 1357 | + protected function selectDb($dbname) |
|
| 1358 | + { |
|
| 1359 | + return mysql_select_db($dbname); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Check if certain DB user exists |
|
| 1364 | + * @param string $username |
|
| 1365 | + */ |
|
| 1366 | + public function userExists($username) |
|
| 1367 | + { |
|
| 1368 | + $db = $this->getOne("SELECT DATABASE()"); |
|
| 1369 | + if(!$this->selectDb("mysql")) { |
|
| 1370 | + return false; |
|
| 1371 | + } |
|
| 1372 | + $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
| 1373 | + if(!$this->selectDb($db)) { |
|
| 1374 | + $this->checkError("Cannot select database $db", true); |
|
| 1375 | + } |
|
| 1376 | + return !empty($user); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * Create DB user |
|
| 1381 | + * @param string $database_name |
|
| 1382 | + * @param string $host_name |
|
| 1383 | + * @param string $user |
|
| 1384 | + * @param string $password |
|
| 1385 | + */ |
|
| 1386 | + public function createDbUser($database_name, $host_name, $user, $password) |
|
| 1387 | + { |
|
| 1388 | + $qpassword = $this->quote($password); |
|
| 1389 | + $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
| 1390 | 1390 | ON `$database_name`.* |
| 1391 | 1391 | TO \"$user\"@\"$host_name\" |
| 1392 | 1392 | IDENTIFIED BY '{$qpassword}';", true); |
| 1393 | 1393 | |
| 1394 | - $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
| 1395 | - if($host_name != 'localhost') { |
|
| 1396 | - $this->createDbUser($database_name, "localhost", $user, $password); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * Create a database |
|
| 1402 | - * @param string $dbname |
|
| 1403 | - */ |
|
| 1404 | - public function createDatabase($dbname) |
|
| 1405 | - { |
|
| 1406 | - $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - public function preInstall() |
|
| 1410 | - { |
|
| 1411 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
| 1412 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
| 1413 | - |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * Drop a database |
|
| 1418 | - * @param string $dbname |
|
| 1419 | - */ |
|
| 1420 | - public function dropDatabase($dbname) |
|
| 1421 | - { |
|
| 1422 | - return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - /** |
|
| 1426 | - * Check if this driver can be used |
|
| 1427 | - * @return bool |
|
| 1428 | - */ |
|
| 1429 | - public function valid() |
|
| 1430 | - { |
|
| 1431 | - return function_exists("mysql_connect"); |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - /** |
|
| 1435 | - * Check DB version |
|
| 1436 | - * @see DBManager::canInstall() |
|
| 1437 | - */ |
|
| 1438 | - public function canInstall() |
|
| 1439 | - { |
|
| 1440 | - $db_version = $this->version(); |
|
| 1441 | - if(empty($db_version)) { |
|
| 1442 | - return array('ERR_DB_VERSION_FAILURE'); |
|
| 1443 | - } |
|
| 1444 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
| 1445 | - return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
| 1446 | - } |
|
| 1447 | - return true; |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - public function installConfig() |
|
| 1451 | - { |
|
| 1452 | - return array( |
|
| 1453 | - 'LBL_DBCONFIG_MSG3' => array( |
|
| 1454 | - "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
| 1455 | - ), |
|
| 1456 | - 'LBL_DBCONFIG_MSG2' => array( |
|
| 1457 | - "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
| 1458 | - ), |
|
| 1459 | - 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
| 1460 | - 'LBL_DBCONFIG_B_MSG1' => array( |
|
| 1461 | - "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
| 1462 | - "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
| 1463 | - ) |
|
| 1464 | - ); |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * Disable keys on the table |
|
| 1469 | - * @abstract |
|
| 1470 | - * @param string $tableName |
|
| 1471 | - */ |
|
| 1472 | - public function disableKeys($tableName) |
|
| 1473 | - { |
|
| 1474 | - return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
| 1475 | - } |
|
| 1476 | - |
|
| 1477 | - /** |
|
| 1478 | - * Re-enable keys on the table |
|
| 1479 | - * @abstract |
|
| 1480 | - * @param string $tableName |
|
| 1481 | - */ |
|
| 1482 | - public function enableKeys($tableName) |
|
| 1483 | - { |
|
| 1484 | - return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
| 1485 | - } |
|
| 1394 | + $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
| 1395 | + if($host_name != 'localhost') { |
|
| 1396 | + $this->createDbUser($database_name, "localhost", $user, $password); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + /** |
|
| 1401 | + * Create a database |
|
| 1402 | + * @param string $dbname |
|
| 1403 | + */ |
|
| 1404 | + public function createDatabase($dbname) |
|
| 1405 | + { |
|
| 1406 | + $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
| 1407 | + } |
|
| 1408 | + |
|
| 1409 | + public function preInstall() |
|
| 1410 | + { |
|
| 1411 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
| 1412 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
| 1413 | + |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * Drop a database |
|
| 1418 | + * @param string $dbname |
|
| 1419 | + */ |
|
| 1420 | + public function dropDatabase($dbname) |
|
| 1421 | + { |
|
| 1422 | + return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + /** |
|
| 1426 | + * Check if this driver can be used |
|
| 1427 | + * @return bool |
|
| 1428 | + */ |
|
| 1429 | + public function valid() |
|
| 1430 | + { |
|
| 1431 | + return function_exists("mysql_connect"); |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + /** |
|
| 1435 | + * Check DB version |
|
| 1436 | + * @see DBManager::canInstall() |
|
| 1437 | + */ |
|
| 1438 | + public function canInstall() |
|
| 1439 | + { |
|
| 1440 | + $db_version = $this->version(); |
|
| 1441 | + if(empty($db_version)) { |
|
| 1442 | + return array('ERR_DB_VERSION_FAILURE'); |
|
| 1443 | + } |
|
| 1444 | + if(version_compare($db_version, '4.1.2') < 0) { |
|
| 1445 | + return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
| 1446 | + } |
|
| 1447 | + return true; |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + public function installConfig() |
|
| 1451 | + { |
|
| 1452 | + return array( |
|
| 1453 | + 'LBL_DBCONFIG_MSG3' => array( |
|
| 1454 | + "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
| 1455 | + ), |
|
| 1456 | + 'LBL_DBCONFIG_MSG2' => array( |
|
| 1457 | + "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
| 1458 | + ), |
|
| 1459 | + 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
| 1460 | + 'LBL_DBCONFIG_B_MSG1' => array( |
|
| 1461 | + "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
| 1462 | + "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
| 1463 | + ) |
|
| 1464 | + ); |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * Disable keys on the table |
|
| 1469 | + * @abstract |
|
| 1470 | + * @param string $tableName |
|
| 1471 | + */ |
|
| 1472 | + public function disableKeys($tableName) |
|
| 1473 | + { |
|
| 1474 | + return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
| 1475 | + } |
|
| 1476 | + |
|
| 1477 | + /** |
|
| 1478 | + * Re-enable keys on the table |
|
| 1479 | + * @abstract |
|
| 1480 | + * @param string $tableName |
|
| 1481 | + */ |
|
| 1482 | + public function enableKeys($tableName) |
|
| 1483 | + { |
|
| 1484 | + return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
| 1485 | + } |
|
| 1486 | 1486 | |
| 1487 | 1487 | /** |
| 1488 | 1488 | * Returns a DB specific FROM clause which can be used to select against functions. |
@@ -1501,8 +1501,8 @@ discard block |
||
| 1501 | 1501 | * @return string |
| 1502 | 1502 | */ |
| 1503 | 1503 | |
| 1504 | - public function getGuidSQL() |
|
| 1504 | + public function getGuidSQL() |
|
| 1505 | 1505 | { |
| 1506 | - return 'UUID()'; |
|
| 1506 | + return 'UUID()'; |
|
| 1507 | 1507 | } |
| 1508 | 1508 | } |
@@ -825,33 +825,33 @@ discard block |
||
| 825 | 825 | $fields = $index['fields']; |
| 826 | 826 | |
| 827 | 827 | switch ($type) { |
| 828 | - case 'unique': |
|
| 829 | - $columns[] = " UNIQUE $name ($fields)"; |
|
| 830 | - break; |
|
| 831 | - case 'primary': |
|
| 832 | - $columns[] = " PRIMARY KEY ($fields)"; |
|
| 833 | - break; |
|
| 834 | - case 'index': |
|
| 835 | - case 'foreign': |
|
| 836 | - case 'clustered': |
|
| 837 | - case 'alternate_key': |
|
| 838 | - /** |
|
| 828 | + case 'unique': |
|
| 829 | + $columns[] = " UNIQUE $name ($fields)"; |
|
| 830 | + break; |
|
| 831 | + case 'primary': |
|
| 832 | + $columns[] = " PRIMARY KEY ($fields)"; |
|
| 833 | + break; |
|
| 834 | + case 'index': |
|
| 835 | + case 'foreign': |
|
| 836 | + case 'clustered': |
|
| 837 | + case 'alternate_key': |
|
| 838 | + /** |
|
| 839 | 839 | * @todo here it is assumed that the primary key of the foreign |
| 840 | 840 | * table will always be named 'id'. It must be noted though |
| 841 | 841 | * that this can easily be fixed by referring to db dictionary |
| 842 | 842 | * to find the correct primary field name |
| 843 | 843 | */ |
| 844 | - if ( $alter_table ) |
|
| 845 | - $columns[] = " INDEX $name ($fields)"; |
|
| 846 | - else |
|
| 847 | - $columns[] = " KEY $name ($fields)"; |
|
| 848 | - break; |
|
| 849 | - case 'fulltext': |
|
| 850 | - if ($this->full_text_indexing_installed()) |
|
| 851 | - $columns[] = " FULLTEXT ($fields)"; |
|
| 852 | - else |
|
| 853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 854 | - break; |
|
| 844 | + if ( $alter_table ) |
|
| 845 | + $columns[] = " INDEX $name ($fields)"; |
|
| 846 | + else |
|
| 847 | + $columns[] = " KEY $name ($fields)"; |
|
| 848 | + break; |
|
| 849 | + case 'fulltext': |
|
| 850 | + if ($this->full_text_indexing_installed()) |
|
| 851 | + $columns[] = " FULLTEXT ($fields)"; |
|
| 852 | + else |
|
| 853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 854 | + break; |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | $columns = implode(", $alter_action ", $columns); |
@@ -935,33 +935,33 @@ discard block |
||
| 935 | 935 | |
| 936 | 936 | switch ($type){ |
| 937 | 937 | // generic indices |
| 938 | - case 'index': |
|
| 939 | - case 'alternate_key': |
|
| 940 | - case 'clustered': |
|
| 941 | - if ($drop) |
|
| 942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 943 | - else |
|
| 944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 945 | - break; |
|
| 946 | - // constraints as indices |
|
| 947 | - case 'unique': |
|
| 948 | - if ($drop) |
|
| 949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 950 | - else |
|
| 951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 952 | - break; |
|
| 953 | - case 'primary': |
|
| 954 | - if ($drop) |
|
| 955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 956 | - else |
|
| 957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 958 | - break; |
|
| 959 | - case 'foreign': |
|
| 960 | - if ($drop) |
|
| 961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 962 | - else |
|
| 963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 964 | - break; |
|
| 938 | + case 'index': |
|
| 939 | + case 'alternate_key': |
|
| 940 | + case 'clustered': |
|
| 941 | + if ($drop) |
|
| 942 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 943 | + else |
|
| 944 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 945 | + break; |
|
| 946 | + // constraints as indices |
|
| 947 | + case 'unique': |
|
| 948 | + if ($drop) |
|
| 949 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 950 | + else |
|
| 951 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 952 | + break; |
|
| 953 | + case 'primary': |
|
| 954 | + if ($drop) |
|
| 955 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 956 | + else |
|
| 957 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 958 | + break; |
|
| 959 | + case 'foreign': |
|
| 960 | + if ($drop) |
|
| 961 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 962 | + else |
|
| 963 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 964 | + break; |
|
| 965 | 965 | } |
| 966 | 966 | return $sql; |
| 967 | 967 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -170,25 +170,25 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
| 172 | 172 | { |
| 173 | - if(is_array($sql)) { |
|
| 173 | + if (is_array($sql)) { |
|
| 174 | 174 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | parent::countQuery($sql); |
| 178 | - $GLOBALS['log']->info('Query:' . $sql); |
|
| 178 | + $GLOBALS['log']->info('Query:'.$sql); |
|
| 179 | 179 | $this->checkConnection(); |
| 180 | 180 | $this->query_time = microtime(true); |
| 181 | 181 | $this->lastsql = $sql; |
| 182 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
| 182 | + $result = $suppress ? @mysql_query($sql, $this->database) : mysql_query($sql, $this->database); |
|
| 183 | 183 | |
| 184 | 184 | $this->query_time = microtime(true) - $this->query_time; |
| 185 | 185 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
| 186 | 186 | |
| 187 | 187 | |
| 188 | - if($keepResult) |
|
| 188 | + if ($keepResult) |
|
| 189 | 189 | $this->lastResult = $result; |
| 190 | 190 | |
| 191 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
| 191 | + $this->checkError($msg.' Query Failed:'.$sql.'::', $dieOnError); |
|
| 192 | 192 | return $result; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | public function disconnect() |
| 225 | 225 | { |
| 226 | 226 | $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
| 227 | - if(!empty($this->database)){ |
|
| 227 | + if (!empty($this->database)) { |
|
| 228 | 228 | $this->freeResult(); |
| 229 | 229 | mysql_close($this->database); |
| 230 | 230 | $this->database = null; |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | protected function freeDbResult($dbResult) |
| 238 | 238 | { |
| 239 | - if(!empty($dbResult)) |
|
| 239 | + if (!empty($dbResult)) |
|
| 240 | 240 | mysql_free_result($dbResult); |
| 241 | 241 | } |
| 242 | 242 | |
@@ -262,15 +262,15 @@ discard block |
||
| 262 | 262 | $count = (int)$count; |
| 263 | 263 | if ($start < 0) |
| 264 | 264 | $start = 0; |
| 265 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
| 265 | + $GLOBALS['log']->debug('Limit Query:'.$sql.' Start: '.$start.' count: '.$count); |
|
| 266 | 266 | |
| 267 | 267 | $sql = "$sql LIMIT $start,$count"; |
| 268 | 268 | $this->lastsql = $sql; |
| 269 | 269 | |
| 270 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
| 270 | + if (!empty($GLOBALS['sugar_config']['check_query'])) { |
|
| 271 | 271 | $this->checkQuery($sql); |
| 272 | 272 | } |
| 273 | - if(!$execute) { |
|
| 273 | + if (!$execute) { |
|
| 274 | 274 | return $sql; |
| 275 | 275 | } |
| 276 | 276 | |
@@ -283,14 +283,14 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | protected function checkQuery($sql, $object_name = false) |
| 285 | 285 | { |
| 286 | - $result = $this->query('EXPLAIN ' . $sql); |
|
| 286 | + $result = $this->query('EXPLAIN '.$sql); |
|
| 287 | 287 | $badQuery = array(); |
| 288 | 288 | while ($row = $this->fetchByAssoc($result)) { |
| 289 | 289 | if (empty($row['table'])) |
| 290 | 290 | continue; |
| 291 | 291 | $badQuery[$row['table']] = ''; |
| 292 | 292 | if (strtoupper($row['type']) == 'ALL') |
| 293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 293 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 294 | 294 | if (empty($row['key'])) |
| 295 | 295 | $badQuery[$row['table']] .= ' No Index Key Used;'; |
| 296 | 296 | if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
@@ -299,18 +299,18 @@ discard block |
||
| 299 | 299 | $badQuery[$row['table']] .= ' Using Temporary Table;'; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - if ( empty($badQuery) ) |
|
| 302 | + if (empty($badQuery)) |
|
| 303 | 303 | return true; |
| 304 | 304 | |
| 305 | - foreach($badQuery as $table=>$data ){ |
|
| 306 | - if(!empty($data)){ |
|
| 307 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
| 308 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
| 305 | + foreach ($badQuery as $table=>$data) { |
|
| 306 | + if (!empty($data)) { |
|
| 307 | + $warning = ' Table:'.$table.' Data:'.$data; |
|
| 308 | + if (!empty($GLOBALS['sugar_config']['check_query_log'])) { |
|
| 309 | 309 | $GLOBALS['log']->fatal($sql); |
| 310 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
| 310 | + $GLOBALS['log']->fatal('CHECK QUERY:'.$warning); |
|
| 311 | 311 | } |
| 312 | - else{ |
|
| 313 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
| 312 | + else { |
|
| 313 | + $GLOBALS['log']->warn('CHECK QUERY:'.$warning); |
|
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -327,19 +327,19 @@ discard block |
||
| 327 | 327 | $result = $this->query("DESCRIBE $tablename"); |
| 328 | 328 | |
| 329 | 329 | $columns = array(); |
| 330 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 330 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
| 331 | 331 | $name = strtolower($row['Field']); |
| 332 | - $columns[$name]['name']=$name; |
|
| 332 | + $columns[$name]['name'] = $name; |
|
| 333 | 333 | $matches = array(); |
| 334 | 334 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
| 335 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
| 336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
| 335 | + $columns[$name]['type'] = strtolower($matches[1][0]); |
|
| 336 | + if (isset($matches[2][0]) && in_array(strtolower($matches[1][0]), array('varchar', 'char', 'varchar2', 'int', 'decimal', 'float'))) |
|
| 337 | + $columns[$name]['len'] = strtolower($matches[2][0]); |
|
| 338 | + if (stristr($row['Extra'], 'auto_increment')) |
|
| 339 | 339 | $columns[$name]['auto_increment'] = '1'; |
| 340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 340 | + if ($row['Null'] == 'NO' && !stristr($row['Key'], 'PRI')) |
|
| 341 | 341 | $columns[$name]['required'] = 'true'; |
| 342 | - if (!empty($row['Default']) ) |
|
| 342 | + if (!empty($row['Default'])) |
|
| 343 | 343 | $columns[$name]['default'] = $row['Default']; |
| 344 | 344 | } |
| 345 | 345 | return $columns; |
@@ -348,20 +348,20 @@ discard block |
||
| 348 | 348 | /** |
| 349 | 349 | * @see DBManager::getFieldsArray() |
| 350 | 350 | */ |
| 351 | - public function getFieldsArray($result, $make_lower_case=false) |
|
| 351 | + public function getFieldsArray($result, $make_lower_case = false) |
|
| 352 | 352 | { |
| 353 | 353 | $field_array = array(); |
| 354 | 354 | |
| 355 | - if(empty($result)) |
|
| 355 | + if (empty($result)) |
|
| 356 | 356 | return 0; |
| 357 | 357 | |
| 358 | 358 | $fields = mysql_num_fields($result); |
| 359 | - for ($i=0; $i < $fields; $i++) { |
|
| 359 | + for ($i = 0; $i < $fields; $i++) { |
|
| 360 | 360 | $meta = mysql_fetch_field($result, $i); |
| 361 | 361 | if (!$meta) |
| 362 | 362 | return array(); |
| 363 | 363 | |
| 364 | - if($make_lower_case == true) |
|
| 364 | + if ($make_lower_case == true) |
|
| 365 | 365 | $meta->name = strtolower($meta->name); |
| 366 | 366 | |
| 367 | 367 | $field_array[] = $meta->name; |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | if (!empty($r)) { |
| 394 | 394 | while ($a = $this->fetchByAssoc($r)) { |
| 395 | 395 | $row = array_values($a); |
| 396 | - $tables[]=$row[0]; |
|
| 396 | + $tables[] = $row[0]; |
|
| 397 | 397 | } |
| 398 | 398 | return $tables; |
| 399 | 399 | } |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | |
| 420 | 420 | if ($this->getDatabase()) { |
| 421 | 421 | $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
| 422 | - if(empty($result)) return false; |
|
| 422 | + if (empty($result)) return false; |
|
| 423 | 423 | $row = $this->fetchByAssoc($result); |
| 424 | 424 | return !empty($row); |
| 425 | 425 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | if (!empty($r)) { |
| 441 | 441 | while ($a = $this->fetchByAssoc($r)) { |
| 442 | 442 | $row = array_values($a); |
| 443 | - $tables[]=$row[0]; |
|
| 443 | + $tables[] = $row[0]; |
|
| 444 | 444 | } |
| 445 | 445 | return $tables; |
| 446 | 446 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | */ |
| 454 | 454 | public function quote($string) |
| 455 | 455 | { |
| 456 | - if(is_array($string)) { |
|
| 456 | + if (is_array($string)) { |
|
| 457 | 457 | return $this->arrayQuote($string); |
| 458 | 458 | } |
| 459 | 459 | return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | { |
| 475 | 475 | global $sugar_config; |
| 476 | 476 | |
| 477 | - if(is_null($configOptions)) |
|
| 477 | + if (is_null($configOptions)) |
|
| 478 | 478 | $configOptions = $sugar_config['dbconfig']; |
| 479 | 479 | |
| 480 | 480 | if ($this->getOption('persistent')) { |
@@ -491,10 +491,10 @@ discard block |
||
| 491 | 491 | $configOptions['db_user_name'], |
| 492 | 492 | $configOptions['db_password'] |
| 493 | 493 | ); |
| 494 | - if(empty($this->database)) { |
|
| 494 | + if (empty($this->database)) { |
|
| 495 | 495 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
| 496 | - if($dieOnError) { |
|
| 497 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 496 | + if ($dieOnError) { |
|
| 497 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 498 | 498 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
| 499 | 499 | } else { |
| 500 | 500 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -504,15 +504,15 @@ discard block |
||
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | // Do not pass connection information because we have not connected yet |
| 507 | - if($this->database && $this->getOption('persistent')){ |
|
| 507 | + if ($this->database && $this->getOption('persistent')) { |
|
| 508 | 508 | $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
| 509 | 509 | . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
| 510 | 510 | . "in your config.php file</b>"; |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 514 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
| 515 | - if($dieOnError) { |
|
| 513 | + if (!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
| 514 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}: ".mysql_error($this->database)); |
|
| 515 | + if ($dieOnError) { |
|
| 516 | 516 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
| 517 | 517 | } else { |
| 518 | 518 | return false; |
@@ -523,12 +523,12 @@ discard block |
||
| 523 | 523 | mysql_query("SET CHARACTER SET utf8", $this->database); |
| 524 | 524 | $names = "SET NAMES 'utf8'"; |
| 525 | 525 | $collation = $this->getOption('collation'); |
| 526 | - if(!empty($collation)) { |
|
| 526 | + if (!empty($collation)) { |
|
| 527 | 527 | $names .= " COLLATE '$collation'"; |
| 528 | 528 | } |
| 529 | 529 | mysql_query($names, $this->database); |
| 530 | 530 | |
| 531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 531 | + if (!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 532 | 532 | $GLOBALS['log']->info("connected to db"); |
| 533 | 533 | $this->connectOptions = $configOptions; |
| 534 | 534 | |
@@ -544,16 +544,16 @@ discard block |
||
| 544 | 544 | */ |
| 545 | 545 | public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
| 546 | 546 | { |
| 547 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
| 547 | + $sql = parent::repairTableParams($tablename, $fielddefs, $indices, false, $engine); |
|
| 548 | 548 | |
| 549 | - if ( $sql == '' ) |
|
| 549 | + if ($sql == '') |
|
| 550 | 550 | return ''; |
| 551 | 551 | |
| 552 | - if ( stristr($sql,'create table') ) |
|
| 552 | + if (stristr($sql, 'create table')) |
|
| 553 | 553 | { |
| 554 | 554 | if ($execute) { |
| 555 | - $msg = "Error creating table: ".$tablename. ":"; |
|
| 556 | - $this->query($sql,true,$msg); |
|
| 555 | + $msg = "Error creating table: ".$tablename.":"; |
|
| 556 | + $this->query($sql, true, $msg); |
|
| 557 | 557 | } |
| 558 | 558 | return $sql; |
| 559 | 559 | } |
@@ -562,23 +562,23 @@ discard block |
||
| 562 | 562 | $match = array(); |
| 563 | 563 | preg_match_all('!/\*.*?\*/!is', $sql, $match); |
| 564 | 564 | $commentBlocks = $match[0]; |
| 565 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
| 565 | + $sql = preg_replace('!/\*.*?\*/!is', '', $sql); |
|
| 566 | 566 | |
| 567 | 567 | // now, we should only have alter table statements |
| 568 | 568 | // let's replace the 'alter table name' part with a comma |
| 569 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
| 569 | + $sql = preg_replace("!alter table $tablename!is", ', ', $sql); |
|
| 570 | 570 | |
| 571 | 571 | // re-add it at the beginning |
| 572 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
| 573 | - $sql = str_replace(";","",$sql); |
|
| 574 | - $sql = str_replace("\n","",$sql); |
|
| 572 | + $sql = substr_replace($sql, '', strpos($sql, ','), 1); |
|
| 573 | + $sql = str_replace(";", "", $sql); |
|
| 574 | + $sql = str_replace("\n", "", $sql); |
|
| 575 | 575 | $sql = "ALTER TABLE $tablename $sql"; |
| 576 | 576 | |
| 577 | - if ( $execute ) |
|
| 578 | - $this->query($sql,'Error with MySQL repair table'); |
|
| 577 | + if ($execute) |
|
| 578 | + $this->query($sql, 'Error with MySQL repair table'); |
|
| 579 | 579 | |
| 580 | 580 | // and re-add the comments at the beginning |
| 581 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
| 581 | + $sql = implode("\n", $commentBlocks)."\n".$sql."\n"; |
|
| 582 | 582 | |
| 583 | 583 | return $sql; |
| 584 | 584 | } |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | public function convert($string, $type, array $additional_parameters = array()) |
| 590 | 590 | { |
| 591 | 591 | $all_parameters = $additional_parameters; |
| 592 | - if(is_array($string)) { |
|
| 592 | + if (is_array($string)) { |
|
| 593 | 593 | $all_parameters = array_merge($string, $all_parameters); |
| 594 | 594 | } elseif (!is_null($string)) { |
| 595 | 595 | array_unshift($all_parameters, $string); |
@@ -602,17 +602,17 @@ discard block |
||
| 602 | 602 | case 'left': |
| 603 | 603 | return "LEFT($all_strings)"; |
| 604 | 604 | case 'date_format': |
| 605 | - if(empty($additional_parameters)) { |
|
| 605 | + if (empty($additional_parameters)) { |
|
| 606 | 606 | return "DATE_FORMAT($string,'%Y-%m-%d')"; |
| 607 | 607 | } else { |
| 608 | 608 | $format = $additional_parameters[0]; |
| 609 | - if($format[0] != "'") { |
|
| 609 | + if ($format[0] != "'") { |
|
| 610 | 610 | $format = $this->quoted($format); |
| 611 | 611 | } |
| 612 | 612 | return "DATE_FORMAT($string,$format)"; |
| 613 | 613 | } |
| 614 | 614 | case 'ifnull': |
| 615 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 615 | + if (empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
| 616 | 616 | $all_strings .= ",''"; |
| 617 | 617 | } |
| 618 | 618 | return "IFNULL($all_strings)"; |
@@ -631,7 +631,7 @@ discard block |
||
| 631 | 631 | case 'add_tz_offset' : |
| 632 | 632 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
| 633 | 633 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
| 634 | - return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
|
| 634 | + return $string.' '.$operation.' INTERVAL '.abs($getUserUTCOffset).' MINUTE'; |
|
| 635 | 635 | case 'avg': |
| 636 | 636 | return "avg($string)"; |
| 637 | 637 | } |
@@ -672,15 +672,15 @@ discard block |
||
| 672 | 672 | */ |
| 673 | 673 | protected function isEngineEnabled($engine) |
| 674 | 674 | { |
| 675 | - if(!is_string($engine)) return false; |
|
| 675 | + if (!is_string($engine)) return false; |
|
| 676 | 676 | |
| 677 | 677 | $engine = strtoupper($engine); |
| 678 | 678 | |
| 679 | 679 | $r = $this->query("SHOW ENGINES"); |
| 680 | 680 | |
| 681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
| 682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
| 683 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
| 681 | + while ($row = $this->fetchByAssoc($r)) |
|
| 682 | + if (strtoupper($row['Engine']) == $engine) |
|
| 683 | + return ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT'); |
|
| 684 | 684 | |
| 685 | 685 | return false; |
| 686 | 686 | } |
@@ -708,9 +708,9 @@ discard block |
||
| 708 | 708 | */ |
| 709 | 709 | public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
| 710 | 710 | { |
| 711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 711 | + if (empty($engine) && isset($fieldDefs['engine'])) |
|
| 712 | 712 | $engine = $fieldDefs['engine']; |
| 713 | - if ( !$this->isEngineEnabled($engine) ) |
|
| 713 | + if (!$this->isEngineEnabled($engine)) |
|
| 714 | 714 | $engine = ''; |
| 715 | 715 | |
| 716 | 716 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
@@ -723,13 +723,13 @@ discard block |
||
| 723 | 723 | |
| 724 | 724 | // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
| 725 | 725 | $collation = $this->getOption('collation'); |
| 726 | - if(empty($collation)) { |
|
| 726 | + if (empty($collation)) { |
|
| 727 | 727 | $collation = 'utf8_general_ci'; |
| 728 | 728 | } |
| 729 | 729 | $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
| 730 | 730 | |
| 731 | 731 | if (!empty($engine)) |
| 732 | - $sql.= " ENGINE=$engine"; |
|
| 732 | + $sql .= " ENGINE=$engine"; |
|
| 733 | 733 | |
| 734 | 734 | return $sql; |
| 735 | 735 | } |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | public function isTextType($type) |
| 742 | 742 | { |
| 743 | 743 | $type = $this->getColumnType(strtolower($type)); |
| 744 | - return in_array($type, array('blob','text','longblob', 'longtext')); |
|
| 744 | + return in_array($type, array('blob', 'text', 'longblob', 'longtext')); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -752,16 +752,16 @@ discard block |
||
| 752 | 752 | // always return as array for post-processing |
| 753 | 753 | $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
| 754 | 754 | |
| 755 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
| 755 | + if ($ref['colType'] == 'int' && !empty($fieldDef['len'])) { |
|
| 756 | 756 | $ref['colType'] .= "(".$fieldDef['len'].")"; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | // bug 22338 - don't set a default value on text or blob fields |
| 760 | - if ( isset($ref['default']) && |
|
| 760 | + if (isset($ref['default']) && |
|
| 761 | 761 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
| 762 | 762 | $ref['default'] = ''; |
| 763 | 763 | |
| 764 | - if ( $return_as_array ) |
|
| 764 | + if ($return_as_array) |
|
| 765 | 765 | return $ref; |
| 766 | 766 | else |
| 767 | 767 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
@@ -773,8 +773,8 @@ discard block |
||
| 773 | 773 | protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
| 774 | 774 | { |
| 775 | 775 | $columns = array(); |
| 776 | - if ($this->isFieldArray($fieldDefs)){ |
|
| 777 | - foreach ($fieldDefs as $def){ |
|
| 776 | + if ($this->isFieldArray($fieldDefs)) { |
|
| 777 | + foreach ($fieldDefs as $def) { |
|
| 778 | 778 | if ($action == 'drop') |
| 779 | 779 | $columns[] = $def['name']; |
| 780 | 780 | else |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | |
| 812 | 812 | $columns = array(); |
| 813 | 813 | foreach ($indices as $index) { |
| 814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 814 | + if (!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 815 | 815 | continue; |
| 816 | 816 | if (isset($index['source']) && $index['source'] != 'db') |
| 817 | 817 | continue; |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | * that this can easily be fixed by referring to db dictionary |
| 842 | 842 | * to find the correct primary field name |
| 843 | 843 | */ |
| 844 | - if ( $alter_table ) |
|
| 844 | + if ($alter_table) |
|
| 845 | 845 | $columns[] = " INDEX $name ($fields)"; |
| 846 | 846 | else |
| 847 | 847 | $columns[] = " KEY $name ($fields)"; |
@@ -850,13 +850,13 @@ discard block |
||
| 850 | 850 | if ($this->full_text_indexing_installed()) |
| 851 | 851 | $columns[] = " FULLTEXT ($fields)"; |
| 852 | 852 | else |
| 853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:', $name); |
|
| 854 | 854 | break; |
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | $columns = implode(", $alter_action ", $columns); |
| 858 | - if(!empty($alter_action)){ |
|
| 859 | - $columns = $alter_action . ' '. $columns; |
|
| 858 | + if (!empty($alter_action)) { |
|
| 859 | + $columns = $alter_action.' '.$columns; |
|
| 860 | 860 | } |
| 861 | 861 | return $columns; |
| 862 | 862 | } |
@@ -878,7 +878,7 @@ discard block |
||
| 878 | 878 | public function setAutoIncrementStart($table, $field_name, $start_value) |
| 879 | 879 | { |
| 880 | 880 | $start_value = (int)$start_value; |
| 881 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 881 | + return $this->query("ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -907,18 +907,18 @@ discard block |
||
| 907 | 907 | $result = $this->query("SHOW INDEX FROM $tablename"); |
| 908 | 908 | |
| 909 | 909 | $indices = array(); |
| 910 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
| 911 | - $index_type='index'; |
|
| 912 | - if ($row['Key_name'] =='PRIMARY') { |
|
| 913 | - $index_type='primary'; |
|
| 910 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
| 911 | + $index_type = 'index'; |
|
| 912 | + if ($row['Key_name'] == 'PRIMARY') { |
|
| 913 | + $index_type = 'primary'; |
|
| 914 | 914 | } |
| 915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
| 916 | - $index_type='unique'; |
|
| 915 | + elseif ($row['Non_unique'] == '0') { |
|
| 916 | + $index_type = 'unique'; |
|
| 917 | 917 | } |
| 918 | 918 | $name = strtolower($row['Key_name']); |
| 919 | - $indices[$name]['name']=$name; |
|
| 920 | - $indices[$name]['type']=$index_type; |
|
| 921 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
| 919 | + $indices[$name]['name'] = $name; |
|
| 920 | + $indices[$name]['type'] = $index_type; |
|
| 921 | + $indices[$name]['fields'][] = strtolower($row['Column_name']); |
|
| 922 | 922 | } |
| 923 | 923 | return $indices; |
| 924 | 924 | } |
@@ -929,11 +929,11 @@ discard block |
||
| 929 | 929 | public function add_drop_constraint($table, $definition, $drop = false) |
| 930 | 930 | { |
| 931 | 931 | $type = $definition['type']; |
| 932 | - $fields = implode(',',$definition['fields']); |
|
| 932 | + $fields = implode(',', $definition['fields']); |
|
| 933 | 933 | $name = $definition['name']; |
| 934 | 934 | $sql = ''; |
| 935 | 935 | |
| 936 | - switch ($type){ |
|
| 936 | + switch ($type) { |
|
| 937 | 937 | // generic indices |
| 938 | 938 | case 'index': |
| 939 | 939 | case 'alternate_key': |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | */ |
| 978 | 978 | public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
| 979 | 979 | { |
| 980 | - if(stripos($sql, ' LIMIT ') === false) { |
|
| 980 | + if (stripos($sql, ' LIMIT ') === false) { |
|
| 981 | 981 | // little optimization to just fetch one row |
| 982 | 982 | $sql .= " LIMIT 0,1"; |
| 983 | 983 | } |
@@ -997,13 +997,13 @@ discard block |
||
| 997 | 997 | */ |
| 998 | 998 | public function massageFieldDef(&$fieldDef, $tablename) |
| 999 | 999 | { |
| 1000 | - parent::massageFieldDef($fieldDef,$tablename); |
|
| 1000 | + parent::massageFieldDef($fieldDef, $tablename); |
|
| 1001 | 1001 | |
| 1002 | - if ( isset($fieldDef['default']) && |
|
| 1002 | + if (isset($fieldDef['default']) && |
|
| 1003 | 1003 | ($fieldDef['dbType'] == 'text' |
| 1004 | 1004 | || $fieldDef['dbType'] == 'blob' |
| 1005 | 1005 | || $fieldDef['dbType'] == 'longtext' |
| 1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
| 1006 | + || $fieldDef['dbType'] == 'longblob')) |
|
| 1007 | 1007 | unset($fieldDef['default']); |
| 1008 | 1008 | if ($fieldDef['dbType'] == 'uint') |
| 1009 | 1009 | $fieldDef['len'] = '10'; |
@@ -1011,22 +1011,22 @@ discard block |
||
| 1011 | 1011 | $fieldDef['len'] = '20'; |
| 1012 | 1012 | if ($fieldDef['dbType'] == 'bool') |
| 1013 | 1013 | $fieldDef['type'] = 'tinyint'; |
| 1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1014 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default'])) |
|
| 1015 | 1015 | $fieldDef['default'] = '0'; |
| 1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1016 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len'])) |
|
| 1017 | 1017 | $fieldDef['len'] = '255'; |
| 1018 | 1018 | if ($fieldDef['dbType'] == 'uint') |
| 1019 | 1019 | $fieldDef['len'] = '10'; |
| 1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1020 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len'])) |
|
| 1021 | 1021 | $fieldDef['len'] = '11'; |
| 1022 | 1022 | |
| 1023 | - if($fieldDef['dbType'] == 'decimal') { |
|
| 1024 | - if(isset($fieldDef['len'])) { |
|
| 1025 | - if(strstr($fieldDef['len'], ",") === false) { |
|
| 1023 | + if ($fieldDef['dbType'] == 'decimal') { |
|
| 1024 | + if (isset($fieldDef['len'])) { |
|
| 1025 | + if (strstr($fieldDef['len'], ",") === false) { |
|
| 1026 | 1026 | $fieldDef['len'] .= ",0"; |
| 1027 | 1027 | } |
| 1028 | 1028 | } else { |
| 1029 | - $fieldDef['len'] = '10,0'; |
|
| 1029 | + $fieldDef['len'] = '10,0'; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | } |
| 1032 | 1032 | } |
@@ -1046,8 +1046,8 @@ discard block |
||
| 1046 | 1046 | { |
| 1047 | 1047 | $sql = array(); |
| 1048 | 1048 | foreach ($indexes as $index) { |
| 1049 | - $name =$index['name']; |
|
| 1050 | - if($execute) { |
|
| 1049 | + $name = $index['name']; |
|
| 1050 | + if ($execute) { |
|
| 1051 | 1051 | unset(self::$index_descriptions[$tablename][$name]); |
| 1052 | 1052 | } |
| 1053 | 1053 | if ($index['type'] == 'primary') { |
@@ -1057,8 +1057,8 @@ discard block |
||
| 1057 | 1057 | } |
| 1058 | 1058 | } |
| 1059 | 1059 | if (!empty($sql)) { |
| 1060 | - $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
|
| 1061 | - if($execute) |
|
| 1060 | + $sql = "ALTER TABLE $tablename ".join(",", $sql).";"; |
|
| 1061 | + if ($execute) |
|
| 1062 | 1062 | $this->query($sql); |
| 1063 | 1063 | } else { |
| 1064 | 1064 | $sql = ''; |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | $q = "SHOW COLLATION LIKE 'utf8%'"; |
| 1085 | 1085 | $r = $this->query($q); |
| 1086 | 1086 | $res = array(); |
| 1087 | - while($a = $this->fetchByAssoc($r)) { |
|
| 1087 | + while ($a = $this->fetchByAssoc($r)) { |
|
| 1088 | 1088 | $res[] = $a['Collation']; |
| 1089 | 1089 | } |
| 1090 | 1090 | return $res; |
@@ -1104,13 +1104,13 @@ discard block |
||
| 1104 | 1104 | public function emptyValue($type) |
| 1105 | 1105 | { |
| 1106 | 1106 | $ctype = $this->getColumnType($type); |
| 1107 | - if($ctype == "datetime") { |
|
| 1107 | + if ($ctype == "datetime") { |
|
| 1108 | 1108 | return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
| 1109 | 1109 | } |
| 1110 | - if($ctype == "date") { |
|
| 1110 | + if ($ctype == "date") { |
|
| 1111 | 1111 | return $this->convert($this->quoted("0000-00-00"), "date"); |
| 1112 | 1112 | } |
| 1113 | - if($ctype == "time") { |
|
| 1113 | + if ($ctype == "time") { |
|
| 1114 | 1114 | return $this->convert($this->quoted("00:00:00"), "time"); |
| 1115 | 1115 | } |
| 1116 | 1116 | return parent::emptyValue($type); |
@@ -1122,13 +1122,13 @@ discard block |
||
| 1122 | 1122 | */ |
| 1123 | 1123 | public function lastDbError() |
| 1124 | 1124 | { |
| 1125 | - if($this->database) { |
|
| 1126 | - if(mysql_errno($this->database)) { |
|
| 1125 | + if ($this->database) { |
|
| 1126 | + if (mysql_errno($this->database)) { |
|
| 1127 | 1127 | return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
| 1128 | 1128 | } |
| 1129 | 1129 | } else { |
| 1130 | - $err = mysql_error(); |
|
| 1131 | - if($err) { |
|
| 1130 | + $err = mysql_error(); |
|
| 1131 | + if ($err) { |
|
| 1132 | 1132 | return $err; |
| 1133 | 1133 | } |
| 1134 | 1134 | } |
@@ -1141,7 +1141,7 @@ discard block |
||
| 1141 | 1141 | */ |
| 1142 | 1142 | protected function quoteTerm($term) |
| 1143 | 1143 | { |
| 1144 | - if(strpos($term, ' ') !== false) { |
|
| 1144 | + if (strpos($term, ' ') !== false) { |
|
| 1145 | 1145 | return '"'.$term.'"'; |
| 1146 | 1146 | } |
| 1147 | 1147 | return $term; |
@@ -1157,16 +1157,16 @@ discard block |
||
| 1157 | 1157 | public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
| 1158 | 1158 | { |
| 1159 | 1159 | $condition = array(); |
| 1160 | - foreach($terms as $term) { |
|
| 1160 | + foreach ($terms as $term) { |
|
| 1161 | 1161 | $condition[] = $this->quoteTerm($term); |
| 1162 | 1162 | } |
| 1163 | - foreach($must_terms as $term) { |
|
| 1163 | + foreach ($must_terms as $term) { |
|
| 1164 | 1164 | $condition[] = "+".$this->quoteTerm($term); |
| 1165 | 1165 | } |
| 1166 | - foreach($exclude_terms as $term) { |
|
| 1166 | + foreach ($exclude_terms as $term) { |
|
| 1167 | 1167 | $condition[] = "-".$this->quoteTerm($term); |
| 1168 | 1168 | } |
| 1169 | - $condition = $this->quoted(join(" ",$condition)); |
|
| 1169 | + $condition = $this->quoted(join(" ", $condition)); |
|
| 1170 | 1170 | return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
| 1171 | 1171 | } |
| 1172 | 1172 | |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | { |
| 1179 | 1179 | $charsets = array(); |
| 1180 | 1180 | $res = $this->query("show variables like 'character\\_set\\_%'"); |
| 1181 | - while($row = $this->fetchByAssoc($res)) { |
|
| 1181 | + while ($row = $this->fetchByAssoc($res)) { |
|
| 1182 | 1182 | $charsets[$row['Variable_name']] = $row['Value']; |
| 1183 | 1183 | } |
| 1184 | 1184 | return $charsets; |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | { |
| 1189 | 1189 | $charsets = $this->getCharsetInfo(); |
| 1190 | 1190 | $charset_str = array(); |
| 1191 | - foreach($charsets as $name => $value) { |
|
| 1191 | + foreach ($charsets as $name => $value) { |
|
| 1192 | 1192 | $charset_str[] = "$name = $value"; |
| 1193 | 1193 | } |
| 1194 | 1194 | return array( |
@@ -1210,18 +1210,18 @@ discard block |
||
| 1210 | 1210 | { |
| 1211 | 1211 | $this->log->debug("creating temp table for [$table]..."); |
| 1212 | 1212 | $result = $this->query("SHOW CREATE TABLE {$table}"); |
| 1213 | - if(empty($result)) { |
|
| 1213 | + if (empty($result)) { |
|
| 1214 | 1214 | return false; |
| 1215 | 1215 | } |
| 1216 | 1216 | $row = $this->fetchByAssoc($result); |
| 1217 | - if(empty($row) || empty($row['Create Table'])) { |
|
| 1217 | + if (empty($row) || empty($row['Create Table'])) { |
|
| 1218 | 1218 | return false; |
| 1219 | 1219 | } |
| 1220 | 1220 | $create = $row['Create Table']; |
| 1221 | 1221 | // rewrite DDL with _temp name |
| 1222 | 1222 | $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
| 1223 | 1223 | $r2 = $this->query($tempTableQuery); |
| 1224 | - if(empty($r2)) { |
|
| 1224 | + if (empty($r2)) { |
|
| 1225 | 1225 | return false; |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -1243,11 +1243,11 @@ discard block |
||
| 1243 | 1243 | $this->log->debug("verifying ALTER TABLE"); |
| 1244 | 1244 | // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
| 1245 | 1245 | // over to the temp tables |
| 1246 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1246 | + if (strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
| 1247 | 1247 | $this->log->debug("Skipping DROP PRIMARY KEY"); |
| 1248 | 1248 | return ''; |
| 1249 | 1249 | } |
| 1250 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1250 | + if (!$this->makeTempTableCopy($table)) { |
|
| 1251 | 1251 | return 'Could not create temp table copy'; |
| 1252 | 1252 | } |
| 1253 | 1253 | |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | $this->log->debug('testing query: ['.$query.']'); |
| 1256 | 1256 | $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
| 1257 | 1257 | if (strpos($tempTableTestQuery, 'idx') === false) { |
| 1258 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1258 | + if (strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1259 | 1259 | return 'Could not use a temp table to test query!'; |
| 1260 | 1260 | } |
| 1261 | 1261 | |
@@ -1268,7 +1268,7 @@ discard block |
||
| 1268 | 1268 | $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
| 1269 | 1269 | } |
| 1270 | 1270 | $mysqlError = $this->getL(); |
| 1271 | - if(!empty($mysqlError)) { |
|
| 1271 | + if (!empty($mysqlError)) { |
|
| 1272 | 1272 | return $mysqlError; |
| 1273 | 1273 | } |
| 1274 | 1274 | $this->dropTableName("{$table}__uw_temp"); |
@@ -1280,13 +1280,13 @@ discard block |
||
| 1280 | 1280 | { |
| 1281 | 1281 | $this->log->debug("verifying $querytype statement"); |
| 1282 | 1282 | |
| 1283 | - if(!$this->makeTempTableCopy($table)) { |
|
| 1283 | + if (!$this->makeTempTableCopy($table)) { |
|
| 1284 | 1284 | return 'Could not create temp table copy'; |
| 1285 | 1285 | } |
| 1286 | 1286 | // test the query on the test table |
| 1287 | 1287 | $this->log->debug('testing query: ['.$query.']'); |
| 1288 | 1288 | $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
| 1289 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1289 | + if (strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
| 1290 | 1290 | return 'Could not use a temp table to test query!'; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
@@ -1366,11 +1366,11 @@ discard block |
||
| 1366 | 1366 | public function userExists($username) |
| 1367 | 1367 | { |
| 1368 | 1368 | $db = $this->getOne("SELECT DATABASE()"); |
| 1369 | - if(!$this->selectDb("mysql")) { |
|
| 1369 | + if (!$this->selectDb("mysql")) { |
|
| 1370 | 1370 | return false; |
| 1371 | 1371 | } |
| 1372 | 1372 | $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
| 1373 | - if(!$this->selectDb($db)) { |
|
| 1373 | + if (!$this->selectDb($db)) { |
|
| 1374 | 1374 | $this->checkError("Cannot select database $db", true); |
| 1375 | 1375 | } |
| 1376 | 1376 | return !empty($user); |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | IDENTIFIED BY '{$qpassword}';", true); |
| 1393 | 1393 | |
| 1394 | 1394 | $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
| 1395 | - if($host_name != 'localhost') { |
|
| 1395 | + if ($host_name != 'localhost') { |
|
| 1396 | 1396 | $this->createDbUser($database_name, "localhost", $user, $password); |
| 1397 | 1397 | } |
| 1398 | 1398 | } |
@@ -1438,10 +1438,10 @@ discard block |
||
| 1438 | 1438 | public function canInstall() |
| 1439 | 1439 | { |
| 1440 | 1440 | $db_version = $this->version(); |
| 1441 | - if(empty($db_version)) { |
|
| 1441 | + if (empty($db_version)) { |
|
| 1442 | 1442 | return array('ERR_DB_VERSION_FAILURE'); |
| 1443 | 1443 | } |
| 1444 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
| 1444 | + if (version_compare($db_version, '4.1.2') < 0) { |
|
| 1445 | 1445 | return array('ERR_DB_MYSQL_VERSION', $db_version); |
| 1446 | 1446 | } |
| 1447 | 1447 | return true; |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -185,8 +187,9 @@ discard block |
||
| 185 | 187 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
| 186 | 188 | |
| 187 | 189 | |
| 188 | - if($keepResult) |
|
| 189 | - $this->lastResult = $result; |
|
| 190 | + if($keepResult) { |
|
| 191 | + $this->lastResult = $result; |
|
| 192 | + } |
|
| 190 | 193 | |
| 191 | 194 | $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
| 192 | 195 | return $result; |
@@ -236,8 +239,9 @@ discard block |
||
| 236 | 239 | */ |
| 237 | 240 | protected function freeDbResult($dbResult) |
| 238 | 241 | { |
| 239 | - if(!empty($dbResult)) |
|
| 240 | - mysql_free_result($dbResult); |
|
| 242 | + if(!empty($dbResult)) { |
|
| 243 | + mysql_free_result($dbResult); |
|
| 244 | + } |
|
| 241 | 245 | } |
| 242 | 246 | |
| 243 | 247 | |
@@ -260,8 +264,9 @@ discard block |
||
| 260 | 264 | { |
| 261 | 265 | $start = (int)$start; |
| 262 | 266 | $count = (int)$count; |
| 263 | - if ($start < 0) |
|
| 264 | - $start = 0; |
|
| 267 | + if ($start < 0) { |
|
| 268 | + $start = 0; |
|
| 269 | + } |
|
| 265 | 270 | $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
| 266 | 271 | |
| 267 | 272 | $sql = "$sql LIMIT $start,$count"; |
@@ -286,21 +291,27 @@ discard block |
||
| 286 | 291 | $result = $this->query('EXPLAIN ' . $sql); |
| 287 | 292 | $badQuery = array(); |
| 288 | 293 | while ($row = $this->fetchByAssoc($result)) { |
| 289 | - if (empty($row['table'])) |
|
| 290 | - continue; |
|
| 294 | + if (empty($row['table'])) { |
|
| 295 | + continue; |
|
| 296 | + } |
|
| 291 | 297 | $badQuery[$row['table']] = ''; |
| 292 | - if (strtoupper($row['type']) == 'ALL') |
|
| 293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 294 | - if (empty($row['key'])) |
|
| 295 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 296 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
| 297 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 298 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
| 299 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 298 | + if (strtoupper($row['type']) == 'ALL') { |
|
| 299 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
| 300 | + } |
|
| 301 | + if (empty($row['key'])) { |
|
| 302 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
| 303 | + } |
|
| 304 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) { |
|
| 305 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
| 306 | + } |
|
| 307 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) { |
|
| 308 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
| 309 | + } |
|
| 300 | 310 | } |
| 301 | 311 | |
| 302 | - if ( empty($badQuery) ) |
|
| 303 | - return true; |
|
| 312 | + if ( empty($badQuery) ) { |
|
| 313 | + return true; |
|
| 314 | + } |
|
| 304 | 315 | |
| 305 | 316 | foreach($badQuery as $table=>$data ){ |
| 306 | 317 | if(!empty($data)){ |
@@ -308,8 +319,7 @@ discard block |
||
| 308 | 319 | if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
| 309 | 320 | $GLOBALS['log']->fatal($sql); |
| 310 | 321 | $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
| 311 | - } |
|
| 312 | - else{ |
|
| 322 | + } else{ |
|
| 313 | 323 | $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
| 314 | 324 | } |
| 315 | 325 | } |
@@ -333,14 +343,18 @@ discard block |
||
| 333 | 343 | $matches = array(); |
| 334 | 344 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
| 335 | 345 | $columns[$name]['type']=strtolower($matches[1][0]); |
| 336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
| 337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
| 339 | - $columns[$name]['auto_increment'] = '1'; |
|
| 340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
| 341 | - $columns[$name]['required'] = 'true'; |
|
| 342 | - if (!empty($row['Default']) ) |
|
| 343 | - $columns[$name]['default'] = $row['Default']; |
|
| 346 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) { |
|
| 347 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
| 348 | + } |
|
| 349 | + if ( stristr($row['Extra'],'auto_increment') ) { |
|
| 350 | + $columns[$name]['auto_increment'] = '1'; |
|
| 351 | + } |
|
| 352 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) { |
|
| 353 | + $columns[$name]['required'] = 'true'; |
|
| 354 | + } |
|
| 355 | + if (!empty($row['Default']) ) { |
|
| 356 | + $columns[$name]['default'] = $row['Default']; |
|
| 357 | + } |
|
| 344 | 358 | } |
| 345 | 359 | return $columns; |
| 346 | 360 | } |
@@ -352,17 +366,20 @@ discard block |
||
| 352 | 366 | { |
| 353 | 367 | $field_array = array(); |
| 354 | 368 | |
| 355 | - if(empty($result)) |
|
| 356 | - return 0; |
|
| 369 | + if(empty($result)) { |
|
| 370 | + return 0; |
|
| 371 | + } |
|
| 357 | 372 | |
| 358 | 373 | $fields = mysql_num_fields($result); |
| 359 | 374 | for ($i=0; $i < $fields; $i++) { |
| 360 | 375 | $meta = mysql_fetch_field($result, $i); |
| 361 | - if (!$meta) |
|
| 362 | - return array(); |
|
| 376 | + if (!$meta) { |
|
| 377 | + return array(); |
|
| 378 | + } |
|
| 363 | 379 | |
| 364 | - if($make_lower_case == true) |
|
| 365 | - $meta->name = strtolower($meta->name); |
|
| 380 | + if($make_lower_case == true) { |
|
| 381 | + $meta->name = strtolower($meta->name); |
|
| 382 | + } |
|
| 366 | 383 | |
| 367 | 384 | $field_array[] = $meta->name; |
| 368 | 385 | } |
@@ -375,7 +392,9 @@ discard block |
||
| 375 | 392 | */ |
| 376 | 393 | public function fetchRow($result) |
| 377 | 394 | { |
| 378 | - if (empty($result)) return false; |
|
| 395 | + if (empty($result)) { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 379 | 398 | |
| 380 | 399 | return mysql_fetch_assoc($result); |
| 381 | 400 | } |
@@ -419,7 +438,9 @@ discard block |
||
| 419 | 438 | |
| 420 | 439 | if ($this->getDatabase()) { |
| 421 | 440 | $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
| 422 | - if(empty($result)) return false; |
|
| 441 | + if(empty($result)) { |
|
| 442 | + return false; |
|
| 443 | + } |
|
| 423 | 444 | $row = $this->fetchByAssoc($result); |
| 424 | 445 | return !empty($row); |
| 425 | 446 | } |
@@ -474,8 +495,9 @@ discard block |
||
| 474 | 495 | { |
| 475 | 496 | global $sugar_config; |
| 476 | 497 | |
| 477 | - if(is_null($configOptions)) |
|
| 478 | - $configOptions = $sugar_config['dbconfig']; |
|
| 498 | + if(is_null($configOptions)) { |
|
| 499 | + $configOptions = $sugar_config['dbconfig']; |
|
| 500 | + } |
|
| 479 | 501 | |
| 480 | 502 | if ($this->getOption('persistent')) { |
| 481 | 503 | $this->database = @mysql_pconnect( |
@@ -528,8 +550,9 @@ discard block |
||
| 528 | 550 | } |
| 529 | 551 | mysql_query($names, $this->database); |
| 530 | 552 | |
| 531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
| 532 | - $GLOBALS['log']->info("connected to db"); |
|
| 553 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) { |
|
| 554 | + $GLOBALS['log']->info("connected to db"); |
|
| 555 | + } |
|
| 533 | 556 | $this->connectOptions = $configOptions; |
| 534 | 557 | |
| 535 | 558 | $GLOBALS['log']->info("Connect:".$this->database); |
@@ -546,8 +569,9 @@ discard block |
||
| 546 | 569 | { |
| 547 | 570 | $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
| 548 | 571 | |
| 549 | - if ( $sql == '' ) |
|
| 550 | - return ''; |
|
| 572 | + if ( $sql == '' ) { |
|
| 573 | + return ''; |
|
| 574 | + } |
|
| 551 | 575 | |
| 552 | 576 | if ( stristr($sql,'create table') ) |
| 553 | 577 | { |
@@ -574,8 +598,9 @@ discard block |
||
| 574 | 598 | $sql = str_replace("\n","",$sql); |
| 575 | 599 | $sql = "ALTER TABLE $tablename $sql"; |
| 576 | 600 | |
| 577 | - if ( $execute ) |
|
| 578 | - $this->query($sql,'Error with MySQL repair table'); |
|
| 601 | + if ( $execute ) { |
|
| 602 | + $this->query($sql,'Error with MySQL repair table'); |
|
| 603 | + } |
|
| 579 | 604 | |
| 580 | 605 | // and re-add the comments at the beginning |
| 581 | 606 | $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
@@ -672,15 +697,18 @@ discard block |
||
| 672 | 697 | */ |
| 673 | 698 | protected function isEngineEnabled($engine) |
| 674 | 699 | { |
| 675 | - if(!is_string($engine)) return false; |
|
| 700 | + if(!is_string($engine)) { |
|
| 701 | + return false; |
|
| 702 | + } |
|
| 676 | 703 | |
| 677 | 704 | $engine = strtoupper($engine); |
| 678 | 705 | |
| 679 | 706 | $r = $this->query("SHOW ENGINES"); |
| 680 | 707 | |
| 681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
| 682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
| 708 | + while ( $row = $this->fetchByAssoc($r) ) { |
|
| 709 | + if ( strtoupper($row['Engine']) == $engine ) |
|
| 683 | 710 | return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
| 711 | + } |
|
| 684 | 712 | |
| 685 | 713 | return false; |
| 686 | 714 | } |
@@ -708,18 +736,22 @@ discard block |
||
| 708 | 736 | */ |
| 709 | 737 | public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
| 710 | 738 | { |
| 711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
| 712 | - $engine = $fieldDefs['engine']; |
|
| 713 | - if ( !$this->isEngineEnabled($engine) ) |
|
| 714 | - $engine = ''; |
|
| 739 | + if ( empty($engine) && isset($fieldDefs['engine'])) { |
|
| 740 | + $engine = $fieldDefs['engine']; |
|
| 741 | + } |
|
| 742 | + if ( !$this->isEngineEnabled($engine) ) { |
|
| 743 | + $engine = ''; |
|
| 744 | + } |
|
| 715 | 745 | |
| 716 | 746 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
| 717 | - if (empty($columns)) |
|
| 718 | - return false; |
|
| 747 | + if (empty($columns)) { |
|
| 748 | + return false; |
|
| 749 | + } |
|
| 719 | 750 | |
| 720 | 751 | $keys = $this->keysSQL($indices); |
| 721 | - if (!empty($keys)) |
|
| 722 | - $keys = ",$keys"; |
|
| 752 | + if (!empty($keys)) { |
|
| 753 | + $keys = ",$keys"; |
|
| 754 | + } |
|
| 723 | 755 | |
| 724 | 756 | // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
| 725 | 757 | $collation = $this->getOption('collation'); |
@@ -728,8 +760,9 @@ discard block |
||
| 728 | 760 | } |
| 729 | 761 | $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
| 730 | 762 | |
| 731 | - if (!empty($engine)) |
|
| 732 | - $sql.= " ENGINE=$engine"; |
|
| 763 | + if (!empty($engine)) { |
|
| 764 | + $sql.= " ENGINE=$engine"; |
|
| 765 | + } |
|
| 733 | 766 | |
| 734 | 767 | return $sql; |
| 735 | 768 | } |
@@ -758,13 +791,15 @@ discard block |
||
| 758 | 791 | |
| 759 | 792 | // bug 22338 - don't set a default value on text or blob fields |
| 760 | 793 | if ( isset($ref['default']) && |
| 761 | - in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
|
| 762 | - $ref['default'] = ''; |
|
| 794 | + in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) { |
|
| 795 | + $ref['default'] = ''; |
|
| 796 | + } |
|
| 763 | 797 | |
| 764 | - if ( $return_as_array ) |
|
| 765 | - return $ref; |
|
| 766 | - else |
|
| 767 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 798 | + if ( $return_as_array ) { |
|
| 799 | + return $ref; |
|
| 800 | + } else { |
|
| 801 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
| 802 | + } |
|
| 768 | 803 | } |
| 769 | 804 | |
| 770 | 805 | /** |
@@ -775,16 +810,18 @@ discard block |
||
| 775 | 810 | $columns = array(); |
| 776 | 811 | if ($this->isFieldArray($fieldDefs)){ |
| 777 | 812 | foreach ($fieldDefs as $def){ |
| 778 | - if ($action == 'drop') |
|
| 779 | - $columns[] = $def['name']; |
|
| 780 | - else |
|
| 781 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 813 | + if ($action == 'drop') { |
|
| 814 | + $columns[] = $def['name']; |
|
| 815 | + } else { |
|
| 816 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
| 817 | + } |
|
| 782 | 818 | } |
| 783 | 819 | } else { |
| 784 | - if ($action == 'drop') |
|
| 785 | - $columns[] = $fieldDefs['name']; |
|
| 786 | - else |
|
| 787 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 820 | + if ($action == 'drop') { |
|
| 821 | + $columns[] = $fieldDefs['name']; |
|
| 822 | + } else { |
|
| 823 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
| 824 | + } |
|
| 788 | 825 | } |
| 789 | 826 | |
| 790 | 827 | return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
@@ -806,23 +843,27 @@ discard block |
||
| 806 | 843 | { |
| 807 | 844 | // check if the passed value is an array of fields. |
| 808 | 845 | // if not, convert it into an array |
| 809 | - if (!$this->isFieldArray($indices)) |
|
| 810 | - $indices[] = $indices; |
|
| 846 | + if (!$this->isFieldArray($indices)) { |
|
| 847 | + $indices[] = $indices; |
|
| 848 | + } |
|
| 811 | 849 | |
| 812 | 850 | $columns = array(); |
| 813 | 851 | foreach ($indices as $index) { |
| 814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
| 815 | - continue; |
|
| 816 | - if (isset($index['source']) && $index['source'] != 'db') |
|
| 817 | - continue; |
|
| 852 | + if(!empty($index['db']) && $index['db'] != $this->dbType) { |
|
| 853 | + continue; |
|
| 854 | + } |
|
| 855 | + if (isset($index['source']) && $index['source'] != 'db') { |
|
| 856 | + continue; |
|
| 857 | + } |
|
| 818 | 858 | |
| 819 | 859 | $type = $index['type']; |
| 820 | 860 | $name = $index['name']; |
| 821 | 861 | |
| 822 | - if (is_array($index['fields'])) |
|
| 823 | - $fields = implode(", ", $index['fields']); |
|
| 824 | - else |
|
| 825 | - $fields = $index['fields']; |
|
| 862 | + if (is_array($index['fields'])) { |
|
| 863 | + $fields = implode(", ", $index['fields']); |
|
| 864 | + } else { |
|
| 865 | + $fields = $index['fields']; |
|
| 866 | + } |
|
| 826 | 867 | |
| 827 | 868 | switch ($type) { |
| 828 | 869 | case 'unique': |
@@ -841,16 +882,18 @@ discard block |
||
| 841 | 882 | * that this can easily be fixed by referring to db dictionary |
| 842 | 883 | * to find the correct primary field name |
| 843 | 884 | */ |
| 844 | - if ( $alter_table ) |
|
| 845 | - $columns[] = " INDEX $name ($fields)"; |
|
| 846 | - else |
|
| 847 | - $columns[] = " KEY $name ($fields)"; |
|
| 885 | + if ( $alter_table ) { |
|
| 886 | + $columns[] = " INDEX $name ($fields)"; |
|
| 887 | + } else { |
|
| 888 | + $columns[] = " KEY $name ($fields)"; |
|
| 889 | + } |
|
| 848 | 890 | break; |
| 849 | 891 | case 'fulltext': |
| 850 | - if ($this->full_text_indexing_installed()) |
|
| 851 | - $columns[] = " FULLTEXT ($fields)"; |
|
| 852 | - else |
|
| 853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 892 | + if ($this->full_text_indexing_installed()) { |
|
| 893 | + $columns[] = " FULLTEXT ($fields)"; |
|
| 894 | + } else { |
|
| 895 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
| 896 | + } |
|
| 854 | 897 | break; |
| 855 | 898 | } |
| 856 | 899 | } |
@@ -892,8 +935,9 @@ discard block |
||
| 892 | 935 | { |
| 893 | 936 | $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
| 894 | 937 | $row = $this->fetchByAssoc($result); |
| 895 | - if (!empty($row['Auto_increment'])) |
|
| 896 | - return $row['Auto_increment']; |
|
| 938 | + if (!empty($row['Auto_increment'])) { |
|
| 939 | + return $row['Auto_increment']; |
|
| 940 | + } |
|
| 897 | 941 | |
| 898 | 942 | return ""; |
| 899 | 943 | } |
@@ -911,8 +955,7 @@ discard block |
||
| 911 | 955 | $index_type='index'; |
| 912 | 956 | if ($row['Key_name'] =='PRIMARY') { |
| 913 | 957 | $index_type='primary'; |
| 914 | - } |
|
| 915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
| 958 | + } elseif ( $row['Non_unique'] == '0' ) { |
|
| 916 | 959 | $index_type='unique'; |
| 917 | 960 | } |
| 918 | 961 | $name = strtolower($row['Key_name']); |
@@ -938,29 +981,33 @@ discard block |
||
| 938 | 981 | case 'index': |
| 939 | 982 | case 'alternate_key': |
| 940 | 983 | case 'clustered': |
| 941 | - if ($drop) |
|
| 942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 943 | - else |
|
| 944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 984 | + if ($drop) { |
|
| 985 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
| 986 | + } else { |
|
| 987 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
| 988 | + } |
|
| 945 | 989 | break; |
| 946 | 990 | // constraints as indices |
| 947 | 991 | case 'unique': |
| 948 | - if ($drop) |
|
| 949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 950 | - else |
|
| 951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 992 | + if ($drop) { |
|
| 993 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
| 994 | + } else { |
|
| 995 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
| 996 | + } |
|
| 952 | 997 | break; |
| 953 | 998 | case 'primary': |
| 954 | - if ($drop) |
|
| 955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 956 | - else |
|
| 957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 999 | + if ($drop) { |
|
| 1000 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
| 1001 | + } else { |
|
| 1002 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
| 1003 | + } |
|
| 958 | 1004 | break; |
| 959 | 1005 | case 'foreign': |
| 960 | - if ($drop) |
|
| 961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 962 | - else |
|
| 963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 1006 | + if ($drop) { |
|
| 1007 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
| 1008 | + } else { |
|
| 1009 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
| 1010 | + } |
|
| 964 | 1011 | break; |
| 965 | 1012 | } |
| 966 | 1013 | return $sql; |
@@ -1003,22 +1050,30 @@ discard block |
||
| 1003 | 1050 | ($fieldDef['dbType'] == 'text' |
| 1004 | 1051 | || $fieldDef['dbType'] == 'blob' |
| 1005 | 1052 | || $fieldDef['dbType'] == 'longtext' |
| 1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
| 1007 | - unset($fieldDef['default']); |
|
| 1008 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1009 | - $fieldDef['len'] = '10'; |
|
| 1010 | - if ($fieldDef['dbType'] == 'ulong') |
|
| 1011 | - $fieldDef['len'] = '20'; |
|
| 1012 | - if ($fieldDef['dbType'] == 'bool') |
|
| 1013 | - $fieldDef['type'] = 'tinyint'; |
|
| 1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
| 1015 | - $fieldDef['default'] = '0'; |
|
| 1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
| 1017 | - $fieldDef['len'] = '255'; |
|
| 1018 | - if ($fieldDef['dbType'] == 'uint') |
|
| 1019 | - $fieldDef['len'] = '10'; |
|
| 1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
| 1021 | - $fieldDef['len'] = '11'; |
|
| 1053 | + || $fieldDef['dbType'] == 'longblob' )) { |
|
| 1054 | + unset($fieldDef['default']); |
|
| 1055 | + } |
|
| 1056 | + if ($fieldDef['dbType'] == 'uint') { |
|
| 1057 | + $fieldDef['len'] = '10'; |
|
| 1058 | + } |
|
| 1059 | + if ($fieldDef['dbType'] == 'ulong') { |
|
| 1060 | + $fieldDef['len'] = '20'; |
|
| 1061 | + } |
|
| 1062 | + if ($fieldDef['dbType'] == 'bool') { |
|
| 1063 | + $fieldDef['type'] = 'tinyint'; |
|
| 1064 | + } |
|
| 1065 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) { |
|
| 1066 | + $fieldDef['default'] = '0'; |
|
| 1067 | + } |
|
| 1068 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) { |
|
| 1069 | + $fieldDef['len'] = '255'; |
|
| 1070 | + } |
|
| 1071 | + if ($fieldDef['dbType'] == 'uint') { |
|
| 1072 | + $fieldDef['len'] = '10'; |
|
| 1073 | + } |
|
| 1074 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) { |
|
| 1075 | + $fieldDef['len'] = '11'; |
|
| 1076 | + } |
|
| 1022 | 1077 | |
| 1023 | 1078 | if($fieldDef['dbType'] == 'decimal') { |
| 1024 | 1079 | if(isset($fieldDef['len'])) { |
@@ -1058,8 +1113,9 @@ discard block |
||
| 1058 | 1113 | } |
| 1059 | 1114 | if (!empty($sql)) { |
| 1060 | 1115 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
| 1061 | - if($execute) |
|
| 1062 | - $this->query($sql); |
|
| 1116 | + if($execute) { |
|
| 1117 | + $this->query($sql); |
|
| 1118 | + } |
|
| 1063 | 1119 | } else { |
| 1064 | 1120 | $sql = ''; |
| 1065 | 1121 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | /** |
| 652 | 652 | * Returns the name of the engine to use or null if we are to use the default |
| 653 | 653 | * |
| 654 | - * @param object $bean SugarBean instance |
|
| 654 | + * @param SugarBean $bean SugarBean instance |
|
| 655 | 655 | * @return string |
| 656 | 656 | */ |
| 657 | 657 | protected function getEngine($bean) |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | |
| 1150 | 1150 | /** |
| 1151 | 1151 | * Generate fulltext query from set of terms |
| 1152 | - * @param string $fields Field to search against |
|
| 1152 | + * @param string $field Field to search against |
|
| 1153 | 1153 | * @param array $terms Search terms that may be or not be in the result |
| 1154 | 1154 | * @param array $must_terms Search terms that have to be in the result |
| 1155 | 1155 | * @param array $exclude_terms Search terms that have to be not in the result |
@@ -1276,6 +1276,9 @@ discard block |
||
| 1276 | 1276 | return ''; |
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | + /** |
|
| 1280 | + * @param string $querytype |
|
| 1281 | + */ |
|
| 1279 | 1282 | protected function verifyGenericReplaceQuery($querytype, $table, $query) |
| 1280 | 1283 | { |
| 1281 | 1284 | $this->log->debug("verifying $querytype statement"); |
@@ -98,51 +98,51 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | class MysqliManager extends MysqlManager |
| 100 | 100 | { |
| 101 | - /** |
|
| 102 | - * @see DBManager::$dbType |
|
| 103 | - */ |
|
| 104 | - public $dbType = 'mysql'; |
|
| 105 | - public $variant = 'mysqli'; |
|
| 106 | - public $priority = 10; |
|
| 107 | - public $label = 'LBL_MYSQLI'; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @see DBManager::$backendFunctions |
|
| 111 | - */ |
|
| 112 | - protected $backendFunctions = array( |
|
| 113 | - 'free_result' => 'mysqli_free_result', |
|
| 114 | - 'close' => 'mysqli_close', |
|
| 115 | - 'row_count' => 'mysqli_num_rows', |
|
| 116 | - 'affected_row_count' => 'mysqli_affected_rows', |
|
| 117 | - ); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @see MysqlManager::query() |
|
| 121 | - */ |
|
| 122 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
| 123 | - { |
|
| 124 | - if(is_array($sql)) { |
|
| 125 | - return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
| 101 | + /** |
|
| 102 | + * @see DBManager::$dbType |
|
| 103 | + */ |
|
| 104 | + public $dbType = 'mysql'; |
|
| 105 | + public $variant = 'mysqli'; |
|
| 106 | + public $priority = 10; |
|
| 107 | + public $label = 'LBL_MYSQLI'; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @see DBManager::$backendFunctions |
|
| 111 | + */ |
|
| 112 | + protected $backendFunctions = array( |
|
| 113 | + 'free_result' => 'mysqli_free_result', |
|
| 114 | + 'close' => 'mysqli_close', |
|
| 115 | + 'row_count' => 'mysqli_num_rows', |
|
| 116 | + 'affected_row_count' => 'mysqli_affected_rows', |
|
| 117 | + ); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @see MysqlManager::query() |
|
| 121 | + */ |
|
| 122 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
| 123 | + { |
|
| 124 | + if(is_array($sql)) { |
|
| 125 | + return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - static $queryMD5 = array(); |
|
| 128 | + static $queryMD5 = array(); |
|
| 129 | 129 | |
| 130 | - parent::countQuery($sql); |
|
| 131 | - $GLOBALS['log']->info('Query:' . $sql); |
|
| 132 | - $this->checkConnection(); |
|
| 133 | - $this->query_time = microtime(true); |
|
| 134 | - $this->lastsql = $sql; |
|
| 135 | - $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
|
| 136 | - $md5 = md5($sql); |
|
| 130 | + parent::countQuery($sql); |
|
| 131 | + $GLOBALS['log']->info('Query:' . $sql); |
|
| 132 | + $this->checkConnection(); |
|
| 133 | + $this->query_time = microtime(true); |
|
| 134 | + $this->lastsql = $sql; |
|
| 135 | + $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
|
| 136 | + $md5 = md5($sql); |
|
| 137 | 137 | |
| 138 | - if (empty($queryMD5[$md5])) |
|
| 139 | - $queryMD5[$md5] = true; |
|
| 138 | + if (empty($queryMD5[$md5])) |
|
| 139 | + $queryMD5[$md5] = true; |
|
| 140 | 140 | |
| 141 | - $this->query_time = microtime(true) - $this->query_time; |
|
| 142 | - $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
| 141 | + $this->query_time = microtime(true) - $this->query_time; |
|
| 142 | + $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
| 143 | 143 | |
| 144 | - // This is some heavy duty debugging, leave commented out unless you need this: |
|
| 145 | - /* |
|
| 144 | + // This is some heavy duty debugging, leave commented out unless you need this: |
|
| 145 | + /* |
|
| 146 | 146 | $bt = debug_backtrace(); |
| 147 | 147 | for ( $i = count($bt) ; $i-- ; $i > 0 ) { |
| 148 | 148 | if ( strpos('MysqliManager.php',$bt[$i]['file']) === false ) { |
@@ -154,228 +154,228 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | |
| 156 | 156 | |
| 157 | - if($keepResult) |
|
| 158 | - $this->lastResult = $result; |
|
| 159 | - $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
| 160 | - |
|
| 161 | - return $result; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Returns the number of rows affected by the last query |
|
| 166 | - * |
|
| 167 | - * @return int |
|
| 168 | - */ |
|
| 169 | - public function getAffectedRowCount($result) |
|
| 170 | - { |
|
| 171 | - return mysqli_affected_rows($this->getDatabase()); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Returns the number of rows returned by the result |
|
| 176 | - * |
|
| 177 | - * This function can't be reliably implemented on most DB, do not use it. |
|
| 178 | - * @abstract |
|
| 179 | - * @deprecated |
|
| 180 | - * @param resource $result |
|
| 181 | - * @return int |
|
| 182 | - */ |
|
| 183 | - public function getRowCount($result) |
|
| 184 | - { |
|
| 185 | - return mysqli_num_rows($result); |
|
| 186 | - } |
|
| 157 | + if($keepResult) |
|
| 158 | + $this->lastResult = $result; |
|
| 159 | + $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
| 187 | 160 | |
| 161 | + return $result; |
|
| 162 | + } |
|
| 188 | 163 | |
| 189 | 164 | /** |
| 190 | - * Disconnects from the database |
|
| 191 | - * |
|
| 192 | - * Also handles any cleanup needed |
|
| 193 | - */ |
|
| 194 | - public function disconnect() |
|
| 195 | - { |
|
| 196 | - if(isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
| 197 | - $GLOBALS['log']->debug('Calling MySQLi::disconnect()'); |
|
| 198 | - } |
|
| 199 | - if(!empty($this->database)){ |
|
| 200 | - $this->freeResult(); |
|
| 201 | - mysqli_close($this->database); |
|
| 202 | - $this->database = null; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @see DBManager::freeDbResult() |
|
| 208 | - */ |
|
| 209 | - protected function freeDbResult($dbResult) |
|
| 210 | - { |
|
| 211 | - if(!empty($dbResult)) |
|
| 212 | - mysqli_free_result($dbResult); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @see DBManager::getFieldsArray() |
|
| 217 | - */ |
|
| 218 | - public function getFieldsArray($result, $make_lower_case = false) |
|
| 219 | - { |
|
| 220 | - $field_array = array(); |
|
| 221 | - |
|
| 222 | - if (!isset($result) || empty($result)) |
|
| 223 | - return 0; |
|
| 224 | - |
|
| 225 | - $i = 0; |
|
| 226 | - while ($i < mysqli_num_fields($result)) { |
|
| 227 | - $meta = mysqli_fetch_field_direct($result, $i); |
|
| 228 | - if (!$meta) |
|
| 229 | - return 0; |
|
| 230 | - |
|
| 231 | - if($make_lower_case == true) |
|
| 232 | - $meta->name = strtolower($meta->name); |
|
| 233 | - |
|
| 234 | - $field_array[] = $meta->name; |
|
| 235 | - |
|
| 236 | - $i++; |
|
| 237 | - } |
|
| 165 | + * Returns the number of rows affected by the last query |
|
| 166 | + * |
|
| 167 | + * @return int |
|
| 168 | + */ |
|
| 169 | + public function getAffectedRowCount($result) |
|
| 170 | + { |
|
| 171 | + return mysqli_affected_rows($this->getDatabase()); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Returns the number of rows returned by the result |
|
| 176 | + * |
|
| 177 | + * This function can't be reliably implemented on most DB, do not use it. |
|
| 178 | + * @abstract |
|
| 179 | + * @deprecated |
|
| 180 | + * @param resource $result |
|
| 181 | + * @return int |
|
| 182 | + */ |
|
| 183 | + public function getRowCount($result) |
|
| 184 | + { |
|
| 185 | + return mysqli_num_rows($result); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Disconnects from the database |
|
| 191 | + * |
|
| 192 | + * Also handles any cleanup needed |
|
| 193 | + */ |
|
| 194 | + public function disconnect() |
|
| 195 | + { |
|
| 196 | + if(isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
| 197 | + $GLOBALS['log']->debug('Calling MySQLi::disconnect()'); |
|
| 198 | + } |
|
| 199 | + if(!empty($this->database)){ |
|
| 200 | + $this->freeResult(); |
|
| 201 | + mysqli_close($this->database); |
|
| 202 | + $this->database = null; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @see DBManager::freeDbResult() |
|
| 208 | + */ |
|
| 209 | + protected function freeDbResult($dbResult) |
|
| 210 | + { |
|
| 211 | + if(!empty($dbResult)) |
|
| 212 | + mysqli_free_result($dbResult); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @see DBManager::getFieldsArray() |
|
| 217 | + */ |
|
| 218 | + public function getFieldsArray($result, $make_lower_case = false) |
|
| 219 | + { |
|
| 220 | + $field_array = array(); |
|
| 221 | + |
|
| 222 | + if (!isset($result) || empty($result)) |
|
| 223 | + return 0; |
|
| 224 | + |
|
| 225 | + $i = 0; |
|
| 226 | + while ($i < mysqli_num_fields($result)) { |
|
| 227 | + $meta = mysqli_fetch_field_direct($result, $i); |
|
| 228 | + if (!$meta) |
|
| 229 | + return 0; |
|
| 230 | + |
|
| 231 | + if($make_lower_case == true) |
|
| 232 | + $meta->name = strtolower($meta->name); |
|
| 233 | + |
|
| 234 | + $field_array[] = $meta->name; |
|
| 235 | + |
|
| 236 | + $i++; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $field_array; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @see DBManager::fetchRow() |
|
| 244 | + */ |
|
| 245 | + public function fetchRow($result) |
|
| 246 | + { |
|
| 247 | + if (empty($result)) return false; |
|
| 238 | 248 | |
| 239 | - return $field_array; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @see DBManager::fetchRow() |
|
| 244 | - */ |
|
| 245 | - public function fetchRow($result) |
|
| 246 | - { |
|
| 247 | - if (empty($result)) return false; |
|
| 248 | - |
|
| 249 | - $row = mysqli_fetch_assoc($result); |
|
| 250 | - if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
| 251 | - return $row; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @see DBManager::quote() |
|
| 256 | - */ |
|
| 257 | - public function quote($string) |
|
| 258 | - { |
|
| 259 | - return mysqli_real_escape_string($this->getDatabase(),$this->quoteInternal($string)); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @see DBManager::connect() |
|
| 264 | - */ |
|
| 265 | - public function connect(array $configOptions = null, $dieOnError = false) |
|
| 266 | - { |
|
| 267 | - global $sugar_config; |
|
| 268 | - |
|
| 269 | - if (is_null($configOptions)) |
|
| 270 | - $configOptions = $sugar_config['dbconfig']; |
|
| 271 | - |
|
| 272 | - if(!isset($this->database)) { |
|
| 273 | - |
|
| 274 | - //mysqli connector has a separate parameter for port.. We need to separate it out from the host name |
|
| 275 | - $dbhost=$configOptions['db_host_name']; |
|
| 249 | + $row = mysqli_fetch_assoc($result); |
|
| 250 | + if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
| 251 | + return $row; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @see DBManager::quote() |
|
| 256 | + */ |
|
| 257 | + public function quote($string) |
|
| 258 | + { |
|
| 259 | + return mysqli_real_escape_string($this->getDatabase(),$this->quoteInternal($string)); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @see DBManager::connect() |
|
| 264 | + */ |
|
| 265 | + public function connect(array $configOptions = null, $dieOnError = false) |
|
| 266 | + { |
|
| 267 | + global $sugar_config; |
|
| 268 | + |
|
| 269 | + if (is_null($configOptions)) |
|
| 270 | + $configOptions = $sugar_config['dbconfig']; |
|
| 271 | + |
|
| 272 | + if(!isset($this->database)) { |
|
| 273 | + |
|
| 274 | + //mysqli connector has a separate parameter for port.. We need to separate it out from the host name |
|
| 275 | + $dbhost=$configOptions['db_host_name']; |
|
| 276 | 276 | $dbport=isset($configOptions['db_port']) ? ($configOptions['db_port'] == '' ? null : $configOptions['db_port']) : null; |
| 277 | 277 | |
| 278 | - $pos=strpos($configOptions['db_host_name'],':'); |
|
| 279 | - if ($pos !== false) { |
|
| 280 | - $dbhost=substr($configOptions['db_host_name'],0,$pos); |
|
| 281 | - $dbport=substr($configOptions['db_host_name'],$pos+1); |
|
| 282 | - } |
|
| 278 | + $pos=strpos($configOptions['db_host_name'],':'); |
|
| 279 | + if ($pos !== false) { |
|
| 280 | + $dbhost=substr($configOptions['db_host_name'],0,$pos); |
|
| 281 | + $dbport=substr($configOptions['db_host_name'],$pos+1); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $this->database = @mysqli_connect($dbhost,$configOptions['db_user_name'],$configOptions['db_password'],isset($configOptions['db_name'])?$configOptions['db_name']:'',$dbport); |
|
| 285 | + if(empty($this->database)) { |
|
| 286 | + $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port " .$dbport . ": " . mysqli_connect_error()); |
|
| 287 | + if($dieOnError) { |
|
| 288 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 289 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 290 | + } else { |
|
| 291 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 292 | + } |
|
| 293 | + } else { |
|
| 294 | + return false; |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + } |
|
| 283 | 298 | |
| 284 | - $this->database = @mysqli_connect($dbhost,$configOptions['db_user_name'],$configOptions['db_password'],isset($configOptions['db_name'])?$configOptions['db_name']:'',$dbport); |
|
| 285 | - if(empty($this->database)) { |
|
| 286 | - $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port " .$dbport . ": " . mysqli_connect_error()); |
|
| 287 | - if($dieOnError) { |
|
| 288 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 289 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 290 | - } else { |
|
| 291 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 292 | - } |
|
| 293 | - } else { |
|
| 294 | - return false; |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - } |
|
| 299 | + if(!empty($configOptions['db_name']) && !@mysqli_select_db($this->database,$configOptions['db_name'])) { |
|
| 300 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysqli_connect_error()); |
|
| 301 | + if($dieOnError) { |
|
| 302 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 303 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 304 | + } else { |
|
| 305 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 306 | + } |
|
| 307 | + } else { |
|
| 308 | + return false; |
|
| 309 | + } |
|
| 310 | + } |
|
| 298 | 311 | |
| 299 | - if(!empty($configOptions['db_name']) && !@mysqli_select_db($this->database,$configOptions['db_name'])) { |
|
| 300 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysqli_connect_error()); |
|
| 301 | - if($dieOnError) { |
|
| 302 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 303 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
| 304 | - } else { |
|
| 305 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
| 306 | - } |
|
| 307 | - } else { |
|
| 308 | - return false; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - // cn: using direct calls to prevent this from spamming the Logs |
|
| 313 | - mysqli_query($this->database,"SET CHARACTER SET utf8"); |
|
| 314 | - $names = "SET NAMES 'utf8'"; |
|
| 315 | - $collation = $this->getOption('collation'); |
|
| 316 | - if(!empty($collation)) { |
|
| 317 | - $names .= " COLLATE '$collation'"; |
|
| 318 | - } |
|
| 319 | - mysqli_query($this->database,$names); |
|
| 320 | - |
|
| 321 | - if($this->checkError('Could Not Connect', $dieOnError)) |
|
| 322 | - $GLOBALS['log']->info("connected to db"); |
|
| 323 | - |
|
| 324 | - $this->connectOptions = $configOptions; |
|
| 325 | - return true; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * (non-PHPdoc) |
|
| 330 | - * @see MysqlManager::lastDbError() |
|
| 331 | - */ |
|
| 332 | - public function lastDbError() |
|
| 333 | - { |
|
| 334 | - if($this->database) { |
|
| 335 | - if(mysqli_errno($this->database)) { |
|
| 336 | - return "MySQL error ".mysqli_errno($this->database).": ".mysqli_error($this->database); |
|
| 337 | - } |
|
| 338 | - } else { |
|
| 339 | - $err = mysqli_connect_error(); |
|
| 340 | - if($err) { |
|
| 341 | - return $err; |
|
| 342 | - } |
|
| 343 | - } |
|
| 312 | + // cn: using direct calls to prevent this from spamming the Logs |
|
| 313 | + mysqli_query($this->database,"SET CHARACTER SET utf8"); |
|
| 314 | + $names = "SET NAMES 'utf8'"; |
|
| 315 | + $collation = $this->getOption('collation'); |
|
| 316 | + if(!empty($collation)) { |
|
| 317 | + $names .= " COLLATE '$collation'"; |
|
| 318 | + } |
|
| 319 | + mysqli_query($this->database,$names); |
|
| 344 | 320 | |
| 345 | - return false; |
|
| 346 | - } |
|
| 321 | + if($this->checkError('Could Not Connect', $dieOnError)) |
|
| 322 | + $GLOBALS['log']->info("connected to db"); |
|
| 347 | 323 | |
| 348 | - public function getDbInfo() |
|
| 349 | - { |
|
| 350 | - $charsets = $this->getCharsetInfo(); |
|
| 351 | - $charset_str = array(); |
|
| 352 | - foreach($charsets as $name => $value) { |
|
| 353 | - $charset_str[] = "$name = $value"; |
|
| 354 | - } |
|
| 355 | - return array( |
|
| 356 | - "MySQLi Version" => @mysqli_get_client_info(), |
|
| 357 | - "MySQLi Host Info" => @mysqli_get_host_info($this->database), |
|
| 358 | - "MySQLi Server Info" => @mysqli_get_server_info($this->database), |
|
| 359 | - "MySQLi Client Encoding" => @mysqli_client_encoding($this->database), |
|
| 360 | - "MySQL Character Set Settings" => join(", ", $charset_str), |
|
| 361 | - ); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Select database |
|
| 366 | - * @param string $dbname |
|
| 367 | - */ |
|
| 368 | - protected function selectDb($dbname) |
|
| 369 | - { |
|
| 370 | - return mysqli_select_db($this->getDatabase(), $dbname); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Check if this driver can be used |
|
| 375 | - * @return bool |
|
| 376 | - */ |
|
| 377 | - public function valid() |
|
| 378 | - { |
|
| 379 | - return function_exists("mysqli_connect") && empty($GLOBALS['sugar_config']['mysqli_disabled']); |
|
| 380 | - } |
|
| 324 | + $this->connectOptions = $configOptions; |
|
| 325 | + return true; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * (non-PHPdoc) |
|
| 330 | + * @see MysqlManager::lastDbError() |
|
| 331 | + */ |
|
| 332 | + public function lastDbError() |
|
| 333 | + { |
|
| 334 | + if($this->database) { |
|
| 335 | + if(mysqli_errno($this->database)) { |
|
| 336 | + return "MySQL error ".mysqli_errno($this->database).": ".mysqli_error($this->database); |
|
| 337 | + } |
|
| 338 | + } else { |
|
| 339 | + $err = mysqli_connect_error(); |
|
| 340 | + if($err) { |
|
| 341 | + return $err; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + public function getDbInfo() |
|
| 349 | + { |
|
| 350 | + $charsets = $this->getCharsetInfo(); |
|
| 351 | + $charset_str = array(); |
|
| 352 | + foreach($charsets as $name => $value) { |
|
| 353 | + $charset_str[] = "$name = $value"; |
|
| 354 | + } |
|
| 355 | + return array( |
|
| 356 | + "MySQLi Version" => @mysqli_get_client_info(), |
|
| 357 | + "MySQLi Host Info" => @mysqli_get_host_info($this->database), |
|
| 358 | + "MySQLi Server Info" => @mysqli_get_server_info($this->database), |
|
| 359 | + "MySQLi Client Encoding" => @mysqli_client_encoding($this->database), |
|
| 360 | + "MySQL Character Set Settings" => join(", ", $charset_str), |
|
| 361 | + ); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Select database |
|
| 366 | + * @param string $dbname |
|
| 367 | + */ |
|
| 368 | + protected function selectDb($dbname) |
|
| 369 | + { |
|
| 370 | + return mysqli_select_db($this->getDatabase(), $dbname); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Check if this driver can be used |
|
| 375 | + * @return bool |
|
| 376 | + */ |
|
| 377 | + public function valid() |
|
| 378 | + { |
|
| 379 | + return function_exists("mysqli_connect") && empty($GLOBALS['sugar_config']['mysqli_disabled']); |
|
| 380 | + } |
|
| 381 | 381 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -121,18 +121,18 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
| 123 | 123 | { |
| 124 | - if(is_array($sql)) { |
|
| 124 | + if (is_array($sql)) { |
|
| 125 | 125 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | static $queryMD5 = array(); |
| 129 | 129 | |
| 130 | 130 | parent::countQuery($sql); |
| 131 | - $GLOBALS['log']->info('Query:' . $sql); |
|
| 131 | + $GLOBALS['log']->info('Query:'.$sql); |
|
| 132 | 132 | $this->checkConnection(); |
| 133 | 133 | $this->query_time = microtime(true); |
| 134 | 134 | $this->lastsql = $sql; |
| 135 | - $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
|
| 135 | + $result = $suppress ? @mysqli_query($this->database, $sql) : mysqli_query($this->database, $sql); |
|
| 136 | 136 | $md5 = md5($sql); |
| 137 | 137 | |
| 138 | 138 | if (empty($queryMD5[$md5])) |
@@ -154,9 +154,9 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | |
| 156 | 156 | |
| 157 | - if($keepResult) |
|
| 157 | + if ($keepResult) |
|
| 158 | 158 | $this->lastResult = $result; |
| 159 | - $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
| 159 | + $this->checkError($msg.' Query Failed: '.$sql, $dieOnError); |
|
| 160 | 160 | |
| 161 | 161 | return $result; |
| 162 | 162 | } |
@@ -193,10 +193,10 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | public function disconnect() |
| 195 | 195 | { |
| 196 | - if(isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
| 196 | + if (isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
| 197 | 197 | $GLOBALS['log']->debug('Calling MySQLi::disconnect()'); |
| 198 | 198 | } |
| 199 | - if(!empty($this->database)){ |
|
| 199 | + if (!empty($this->database)) { |
|
| 200 | 200 | $this->freeResult(); |
| 201 | 201 | mysqli_close($this->database); |
| 202 | 202 | $this->database = null; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | protected function freeDbResult($dbResult) |
| 210 | 210 | { |
| 211 | - if(!empty($dbResult)) |
|
| 211 | + if (!empty($dbResult)) |
|
| 212 | 212 | mysqli_free_result($dbResult); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | if (!$meta) |
| 229 | 229 | return 0; |
| 230 | 230 | |
| 231 | - if($make_lower_case == true) |
|
| 231 | + if ($make_lower_case == true) |
|
| 232 | 232 | $meta->name = strtolower($meta->name); |
| 233 | 233 | |
| 234 | 234 | $field_array[] = $meta->name; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | if (empty($result)) return false; |
| 248 | 248 | |
| 249 | 249 | $row = mysqli_fetch_assoc($result); |
| 250 | - if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
| 250 | + if ($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
| 251 | 251 | return $row; |
| 252 | 252 | } |
| 253 | 253 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function quote($string) |
| 258 | 258 | { |
| 259 | - return mysqli_real_escape_string($this->getDatabase(),$this->quoteInternal($string)); |
|
| 259 | + return mysqli_real_escape_string($this->getDatabase(), $this->quoteInternal($string)); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -269,23 +269,23 @@ discard block |
||
| 269 | 269 | if (is_null($configOptions)) |
| 270 | 270 | $configOptions = $sugar_config['dbconfig']; |
| 271 | 271 | |
| 272 | - if(!isset($this->database)) { |
|
| 272 | + if (!isset($this->database)) { |
|
| 273 | 273 | |
| 274 | 274 | //mysqli connector has a separate parameter for port.. We need to separate it out from the host name |
| 275 | - $dbhost=$configOptions['db_host_name']; |
|
| 276 | - $dbport=isset($configOptions['db_port']) ? ($configOptions['db_port'] == '' ? null : $configOptions['db_port']) : null; |
|
| 275 | + $dbhost = $configOptions['db_host_name']; |
|
| 276 | + $dbport = isset($configOptions['db_port']) ? ($configOptions['db_port'] == '' ? null : $configOptions['db_port']) : null; |
|
| 277 | 277 | |
| 278 | - $pos=strpos($configOptions['db_host_name'],':'); |
|
| 278 | + $pos = strpos($configOptions['db_host_name'], ':'); |
|
| 279 | 279 | if ($pos !== false) { |
| 280 | - $dbhost=substr($configOptions['db_host_name'],0,$pos); |
|
| 281 | - $dbport=substr($configOptions['db_host_name'],$pos+1); |
|
| 280 | + $dbhost = substr($configOptions['db_host_name'], 0, $pos); |
|
| 281 | + $dbport = substr($configOptions['db_host_name'], $pos + 1); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - $this->database = @mysqli_connect($dbhost,$configOptions['db_user_name'],$configOptions['db_password'],isset($configOptions['db_name'])?$configOptions['db_name']:'',$dbport); |
|
| 285 | - if(empty($this->database)) { |
|
| 286 | - $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port " .$dbport . ": " . mysqli_connect_error()); |
|
| 287 | - if($dieOnError) { |
|
| 288 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 284 | + $this->database = @mysqli_connect($dbhost, $configOptions['db_user_name'], $configOptions['db_password'], isset($configOptions['db_name']) ? $configOptions['db_name'] : '', $dbport); |
|
| 285 | + if (empty($this->database)) { |
|
| 286 | + $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port ".$dbport.": ".mysqli_connect_error()); |
|
| 287 | + if ($dieOnError) { |
|
| 288 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 289 | 289 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
| 290 | 290 | } else { |
| 291 | 291 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -296,10 +296,10 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if(!empty($configOptions['db_name']) && !@mysqli_select_db($this->database,$configOptions['db_name'])) { |
|
| 300 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysqli_connect_error()); |
|
| 301 | - if($dieOnError) { |
|
| 302 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 299 | + if (!empty($configOptions['db_name']) && !@mysqli_select_db($this->database, $configOptions['db_name'])) { |
|
| 300 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}: ".mysqli_connect_error()); |
|
| 301 | + if ($dieOnError) { |
|
| 302 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
| 303 | 303 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
| 304 | 304 | } else { |
| 305 | 305 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -310,15 +310,15 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | // cn: using direct calls to prevent this from spamming the Logs |
| 313 | - mysqli_query($this->database,"SET CHARACTER SET utf8"); |
|
| 313 | + mysqli_query($this->database, "SET CHARACTER SET utf8"); |
|
| 314 | 314 | $names = "SET NAMES 'utf8'"; |
| 315 | 315 | $collation = $this->getOption('collation'); |
| 316 | - if(!empty($collation)) { |
|
| 316 | + if (!empty($collation)) { |
|
| 317 | 317 | $names .= " COLLATE '$collation'"; |
| 318 | 318 | } |
| 319 | - mysqli_query($this->database,$names); |
|
| 319 | + mysqli_query($this->database, $names); |
|
| 320 | 320 | |
| 321 | - if($this->checkError('Could Not Connect', $dieOnError)) |
|
| 321 | + if ($this->checkError('Could Not Connect', $dieOnError)) |
|
| 322 | 322 | $GLOBALS['log']->info("connected to db"); |
| 323 | 323 | |
| 324 | 324 | $this->connectOptions = $configOptions; |
@@ -331,13 +331,13 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | public function lastDbError() |
| 333 | 333 | { |
| 334 | - if($this->database) { |
|
| 335 | - if(mysqli_errno($this->database)) { |
|
| 334 | + if ($this->database) { |
|
| 335 | + if (mysqli_errno($this->database)) { |
|
| 336 | 336 | return "MySQL error ".mysqli_errno($this->database).": ".mysqli_error($this->database); |
| 337 | 337 | } |
| 338 | 338 | } else { |
| 339 | - $err = mysqli_connect_error(); |
|
| 340 | - if($err) { |
|
| 339 | + $err = mysqli_connect_error(); |
|
| 340 | + if ($err) { |
|
| 341 | 341 | return $err; |
| 342 | 342 | } |
| 343 | 343 | } |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | { |
| 350 | 350 | $charsets = $this->getCharsetInfo(); |
| 351 | 351 | $charset_str = array(); |
| 352 | - foreach($charsets as $name => $value) { |
|
| 352 | + foreach ($charsets as $name => $value) { |
|
| 353 | 353 | $charset_str[] = "$name = $value"; |
| 354 | 354 | } |
| 355 | 355 | return array( |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -135,8 +137,9 @@ discard block |
||
| 135 | 137 | $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
| 136 | 138 | $md5 = md5($sql); |
| 137 | 139 | |
| 138 | - if (empty($queryMD5[$md5])) |
|
| 139 | - $queryMD5[$md5] = true; |
|
| 140 | + if (empty($queryMD5[$md5])) { |
|
| 141 | + $queryMD5[$md5] = true; |
|
| 142 | + } |
|
| 140 | 143 | |
| 141 | 144 | $this->query_time = microtime(true) - $this->query_time; |
| 142 | 145 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
@@ -154,8 +157,9 @@ discard block |
||
| 154 | 157 | */ |
| 155 | 158 | |
| 156 | 159 | |
| 157 | - if($keepResult) |
|
| 158 | - $this->lastResult = $result; |
|
| 160 | + if($keepResult) { |
|
| 161 | + $this->lastResult = $result; |
|
| 162 | + } |
|
| 159 | 163 | $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
| 160 | 164 | |
| 161 | 165 | return $result; |
@@ -208,8 +212,9 @@ discard block |
||
| 208 | 212 | */ |
| 209 | 213 | protected function freeDbResult($dbResult) |
| 210 | 214 | { |
| 211 | - if(!empty($dbResult)) |
|
| 212 | - mysqli_free_result($dbResult); |
|
| 215 | + if(!empty($dbResult)) { |
|
| 216 | + mysqli_free_result($dbResult); |
|
| 217 | + } |
|
| 213 | 218 | } |
| 214 | 219 | |
| 215 | 220 | /** |
@@ -219,17 +224,20 @@ discard block |
||
| 219 | 224 | { |
| 220 | 225 | $field_array = array(); |
| 221 | 226 | |
| 222 | - if (!isset($result) || empty($result)) |
|
| 223 | - return 0; |
|
| 227 | + if (!isset($result) || empty($result)) { |
|
| 228 | + return 0; |
|
| 229 | + } |
|
| 224 | 230 | |
| 225 | 231 | $i = 0; |
| 226 | 232 | while ($i < mysqli_num_fields($result)) { |
| 227 | 233 | $meta = mysqli_fetch_field_direct($result, $i); |
| 228 | - if (!$meta) |
|
| 229 | - return 0; |
|
| 234 | + if (!$meta) { |
|
| 235 | + return 0; |
|
| 236 | + } |
|
| 230 | 237 | |
| 231 | - if($make_lower_case == true) |
|
| 232 | - $meta->name = strtolower($meta->name); |
|
| 238 | + if($make_lower_case == true) { |
|
| 239 | + $meta->name = strtolower($meta->name); |
|
| 240 | + } |
|
| 233 | 241 | |
| 234 | 242 | $field_array[] = $meta->name; |
| 235 | 243 | |
@@ -244,10 +252,15 @@ discard block |
||
| 244 | 252 | */ |
| 245 | 253 | public function fetchRow($result) |
| 246 | 254 | { |
| 247 | - if (empty($result)) return false; |
|
| 255 | + if (empty($result)) { |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 248 | 258 | |
| 249 | 259 | $row = mysqli_fetch_assoc($result); |
| 250 | - if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
| 260 | + if($row == null) { |
|
| 261 | + $row = false; |
|
| 262 | + } |
|
| 263 | + //Make sure MySQLi driver results are consistent with other database drivers |
|
| 251 | 264 | return $row; |
| 252 | 265 | } |
| 253 | 266 | |
@@ -266,8 +279,9 @@ discard block |
||
| 266 | 279 | { |
| 267 | 280 | global $sugar_config; |
| 268 | 281 | |
| 269 | - if (is_null($configOptions)) |
|
| 270 | - $configOptions = $sugar_config['dbconfig']; |
|
| 282 | + if (is_null($configOptions)) { |
|
| 283 | + $configOptions = $sugar_config['dbconfig']; |
|
| 284 | + } |
|
| 271 | 285 | |
| 272 | 286 | if(!isset($this->database)) { |
| 273 | 287 | |
@@ -318,8 +332,9 @@ discard block |
||
| 318 | 332 | } |
| 319 | 333 | mysqli_query($this->database,$names); |
| 320 | 334 | |
| 321 | - if($this->checkError('Could Not Connect', $dieOnError)) |
|
| 322 | - $GLOBALS['log']->info("connected to db"); |
|
| 335 | + if($this->checkError('Could Not Connect', $dieOnError)) { |
|
| 336 | + $GLOBALS['log']->info("connected to db"); |
|
| 337 | + } |
|
| 323 | 338 | |
| 324 | 339 | $this->connectOptions = $configOptions; |
| 325 | 340 | return true; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | break; |
| 82 | 82 | case "mssql": |
| 83 | - if ( function_exists('sqlsrv_connect') |
|
| 83 | + if ( function_exists('sqlsrv_connect') |
|
| 84 | 84 | && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv' )) { |
| 85 | 85 | $my_db_manager = 'SqlsrvManager'; |
| 86 | 86 | } elseif (self::isFreeTDS() |
@@ -122,20 +122,20 @@ discard block |
||
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | - * Returns a reference to the DB object for instance $instanceName, or the default |
|
| 125 | + * Returns a reference to the DB object for instance $instanceName, or the default |
|
| 126 | 126 | * instance if one is not specified |
| 127 | 127 | * |
| 128 | 128 | * @param string $instanceName optional, name of the instance |
| 129 | 129 | * @return object DBManager instance |
| 130 | 130 | */ |
| 131 | - public static function getInstance($instanceName = '') |
|
| 131 | + public static function getInstance($instanceName = '') |
|
| 132 | 132 | { |
| 133 | 133 | global $sugar_config; |
| 134 | 134 | static $count = 0, $old_count = 0; |
| 135 | 135 | |
| 136 | 136 | //fall back to the default instance name |
| 137 | 137 | if(empty($sugar_config['db'][$instanceName])){ |
| 138 | - $instanceName = ''; |
|
| 138 | + $instanceName = ''; |
|
| 139 | 139 | } |
| 140 | 140 | if(!isset(self::$instances[$instanceName])){ |
| 141 | 141 | $config = $sugar_config['dbconfig']; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | /** |
| 249 | 249 | * Check if we have freeTDS driver installed |
| 250 | 250 | * Invoked when connected to mssql. checks if we have freetds version of mssql library. |
| 251 | - * the response is put into a global variable. |
|
| 251 | + * the response is put into a global variable. |
|
| 252 | 252 | * @return bool |
| 253 | 253 | */ |
| 254 | 254 | public static function isFreeTDS() |
@@ -256,14 +256,14 @@ discard block |
||
| 256 | 256 | static $is_freetds = null; |
| 257 | 257 | |
| 258 | 258 | if($is_freetds === null) { |
| 259 | - ob_start(); |
|
| 260 | - phpinfo(INFO_MODULES); |
|
| 261 | - $info=ob_get_contents(); |
|
| 262 | - ob_end_clean(); |
|
| 259 | + ob_start(); |
|
| 260 | + phpinfo(INFO_MODULES); |
|
| 261 | + $info=ob_get_contents(); |
|
| 262 | + ob_end_clean(); |
|
| 263 | 263 | |
| 264 | - $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
| 264 | + $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | return $is_freetds; |
| 268 | - } |
|
| 268 | + } |
|
| 269 | 269 | } |
| 270 | 270 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | global $sugar_config; |
| 71 | 71 | |
| 72 | - if(empty($config['db_manager'])) { |
|
| 72 | + if (empty($config['db_manager'])) { |
|
| 73 | 73 | // standard types |
| 74 | - switch($type) { |
|
| 74 | + switch ($type) { |
|
| 75 | 75 | case "mysql": |
| 76 | 76 | if (empty($sugar_config['mysqli_disabled']) && function_exists('mysqli_connect')) { |
| 77 | 77 | $my_db_manager = 'MysqliManager'; |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | break; |
| 82 | 82 | case "mssql": |
| 83 | - if ( function_exists('sqlsrv_connect') |
|
| 84 | - && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv' )) { |
|
| 83 | + if (function_exists('sqlsrv_connect') |
|
| 84 | + && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv')) { |
|
| 85 | 85 | $my_db_manager = 'SqlsrvManager'; |
| 86 | 86 | } elseif (self::isFreeTDS() |
| 87 | - && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'freetds' )) { |
|
| 87 | + && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'freetds')) { |
|
| 88 | 88 | $my_db_manager = 'FreeTDSManager'; |
| 89 | 89 | } else { |
| 90 | 90 | $my_db_manager = 'MssqlManager'; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | break; |
| 93 | 93 | default: |
| 94 | 94 | $my_db_manager = self::getManagerByType($type, false); |
| 95 | - if(empty($my_db_manager)) { |
|
| 95 | + if (empty($my_db_manager)) { |
|
| 96 | 96 | $GLOBALS['log']->fatal("unable to load DB manager for: $type"); |
| 97 | 97 | sugar_die("Cannot load DB manager"); |
| 98 | 98 | } |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | // sanitize the name |
| 105 | 105 | $my_db_manager = preg_replace("/[^A-Za-z0-9_-]/", "", $my_db_manager); |
| 106 | 106 | |
| 107 | - if(!empty($config['db_manager_class'])){ |
|
| 107 | + if (!empty($config['db_manager_class'])) { |
|
| 108 | 108 | $my_db_manager = $config['db_manager_class']; |
| 109 | 109 | } else { |
| 110 | - if(file_exists("custom/include/database/{$my_db_manager}.php")) { |
|
| 110 | + if (file_exists("custom/include/database/{$my_db_manager}.php")) { |
|
| 111 | 111 | require_once("custom/include/database/{$my_db_manager}.php"); |
| 112 | 112 | } else { |
| 113 | 113 | require_once("include/database/{$my_db_manager}.php"); |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if(class_exists($my_db_manager)) { |
|
| 117 | + if (class_exists($my_db_manager)) { |
|
| 118 | 118 | return new $my_db_manager(); |
| 119 | 119 | } else { |
| 120 | 120 | return null; |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | static $count = 0, $old_count = 0; |
| 135 | 135 | |
| 136 | 136 | //fall back to the default instance name |
| 137 | - if(empty($sugar_config['db'][$instanceName])){ |
|
| 137 | + if (empty($sugar_config['db'][$instanceName])) { |
|
| 138 | 138 | $instanceName = ''; |
| 139 | 139 | } |
| 140 | - if(!isset(self::$instances[$instanceName])){ |
|
| 140 | + if (!isset(self::$instances[$instanceName])) { |
|
| 141 | 141 | $config = $sugar_config['dbconfig']; |
| 142 | 142 | $count++; |
| 143 | 143 | self::$instances[$instanceName] = self::getTypeInstance($config['db_type'], $config); |
| 144 | - if(!empty($sugar_config['dbconfigoption'])) { |
|
| 144 | + if (!empty($sugar_config['dbconfigoption'])) { |
|
| 145 | 145 | self::$instances[$instanceName]->setOptions($sugar_config['dbconfigoption']); |
| 146 | 146 | } |
| 147 | 147 | self::$instances[$instanceName]->connect($config, true); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public static function disconnectAll() |
| 161 | 161 | { |
| 162 | - foreach(self::$instances as $instance) { |
|
| 162 | + foreach (self::$instances as $instance) { |
|
| 163 | 163 | $instance->disconnect(); |
| 164 | 164 | } |
| 165 | 165 | self::$instances = array(); |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | public static function getManagerByType($type, $validate = true) |
| 178 | 178 | { |
| 179 | 179 | $drivers = self::getDbDrivers($validate); |
| 180 | - if(!empty($drivers[$type])) { |
|
| 180 | + if (!empty($drivers[$type])) { |
|
| 181 | 181 | return get_class($drivers[$type]); |
| 182 | 182 | } |
| 183 | 183 | return false; |
@@ -191,19 +191,19 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | protected static function scanDriverDir($dir, &$drivers, $validate = true) |
| 193 | 193 | { |
| 194 | - if(!is_dir($dir)) return; |
|
| 194 | + if (!is_dir($dir)) return; |
|
| 195 | 195 | $scandir = opendir($dir); |
| 196 | - if($scandir === false) return; |
|
| 197 | - while(($name = readdir($scandir)) !== false) { |
|
| 198 | - if(substr($name, -11) != "Manager.php") continue; |
|
| 199 | - if($name == "DBManager.php") continue; |
|
| 196 | + if ($scandir === false) return; |
|
| 197 | + while (($name = readdir($scandir)) !== false) { |
|
| 198 | + if (substr($name, -11) != "Manager.php") continue; |
|
| 199 | + if ($name == "DBManager.php") continue; |
|
| 200 | 200 | require_once("$dir/$name"); |
| 201 | 201 | $classname = substr($name, 0, -4); |
| 202 | - if(!class_exists($classname)) continue; |
|
| 202 | + if (!class_exists($classname)) continue; |
|
| 203 | 203 | $driver = new $classname; |
| 204 | - if(!$validate || $driver->valid()) { |
|
| 205 | - if(empty($drivers[$driver->dbType])) { |
|
| 206 | - $drivers[$driver->dbType] = array(); |
|
| 204 | + if (!$validate || $driver->valid()) { |
|
| 205 | + if (empty($drivers[$driver->dbType])) { |
|
| 206 | + $drivers[$driver->dbType] = array(); |
|
| 207 | 207 | } |
| 208 | 208 | $drivers[$driver->dbType][] = $driver; |
| 209 | 209 | } |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | self::scanDriverDir("custom/include/database", $drivers, $validate); |
| 236 | 236 | |
| 237 | 237 | $result = array(); |
| 238 | - foreach($drivers as $type => $tdrivers) { |
|
| 239 | - if(empty($tdrivers)) continue; |
|
| 240 | - if(count($tdrivers) > 1) { |
|
| 238 | + foreach ($drivers as $type => $tdrivers) { |
|
| 239 | + if (empty($tdrivers)) continue; |
|
| 240 | + if (count($tdrivers) > 1) { |
|
| 241 | 241 | usort($tdrivers, array(__CLASS__, "_compareDrivers")); |
| 242 | 242 | } |
| 243 | 243 | $result[$type] = $tdrivers[0]; |
@@ -255,13 +255,13 @@ discard block |
||
| 255 | 255 | { |
| 256 | 256 | static $is_freetds = null; |
| 257 | 257 | |
| 258 | - if($is_freetds === null) { |
|
| 258 | + if ($is_freetds === null) { |
|
| 259 | 259 | ob_start(); |
| 260 | 260 | phpinfo(INFO_MODULES); |
| 261 | - $info=ob_get_contents(); |
|
| 261 | + $info = ob_get_contents(); |
|
| 262 | 262 | ob_end_clean(); |
| 263 | 263 | |
| 264 | - $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
| 264 | + $is_freetds = (strpos($info, 'FreeTDS') !== false); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | return $is_freetds; |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -191,15 +193,25 @@ discard block |
||
| 191 | 193 | */ |
| 192 | 194 | protected static function scanDriverDir($dir, &$drivers, $validate = true) |
| 193 | 195 | { |
| 194 | - if(!is_dir($dir)) return; |
|
| 196 | + if(!is_dir($dir)) { |
|
| 197 | + return; |
|
| 198 | + } |
|
| 195 | 199 | $scandir = opendir($dir); |
| 196 | - if($scandir === false) return; |
|
| 200 | + if($scandir === false) { |
|
| 201 | + return; |
|
| 202 | + } |
|
| 197 | 203 | while(($name = readdir($scandir)) !== false) { |
| 198 | - if(substr($name, -11) != "Manager.php") continue; |
|
| 199 | - if($name == "DBManager.php") continue; |
|
| 204 | + if(substr($name, -11) != "Manager.php") { |
|
| 205 | + continue; |
|
| 206 | + } |
|
| 207 | + if($name == "DBManager.php") { |
|
| 208 | + continue; |
|
| 209 | + } |
|
| 200 | 210 | require_once("$dir/$name"); |
| 201 | 211 | $classname = substr($name, 0, -4); |
| 202 | - if(!class_exists($classname)) continue; |
|
| 212 | + if(!class_exists($classname)) { |
|
| 213 | + continue; |
|
| 214 | + } |
|
| 203 | 215 | $driver = new $classname; |
| 204 | 216 | if(!$validate || $driver->valid()) { |
| 205 | 217 | if(empty($drivers[$driver->dbType])) { |
@@ -236,7 +248,9 @@ discard block |
||
| 236 | 248 | |
| 237 | 249 | $result = array(); |
| 238 | 250 | foreach($drivers as $type => $tdrivers) { |
| 239 | - if(empty($tdrivers)) continue; |
|
| 251 | + if(empty($tdrivers)) { |
|
| 252 | + continue; |
|
| 253 | + } |
|
| 240 | 254 | if(count($tdrivers) > 1) { |
| 241 | 255 | usort($tdrivers, array(__CLASS__, "_compareDrivers")); |
| 242 | 256 | } |
@@ -236,8 +236,8 @@ discard block |
||
| 236 | 236 | * @param unknown $html_varName |
| 237 | 237 | * @desc INTERNAL FUNCTION handles the rows |
| 238 | 238 | */ |
| 239 | - function process_dynamic_listview_rows($data,$parent_data, $xtemplateSection, $html_varName, $subpanel_def) |
|
| 240 | - { |
|
| 239 | + function process_dynamic_listview_rows($data,$parent_data, $xtemplateSection, $html_varName, $subpanel_def) |
|
| 240 | + { |
|
| 241 | 241 | global $subpanel_item_count; |
| 242 | 242 | global $odd_bg; |
| 243 | 243 | global $even_bg; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | $BG_COLOR = $even_bg; |
| 347 | 347 | } |
| 348 | 348 | $oddRow = !$oddRow; |
| 349 | - $button_contents = array(); |
|
| 349 | + $button_contents = array(); |
|
| 350 | 350 | $this->xTemplate->assign("ROW_COLOR", $ROW_COLOR); |
| 351 | 351 | $this->xTemplate->assign("BG_COLOR", $BG_COLOR); |
| 352 | 352 | $layout_manager = $this->getLayoutManager(); |
@@ -366,43 +366,43 @@ discard block |
||
| 366 | 366 | $thepanel=$subpanel_def; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - /* BEGIN - SECURITY GROUPS */ |
|
| 369 | + /* BEGIN - SECURITY GROUPS */ |
|
| 370 | 370 | |
| 371 | - //This check is costly doing it field by field in the below foreach |
|
| 372 | - //instead pull up here and do once per record.... |
|
| 373 | - $aclaccess_is_owner = false; |
|
| 374 | - $aclaccess_in_group = false; |
|
| 371 | + //This check is costly doing it field by field in the below foreach |
|
| 372 | + //instead pull up here and do once per record.... |
|
| 373 | + $aclaccess_is_owner = false; |
|
| 374 | + $aclaccess_in_group = false; |
|
| 375 | 375 | |
| 376 | - global $current_user; |
|
| 377 | - if(is_admin($current_user)) { |
|
| 378 | - $aclaccess_is_owner = true; |
|
| 379 | - } else { |
|
| 380 | - $aclaccess_is_owner = $aItem->isOwner($current_user->id); |
|
| 381 | - } |
|
| 376 | + global $current_user; |
|
| 377 | + if(is_admin($current_user)) { |
|
| 378 | + $aclaccess_is_owner = true; |
|
| 379 | + } else { |
|
| 380 | + $aclaccess_is_owner = $aItem->isOwner($current_user->id); |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - require_once("modules/SecurityGroups/SecurityGroup.php"); |
|
| 384 | - $aclaccess_in_group = SecurityGroup::groupHasAccess($aItem->module_dir,$aItem->id); |
|
| 383 | + require_once("modules/SecurityGroups/SecurityGroup.php"); |
|
| 384 | + $aclaccess_in_group = SecurityGroup::groupHasAccess($aItem->module_dir,$aItem->id); |
|
| 385 | 385 | |
| 386 | - /* END - SECURITY GROUPS */ |
|
| 386 | + /* END - SECURITY GROUPS */ |
|
| 387 | 387 | |
| 388 | 388 | //get data source name |
| 389 | 389 | $linked_field=$thepanel->get_data_source_name(); |
| 390 | 390 | $linked_field_set=$thepanel->get_data_source_name(true); |
| 391 | 391 | static $count; |
| 392 | 392 | if(!isset($count))$count = 0; |
| 393 | - /* BEGIN - SECURITY GROUPS */ |
|
| 394 | - /** |
|
| 393 | + /* BEGIN - SECURITY GROUPS */ |
|
| 394 | + /** |
|
| 395 | 395 | $field_acl['DetailView'] = $aItem->ACLAccess('DetailView'); |
| 396 | 396 | $field_acl['ListView'] = $aItem->ACLAccess('ListView'); |
| 397 | 397 | $field_acl['EditView'] = $aItem->ACLAccess('EditView'); |
| 398 | 398 | $field_acl['Delete'] = $aItem->ACLAccess('Delete'); |
| 399 | - */ |
|
| 400 | - //pass is_owner, in_group...vars defined above |
|
| 399 | + */ |
|
| 400 | + //pass is_owner, in_group...vars defined above |
|
| 401 | 401 | $field_acl['DetailView'] = $aItem->ACLAccess('DetailView',$aclaccess_is_owner,$aclaccess_in_group); |
| 402 | 402 | $field_acl['ListView'] = $aItem->ACLAccess('ListView',$aclaccess_is_owner,$aclaccess_in_group); |
| 403 | 403 | $field_acl['EditView'] = $aItem->ACLAccess('EditView',$aclaccess_is_owner,$aclaccess_in_group); |
| 404 | 404 | $field_acl['Delete'] = $aItem->ACLAccess('Delete',$aclaccess_is_owner,$aclaccess_in_group); |
| 405 | - /* END - SECURITY GROUPS */ |
|
| 405 | + /* END - SECURITY GROUPS */ |
|
| 406 | 406 | foreach($thepanel->get_list_fields() as $field_name=>$list_field) |
| 407 | 407 | { |
| 408 | 408 | //add linked field attribute to the array. |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | // So we'll populate the field data with the pre-rendered display for the field |
| 470 | 470 | $list_field['fields'][$field_name] = $widget_contents; |
| 471 | 471 | if('full_name' == $field_name){//bug #32465 |
| 472 | - $list_field['fields'][strtoupper($field_name)] = $widget_contents; |
|
| 472 | + $list_field['fields'][strtoupper($field_name)] = $widget_contents; |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | //vardef source is non db, assign the field name to varname for processing of column. |
@@ -482,7 +482,7 @@ discard block |
||
| 482 | 482 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | - $count++; |
|
| 485 | + $count++; |
|
| 486 | 486 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 487 | 487 | $this->xTemplate->assign('CLASS', ""); |
| 488 | 488 | if ( empty($widget_contents) ) $widget_contents = ' '; |
@@ -490,15 +490,15 @@ discard block |
||
| 490 | 490 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 491 | 491 | } else { |
| 492 | 492 | // This handles the edit and remove buttons and icon widget |
| 493 | - if( isset($list_field['widget_class']) && $list_field['widget_class'] == "SubPanelIcon") { |
|
| 494 | - $count++; |
|
| 495 | - $widget_contents = $layout_manager->widgetDisplay($list_field); |
|
| 496 | - $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 497 | - $this->xTemplate->assign('CLASS', ""); |
|
| 498 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 499 | - $this->xTemplate->assign('CELL', $widget_contents); |
|
| 500 | - $this->xTemplate->parse($xtemplateSection.".row.cell"); |
|
| 501 | - } elseif (preg_match("/button/i", $list_field['name'])) { |
|
| 493 | + if( isset($list_field['widget_class']) && $list_field['widget_class'] == "SubPanelIcon") { |
|
| 494 | + $count++; |
|
| 495 | + $widget_contents = $layout_manager->widgetDisplay($list_field); |
|
| 496 | + $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 497 | + $this->xTemplate->assign('CLASS', ""); |
|
| 498 | + if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 499 | + $this->xTemplate->assign('CELL', $widget_contents); |
|
| 500 | + $this->xTemplate->parse($xtemplateSection.".row.cell"); |
|
| 501 | + } elseif (preg_match("/button/i", $list_field['name'])) { |
|
| 502 | 502 | if ((($list_field['name'] === 'edit_button' && $field_acl['EditView']) || ($list_field['name'] === 'close_button' && $field_acl['EditView']) || ($list_field['name'] === 'remove_button' && $field_acl['Delete'])) && '' != ($_content = $layout_manager->widgetDisplay($list_field)) ) |
| 503 | 503 | { |
| 504 | 504 | $button_contents[] = $_content; |
@@ -508,15 +508,15 @@ discard block |
||
| 508 | 508 | { |
| 509 | 509 | $button_contents[] = ''; |
| 510 | 510 | } |
| 511 | - } else { |
|
| 512 | - $count++; |
|
| 513 | - $this->xTemplate->assign('CLASS', ""); |
|
| 514 | - $widget_contents = $layout_manager->widgetDisplay($list_field); |
|
| 515 | - $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 516 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 517 | - $this->xTemplate->assign('CELL', $widget_contents); |
|
| 518 | - $this->xTemplate->parse($xtemplateSection.".row.cell"); |
|
| 519 | - } |
|
| 511 | + } else { |
|
| 512 | + $count++; |
|
| 513 | + $this->xTemplate->assign('CLASS', ""); |
|
| 514 | + $widget_contents = $layout_manager->widgetDisplay($list_field); |
|
| 515 | + $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 516 | + if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 517 | + $this->xTemplate->assign('CELL', $widget_contents); |
|
| 518 | + $this->xTemplate->parse($xtemplateSection.".row.cell"); |
|
| 519 | + } |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | } |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | * All Rights Reserved. |
| 580 | 580 | * Contributor(s): ______________________________________. |
| 581 | 581 | */ |
| 582 | - function ListView() { |
|
| 582 | + function ListView() { |
|
| 583 | 583 | |
| 584 | 584 | |
| 585 | 585 | if(!$this->initialized) { |
@@ -598,11 +598,11 @@ discard block |
||
| 598 | 598 | * All Rights Reserved. |
| 599 | 599 | * Contributor(s): ______________________________________. |
| 600 | 600 | */ |
| 601 | - function setRecordsPerPage($count) { |
|
| 601 | + function setRecordsPerPage($count) { |
|
| 602 | 602 | $this->records_per_page = $count; |
| 603 | 603 | } |
| 604 | 604 | /**sets the header title */ |
| 605 | - function setHeaderTitle($value) { |
|
| 605 | + function setHeaderTitle($value) { |
|
| 606 | 606 | $this->header_title = $value; |
| 607 | 607 | } |
| 608 | 608 | /**sets the header text this is text that's appended to the header table and is usually used for the creation of buttons |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * All Rights Reserved. |
| 611 | 611 | * Contributor(s): ______________________________________. |
| 612 | 612 | */ |
| 613 | - function setHeaderText($value) { |
|
| 613 | + function setHeaderText($value) { |
|
| 614 | 614 | $this->header_text = $value; |
| 615 | 615 | } |
| 616 | 616 | /**sets the path for the XTemplate HTML file to be used this is only needed to be set if you are allowing ListView to create the XTemplate |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | * All Rights Reserved. |
| 619 | 619 | * Contributor(s): ______________________________________. |
| 620 | 620 | */ |
| 621 | - function setXTemplatePath($value) { |
|
| 621 | + function setXTemplatePath($value) { |
|
| 622 | 622 | $this->xTemplatePath= $value; |
| 623 | 623 | } |
| 624 | 624 | |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | * All Rights Reserved. |
| 628 | 628 | * Contributor(s): ______________________________________. |
| 629 | 629 | */ |
| 630 | - function initNewXTemplate($XTemplatePath, $modString, $imagePath = null) { |
|
| 630 | + function initNewXTemplate($XTemplatePath, $modString, $imagePath = null) { |
|
| 631 | 631 | $this->setXTemplatePath($XTemplatePath); |
| 632 | 632 | if(isset($modString)) |
| 633 | 633 | $this->setModStrings($modString); |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * All Rights Reserved. |
| 729 | 729 | * Contributor(s): ______________________________________. |
| 730 | 730 | */ |
| 731 | - function setQuery($where, $limit, $orderBy, $varName, $allowOrderByOveride=true) { |
|
| 731 | + function setQuery($where, $limit, $orderBy, $varName, $allowOrderByOveride=true) { |
|
| 732 | 732 | $this->query_where = $where; |
| 733 | 733 | if($this->getSessionVariable("query", "where") != $where) { |
| 734 | 734 | $this->query_where_has_changed = true; |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * All Rights Reserved. |
| 758 | 758 | * Contributor(s): ______________________________________. |
| 759 | 759 | */ |
| 760 | - function setTheme($theme) { |
|
| 760 | + function setTheme($theme) { |
|
| 761 | 761 | $this->local_theme = $theme; |
| 762 | 762 | if(isset($this->xTemplate))$this->xTemplate->assign("THEME", $this->local_theme); |
| 763 | 763 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | * All Rights Reserved. |
| 768 | 768 | * Contributor(s): ______________________________________. |
| 769 | 769 | */ |
| 770 | - function setAppStrings($app_strings) { |
|
| 770 | + function setAppStrings($app_strings) { |
|
| 771 | 771 | unset($this->local_app_strings); |
| 772 | 772 | $this->local_app_strings = $app_strings; |
| 773 | 773 | if(isset($this->xTemplate))$this->xTemplate->assign("APP", $this->local_app_strings); |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | * All Rights Reserved. |
| 779 | 779 | * Contributor(s): ______________________________________. |
| 780 | 780 | */ |
| 781 | - function setModStrings($mod_strings) { |
|
| 781 | + function setModStrings($mod_strings) { |
|
| 782 | 782 | unset($this->local_module_strings); |
| 783 | 783 | $this->local_mod_strings = $mod_strings; |
| 784 | 784 | if(isset($this->xTemplate))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | * All Rights Reserved. |
| 790 | 790 | * Contributor(s): ______________________________________. |
| 791 | 791 | */ |
| 792 | - function setImagePath($image_path) { |
|
| 792 | + function setImagePath($image_path) { |
|
| 793 | 793 | $this->local_image_path = $image_path; |
| 794 | 794 | if(empty($this->local_image_path)) { |
| 795 | 795 | $this->local_image_path = SugarThemeRegistry::get($this->local_theme)->getImagePath(); |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | * All Rights Reserved. |
| 803 | 803 | * Contributor(s): ______________________________________. |
| 804 | 804 | */ |
| 805 | - function setCurrentModule($currentModule) { |
|
| 805 | + function setCurrentModule($currentModule) { |
|
| 806 | 806 | unset($this->local_current_module); |
| 807 | 807 | $this->local_current_module = $currentModule; |
| 808 | 808 | if(isset($this->xTemplate))$this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | * All Rights Reserved. |
| 814 | 814 | * Contributor(s): ______________________________________. |
| 815 | 815 | */ |
| 816 | - function createXTemplate() { |
|
| 816 | + function createXTemplate() { |
|
| 817 | 817 | if(!isset($this->xTemplate)) { |
| 818 | 818 | if(isset($this->xTemplatePath)) { |
| 819 | 819 | |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | * All Rights Reserved. |
| 835 | 835 | * Contributor(s): ______________________________________. |
| 836 | 836 | */ |
| 837 | - function setXTemplate($newXTemplate) { |
|
| 837 | + function setXTemplate($newXTemplate) { |
|
| 838 | 838 | $this->xTemplate = $newXTemplate; |
| 839 | 839 | } |
| 840 | 840 | |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | * All Rights Reserved. |
| 844 | 844 | * Contributor(s): ______________________________________. |
| 845 | 845 | */ |
| 846 | - function getXTemplate() { |
|
| 846 | + function getXTemplate() { |
|
| 847 | 847 | return $this->xTemplate; |
| 848 | 848 | } |
| 849 | 849 | |
@@ -852,7 +852,7 @@ discard block |
||
| 852 | 852 | * All Rights Reserved. |
| 853 | 853 | * Contributor(s): ______________________________________. |
| 854 | 854 | */ |
| 855 | - function xTemplateAssign($name, $value) { |
|
| 855 | + function xTemplateAssign($name, $value) { |
|
| 856 | 856 | |
| 857 | 857 | if(!isset($this->xTemplate)) { |
| 858 | 858 | $this->createXTemplate(); |
@@ -866,15 +866,15 @@ discard block |
||
| 866 | 866 | * All Rights Reserved. |
| 867 | 867 | * Contributor(s): ______________________________________. |
| 868 | 868 | */ |
| 869 | - function getOffset($localVarName) { |
|
| 870 | - if($this->query_where_has_changed || isset($GLOBALS['record_has_changed'])) { |
|
| 871 | - $this->setSessionVariable($localVarName,"offset", 0); |
|
| 872 | - } |
|
| 873 | - $offset = $this->getSessionVariable($localVarName,"offset"); |
|
| 874 | - if(isset($offset)) { |
|
| 875 | - return $offset; |
|
| 876 | - } |
|
| 877 | - return 0; |
|
| 869 | + function getOffset($localVarName) { |
|
| 870 | + if($this->query_where_has_changed || isset($GLOBALS['record_has_changed'])) { |
|
| 871 | + $this->setSessionVariable($localVarName,"offset", 0); |
|
| 872 | + } |
|
| 873 | + $offset = $this->getSessionVariable($localVarName,"offset"); |
|
| 874 | + if(isset($offset)) { |
|
| 875 | + return $offset; |
|
| 876 | + } |
|
| 877 | + return 0; |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /**INTERNAL FUNCTION sets the offset in the session |
@@ -882,7 +882,7 @@ discard block |
||
| 882 | 882 | * All Rights Reserved. |
| 883 | 883 | * Contributor(s): ______________________________________. |
| 884 | 884 | */ |
| 885 | - function setOffset($localVarName, $value) { |
|
| 885 | + function setOffset($localVarName, $value) { |
|
| 886 | 886 | $this->setSessionVariable($localVarName, "offset", $value); |
| 887 | 887 | } |
| 888 | 888 | |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | * All Rights Reserved. |
| 892 | 892 | * Contributor(s): ______________________________________. |
| 893 | 893 | */ |
| 894 | - function setSessionVariable($localVarName,$varName, $value) { |
|
| 894 | + function setSessionVariable($localVarName,$varName, $value) { |
|
| 895 | 895 | $_SESSION[$this->local_current_module."_".$localVarName."_".$varName] = $value; |
| 896 | 896 | } |
| 897 | 897 | |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | * All Rights Reserved. |
| 907 | 907 | * Contributor(s): ______________________________________. |
| 908 | 908 | */ |
| 909 | - function getSessionVariable($localVarName,$varName) { |
|
| 909 | + function getSessionVariable($localVarName,$varName) { |
|
| 910 | 910 | //Set any variables pass in through request first |
| 911 | 911 | if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
| 912 | 912 | $this->setSessionVariable($localVarName,$varName,$_REQUEST[$this->getSessionVariableName($localVarName, $varName)]); |
@@ -941,10 +941,10 @@ discard block |
||
| 941 | 941 | function calculateSortOrder($sortOrderList) |
| 942 | 942 | { |
| 943 | 943 | $priority_map = array( |
| 944 | - 'request', |
|
| 945 | - 'session', |
|
| 946 | - 'subpaneldefs', |
|
| 947 | - 'default', |
|
| 944 | + 'request', |
|
| 945 | + 'session', |
|
| 946 | + 'subpaneldefs', |
|
| 947 | + 'default', |
|
| 948 | 948 | ); |
| 949 | 949 | |
| 950 | 950 | foreach($priority_map as $p) { |
@@ -960,33 +960,31 @@ discard block |
||
| 960 | 960 | |
| 961 | 961 | |
| 962 | 962 | /** |
| 963 | - |
|
| 964 | - * @return void |
|
| 965 | - * @param unknown $localVarName |
|
| 966 | - * @param unknown $varName |
|
| 967 | - * @desc INTERNAL FUNCTION returns the session/query variable name |
|
| 968 | - * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
| 969 | - * All Rights Reserved. |
|
| 970 | - * Contributor(s): ______________________________________.. |
|
| 971 | - */ |
|
| 963 | + * @return void |
|
| 964 | + * @param unknown $localVarName |
|
| 965 | + * @param unknown $varName |
|
| 966 | + * @desc INTERNAL FUNCTION returns the session/query variable name |
|
| 967 | + * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
| 968 | + * All Rights Reserved. |
|
| 969 | + * Contributor(s): ______________________________________.. |
|
| 970 | + */ |
|
| 972 | 971 | function getSessionVariableName($localVarName,$varName) { |
| 973 | 972 | return $this->local_current_module."_".$localVarName."_".$varName; |
| 974 | 973 | } |
| 975 | 974 | |
| 976 | 975 | /** |
| 977 | - |
|
| 978 | - * @return void |
|
| 979 | - * @param unknown $seed |
|
| 980 | - * @param unknown $xTemplateSection |
|
| 981 | - * @param unknown $html_varName |
|
| 982 | - * @desc INTERNAL FUNCTION Handles List Views using seeds that extend SugarBean |
|
| 976 | + * @return void |
|
| 977 | + * @param unknown $seed |
|
| 978 | + * @param unknown $xTemplateSection |
|
| 979 | + * @param unknown $html_varName |
|
| 980 | + * @desc INTERNAL FUNCTION Handles List Views using seeds that extend SugarBean |
|
| 983 | 981 | $XTemplateSection is the section in the XTemplate file that should be parsed usually main |
| 984 | 982 | $html_VarName is the variable name used in the XTemplateFile e.g. TASK |
| 985 | 983 | $seed is a seed that extends SugarBean |
| 986 | - * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. |
|
| 987 | - * All Rights Reserved.. |
|
| 988 | - * Contributor(s): ______________________________________.. |
|
| 989 | - */ |
|
| 984 | + * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. |
|
| 985 | + * All Rights Reserved.. |
|
| 986 | + * Contributor(s): ______________________________________.. |
|
| 987 | + */ |
|
| 990 | 988 | function processSugarBean($xtemplateSection, $html_varName, $seed) { |
| 991 | 989 | global $list_view_row_count; |
| 992 | 990 | |
@@ -1035,15 +1033,15 @@ discard block |
||
| 1035 | 1033 | |
| 1036 | 1034 | function processUnionBeans($sugarbean, $subpanel_def, $html_var = 'CELL') { |
| 1037 | 1035 | |
| 1038 | - $last_detailview_record = $this->getSessionVariable("detailview", "record"); |
|
| 1039 | - if(!empty($last_detailview_record) && $last_detailview_record != $sugarbean->id){ |
|
| 1040 | - $GLOBALS['record_has_changed'] = true; |
|
| 1041 | - } |
|
| 1042 | - $this->setSessionVariable("detailview", "record", $sugarbean->id); |
|
| 1036 | + $last_detailview_record = $this->getSessionVariable("detailview", "record"); |
|
| 1037 | + if(!empty($last_detailview_record) && $last_detailview_record != $sugarbean->id){ |
|
| 1038 | + $GLOBALS['record_has_changed'] = true; |
|
| 1039 | + } |
|
| 1040 | + $this->setSessionVariable("detailview", "record", $sugarbean->id); |
|
| 1043 | 1041 | |
| 1044 | - $current_offset = $this->getOffset($html_var); |
|
| 1045 | - $module = isset($_REQUEST['module']) ? $_REQUEST['module'] : ''; |
|
| 1046 | - $response = array(); |
|
| 1042 | + $current_offset = $this->getOffset($html_var); |
|
| 1043 | + $module = isset($_REQUEST['module']) ? $_REQUEST['module'] : ''; |
|
| 1044 | + $response = array(); |
|
| 1047 | 1045 | |
| 1048 | 1046 | // choose sort order |
| 1049 | 1047 | $sort_order = array(); |
@@ -1088,11 +1086,11 @@ discard block |
||
| 1088 | 1086 | $_SESSION['last_sub' .$this->subpanel_module. '_order'] = $this->sort_order; |
| 1089 | 1087 | $_SESSION['last_sub' .$this->subpanel_module. '_url'] = $this->getBaseURL($html_var); |
| 1090 | 1088 | |
| 1091 | - // Bug 8139 - Correct Subpanel sorting on 'name', when subpanel sorting default is 'last_name, first_name' |
|
| 1092 | - if (($this->sortby == 'name' || $this->sortby == 'last_name') && |
|
| 1093 | - str_replace(' ', '', trim($subpanel_def->_instance_properties['sort_by'])) == 'last_name,first_name') { |
|
| 1094 | - $this->sortby = 'last_name '.$this->sort_order.', first_name '; |
|
| 1095 | - } |
|
| 1089 | + // Bug 8139 - Correct Subpanel sorting on 'name', when subpanel sorting default is 'last_name, first_name' |
|
| 1090 | + if (($this->sortby == 'name' || $this->sortby == 'last_name') && |
|
| 1091 | + str_replace(' ', '', trim($subpanel_def->_instance_properties['sort_by'])) == 'last_name,first_name') { |
|
| 1092 | + $this->sortby = 'last_name '.$this->sort_order.', first_name '; |
|
| 1093 | + } |
|
| 1096 | 1094 | |
| 1097 | 1095 | if(!empty($this->response)){ |
| 1098 | 1096 | $response =& $this->response; |
@@ -1168,15 +1166,15 @@ discard block |
||
| 1168 | 1166 | return $baseurl; |
| 1169 | 1167 | } |
| 1170 | 1168 | /** |
| 1171 | - * @return void |
|
| 1172 | - * @param unknown $data |
|
| 1173 | - * @param unknown $xTemplateSection |
|
| 1174 | - * @param unknown $html_varName |
|
| 1175 | - * @desc INTERNAL FUNCTION process the List Navigation |
|
| 1176 | - * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
| 1177 | - * All Rights Reserved. |
|
| 1178 | - * Contributor(s): ______________________________________.. |
|
| 1179 | - */ |
|
| 1169 | + * @return void |
|
| 1170 | + * @param unknown $data |
|
| 1171 | + * @param unknown $xTemplateSection |
|
| 1172 | + * @param unknown $html_varName |
|
| 1173 | + * @desc INTERNAL FUNCTION process the List Navigation |
|
| 1174 | + * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
| 1175 | + * All Rights Reserved. |
|
| 1176 | + * Contributor(s): ______________________________________.. |
|
| 1177 | + */ |
|
| 1180 | 1178 | function processListNavigation($xtemplateSection, $html_varName, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean=null, $subpanel_def=null, $col_count = 20) { |
| 1181 | 1179 | |
| 1182 | 1180 | global $export_module; |
@@ -1316,8 +1314,8 @@ discard block |
||
| 1316 | 1314 | $end_record = $end_record-1; |
| 1317 | 1315 | |
| 1318 | 1316 | $script_href = "<a style=\'width: 150px\' name=\"thispage\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'if (document.MassUpdate.select_entire_list.value==1){document.MassUpdate.select_entire_list.value=0;sListView.check_all(document.MassUpdate, \"mass[]\", true, $this->records_per_page)}else {sListView.check_all(document.MassUpdate, \"mass[]\", true)};\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_CURRENT']} ({$this->records_per_page})‎</a>" |
| 1319 | - . "<a style=\'width: 150px\' name=\"selectall\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,{$row_count});\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']} ({$row_count})‎</a>" |
|
| 1320 | - . "<a style=\'width: 150px\' name=\"deselect\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.clear_all(document.MassUpdate, \"mass[]\", false);\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_NONE']}</a>"; |
|
| 1317 | + . "<a style=\'width: 150px\' name=\"selectall\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,{$row_count});\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']} ({$row_count})‎</a>" |
|
| 1318 | + . "<a style=\'width: 150px\' name=\"deselect\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.clear_all(document.MassUpdate, \"mass[]\", false);\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_NONE']}</a>"; |
|
| 1321 | 1319 | |
| 1322 | 1320 | $close_inline_img = SugarThemeRegistry::current()->getImage('close_inline', 'border=0', null, null, ".gif", $app_strings['LBL_CLOSEINLINE']); |
| 1323 | 1321 | |
@@ -1548,15 +1546,15 @@ discard block |
||
| 1548 | 1546 | |
| 1549 | 1547 | |
| 1550 | 1548 | /** |
| 1551 | - * @return void |
|
| 1552 | - * @param unknown $data |
|
| 1553 | - * @param unknown $xTemplateSection |
|
| 1554 | - * @param unknown $html_varName |
|
| 1555 | - * @desc INTERNAL FUNCTION handles the rows |
|
| 1556 | - * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
| 1557 | - * All Rights Reserved. |
|
| 1558 | - * Contributor(s): ______________________________________.. |
|
| 1559 | - */ |
|
| 1549 | + * @return void |
|
| 1550 | + * @param unknown $data |
|
| 1551 | + * @param unknown $xTemplateSection |
|
| 1552 | + * @param unknown $html_varName |
|
| 1553 | + * @desc INTERNAL FUNCTION handles the rows |
|
| 1554 | + * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
|
| 1555 | + * All Rights Reserved. |
|
| 1556 | + * Contributor(s): ______________________________________.. |
|
| 1557 | + */ |
|
| 1560 | 1558 | function processListRows($data, $xtemplateSection, $html_varName) |
| 1561 | 1559 | { |
| 1562 | 1560 | global $odd_bg; |
@@ -1753,7 +1751,7 @@ discard block |
||
| 1753 | 1751 | { |
| 1754 | 1752 | $orderBy= 'amount'; |
| 1755 | 1753 | } |
| 1756 | - $buttons = false; |
|
| 1754 | + $buttons = false; |
|
| 1757 | 1755 | $col_count = 0; |
| 1758 | 1756 | foreach($subpanel_def->get_list_fields() as $column_name=>$widget_args) |
| 1759 | 1757 | { |
@@ -1771,17 +1769,17 @@ discard block |
||
| 1771 | 1769 | } |
| 1772 | 1770 | |
| 1773 | 1771 | if (!preg_match("/_button/i", $column_name)) { |
| 1774 | - $widget_args['name']=$column_name; |
|
| 1775 | - $widget_args['sort'] = $imgArrow; |
|
| 1776 | - $widget_args['start_link_wrapper'] = $this->start_link_wrapper; |
|
| 1777 | - $widget_args['end_link_wrapper'] = $this->end_link_wrapper; |
|
| 1778 | - $widget_args['subpanel_module'] = $this->subpanel_module; |
|
| 1779 | - |
|
| 1780 | - $widget_contents = $layout_manager->widgetDisplay($widget_args); |
|
| 1781 | - $cell_width = empty($widget_args['width']) ? '' : $widget_args['width']; |
|
| 1782 | - $this->xTemplate->assign('HEADER_CELL', $widget_contents); |
|
| 1783 | - static $count; |
|
| 1784 | - if(!isset($count))$count = 0; else $count++; |
|
| 1772 | + $widget_args['name']=$column_name; |
|
| 1773 | + $widget_args['sort'] = $imgArrow; |
|
| 1774 | + $widget_args['start_link_wrapper'] = $this->start_link_wrapper; |
|
| 1775 | + $widget_args['end_link_wrapper'] = $this->end_link_wrapper; |
|
| 1776 | + $widget_args['subpanel_module'] = $this->subpanel_module; |
|
| 1777 | + |
|
| 1778 | + $widget_contents = $layout_manager->widgetDisplay($widget_args); |
|
| 1779 | + $cell_width = empty($widget_args['width']) ? '' : $widget_args['width']; |
|
| 1780 | + $this->xTemplate->assign('HEADER_CELL', $widget_contents); |
|
| 1781 | + static $count; |
|
| 1782 | + if(!isset($count))$count = 0; else $count++; |
|
| 1785 | 1783 | if($col_count == 0 || $column_name == 'name') $footable = 'data-toggle="true"'; |
| 1786 | 1784 | else { |
| 1787 | 1785 | $footable = 'data-hide="phone"'; |
@@ -1789,11 +1787,11 @@ discard block |
||
| 1789 | 1787 | if ($col_count > 4) $footable = 'data-hide="phone,phonelandscape,tablet"'; |
| 1790 | 1788 | } |
| 1791 | 1789 | $this->xTemplate->assign('FOOTABLE', $footable); |
| 1792 | - $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 1793 | - $this->xTemplate->assign('CELL_WIDTH', $cell_width); |
|
| 1794 | - $this->xTemplate->parse('dyn_list_view.header_cell'); |
|
| 1790 | + $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 1791 | + $this->xTemplate->assign('CELL_WIDTH', $cell_width); |
|
| 1792 | + $this->xTemplate->parse('dyn_list_view.header_cell'); |
|
| 1795 | 1793 | } else { |
| 1796 | - $buttons = true; |
|
| 1794 | + $buttons = true; |
|
| 1797 | 1795 | } |
| 1798 | 1796 | } |
| 1799 | 1797 | ++$col_count; |
@@ -1801,29 +1799,29 @@ discard block |
||
| 1801 | 1799 | |
| 1802 | 1800 | if($buttons) { |
| 1803 | 1801 | $this->xTemplate->assign('FOOTABLE', ''); |
| 1804 | - $this->xTemplate->assign('HEADER_CELL', " "); |
|
| 1805 | - $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 1806 | - $this->xTemplate->assign('CELL_WIDTH', $cell_width); |
|
| 1807 | - $this->xTemplate->parse('dyn_list_view.header_cell'); |
|
| 1802 | + $this->xTemplate->assign('HEADER_CELL', " "); |
|
| 1803 | + $this->xTemplate->assign('CELL_COUNT', $count); |
|
| 1804 | + $this->xTemplate->assign('CELL_WIDTH', $cell_width); |
|
| 1805 | + $this->xTemplate->parse('dyn_list_view.header_cell'); |
|
| 1808 | 1806 | } |
| 1809 | 1807 | |
| 1810 | 1808 | } |
| 1811 | 1809 | |
| 1812 | 1810 | |
| 1813 | 1811 | /** |
| 1814 | - * @return void |
|
| 1815 | - * @param unknown $seed |
|
| 1816 | - * @param unknown $xTemplateSection |
|
| 1817 | - * @param unknown $html_varName |
|
| 1818 | - * @desc PUBLIC FUNCTION Handles List Views using seeds that extend SugarBean |
|
| 1812 | + * @return void |
|
| 1813 | + * @param unknown $seed |
|
| 1814 | + * @param unknown $xTemplateSection |
|
| 1815 | + * @param unknown $html_varName |
|
| 1816 | + * @desc PUBLIC FUNCTION Handles List Views using seeds that extend SugarBean |
|
| 1819 | 1817 | $XTemplateSection is the section in the XTemplate file that should be parsed usually main |
| 1820 | 1818 | $html_VarName is the variable name used in the XTemplateFile e.g. TASK |
| 1821 | 1819 | $seed is a seed there are two types of seeds one is a subclass of SugarBean, the other is a list usually created from a sugar bean using get_list |
| 1822 | 1820 | if no XTemplate is set it will create a new XTemplate |
| 1823 | - * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. |
|
| 1824 | - * All Rights Reserved.. |
|
| 1825 | - * Contributor(s): ______________________________________.. |
|
| 1826 | - */ |
|
| 1821 | + * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. |
|
| 1822 | + * All Rights Reserved.. |
|
| 1823 | + * Contributor(s): ______________________________________.. |
|
| 1824 | + */ |
|
| 1827 | 1825 | |
| 1828 | 1826 | function processListViewTwo($seed, $xTemplateSection, $html_varName) { |
| 1829 | 1827 | global $current_user; |
@@ -1898,12 +1896,12 @@ discard block |
||
| 1898 | 1896 | return " <img border='0' src='".SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.{$ext}")."' "; |
| 1899 | 1897 | } |
| 1900 | 1898 | |
| 1901 | - function getArrowEnd() { |
|
| 1902 | - $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow.gif")); |
|
| 1899 | + function getArrowEnd() { |
|
| 1900 | + $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow.gif")); |
|
| 1903 | 1901 | |
| 1904 | 1902 | list($width,$height) = ListView::getArrowImageSize(); |
| 1905 | 1903 | |
| 1906 | - return '.'.$imgFileParts['extension']."' width='$width' height='$height' align='absmiddle' alt=".translate('LBL_SORT').">"; |
|
| 1904 | + return '.'.$imgFileParts['extension']."' width='$width' height='$height' align='absmiddle' alt=".translate('LBL_SORT').">"; |
|
| 1907 | 1905 | } |
| 1908 | 1906 | |
| 1909 | 1907 | function getArrowUpDownEnd($upDown) { |
@@ -1924,9 +1922,9 @@ discard block |
||
| 1924 | 1922 | return " width='$width' height='$height' align='absmiddle' alt='$sortStr'>"; |
| 1925 | 1923 | } |
| 1926 | 1924 | |
| 1927 | - function getArrowImageSize() { |
|
| 1928 | - // jbasicChartDashletsExpColust get the non-sort image's size.. the up and down have be the same. |
|
| 1929 | - $image = SugarThemeRegistry::current()->getImageURL("arrow.gif",false); |
|
| 1925 | + function getArrowImageSize() { |
|
| 1926 | + // jbasicChartDashletsExpColust get the non-sort image's size.. the up and down have be the same. |
|
| 1927 | + $image = SugarThemeRegistry::current()->getImageURL("arrow.gif",false); |
|
| 1930 | 1928 | |
| 1931 | 1929 | $cache_key = 'arrow_size.'.$image; |
| 1932 | 1930 | |
@@ -1958,13 +1956,13 @@ discard block |
||
| 1958 | 1956 | return $result; |
| 1959 | 1957 | } |
| 1960 | 1958 | |
| 1961 | - function getOrderByInfo($html_varName) |
|
| 1962 | - { |
|
| 1963 | - $orderBy = $this->getSessionVariable($html_varName, "OBL"); |
|
| 1964 | - $desc = $this->getSessionVariable($html_varName, $orderBy.'S'); |
|
| 1965 | - $orderBy = str_replace('.', '_', $orderBy); |
|
| 1966 | - return array($orderBy,$desc); |
|
| 1967 | - } |
|
| 1959 | + function getOrderByInfo($html_varName) |
|
| 1960 | + { |
|
| 1961 | + $orderBy = $this->getSessionVariable($html_varName, "OBL"); |
|
| 1962 | + $desc = $this->getSessionVariable($html_varName, $orderBy.'S'); |
|
| 1963 | + $orderBy = str_replace('.', '_', $orderBy); |
|
| 1964 | + return array($orderBy,$desc); |
|
| 1965 | + } |
|
| 1968 | 1966 | |
| 1969 | 1967 | function processSortArrows($html_varName) |
| 1970 | 1968 | { |
@@ -1973,25 +1971,25 @@ discard block |
||
| 1973 | 1971 | |
| 1974 | 1972 | list($orderBy,$desc) = $this->getOrderByInfo($html_varName); |
| 1975 | 1973 | |
| 1976 | - $imgArrow = "_up"; |
|
| 1977 | - if($desc) { |
|
| 1978 | - $imgArrow = "_down"; |
|
| 1979 | - } |
|
| 1980 | - /** |
|
| 1981 | - * @deprecated only used by legacy opportunites listview, nothing current. Leaving for BC |
|
| 1982 | - */ |
|
| 1983 | - if($orderBy == 'amount') |
|
| 1984 | - { |
|
| 1985 | - $this->xTemplateAssign('amount_arrow', $imgArrow); |
|
| 1986 | - } |
|
| 1987 | - else if($orderBy == 'amount_usdollar') |
|
| 1988 | - { |
|
| 1989 | - $this->xTemplateAssign('amount_usdollar_arrow', $imgArrow); |
|
| 1990 | - } |
|
| 1991 | - else |
|
| 1992 | - { |
|
| 1993 | - $this->xTemplateAssign($orderBy.'_arrow', $imgArrow); |
|
| 1994 | - } |
|
| 1974 | + $imgArrow = "_up"; |
|
| 1975 | + if($desc) { |
|
| 1976 | + $imgArrow = "_down"; |
|
| 1977 | + } |
|
| 1978 | + /** |
|
| 1979 | + * @deprecated only used by legacy opportunites listview, nothing current. Leaving for BC |
|
| 1980 | + */ |
|
| 1981 | + if($orderBy == 'amount') |
|
| 1982 | + { |
|
| 1983 | + $this->xTemplateAssign('amount_arrow', $imgArrow); |
|
| 1984 | + } |
|
| 1985 | + else if($orderBy == 'amount_usdollar') |
|
| 1986 | + { |
|
| 1987 | + $this->xTemplateAssign('amount_usdollar_arrow', $imgArrow); |
|
| 1988 | + } |
|
| 1989 | + else |
|
| 1990 | + { |
|
| 1991 | + $this->xTemplateAssign($orderBy.'_arrow', $imgArrow); |
|
| 1992 | + } |
|
| 1995 | 1993 | |
| 1996 | 1994 | $this->xTemplateAssign('arrow_end', $this->getArrowEnd()); |
| 1997 | 1995 | } |
@@ -2030,37 +2028,37 @@ discard block |
||
| 2030 | 2028 | return sugar_microtime(); |
| 2031 | 2029 | } |
| 2032 | 2030 | |
| 2033 | - /**INTERNAL FUNCTION sets a session variable keeping it local to the listview |
|
| 2031 | + /**INTERNAL FUNCTION sets a session variable keeping it local to the listview |
|
| 2034 | 2032 | not the current_module |
| 2035 | 2033 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
| 2036 | 2034 | * All Rights Reserved. |
| 2037 | 2035 | * Contributor(s): ______________________________________. |
| 2038 | 2036 | */ |
| 2039 | - function setLocalSessionVariable($localVarName,$varName, $value) { |
|
| 2037 | + function setLocalSessionVariable($localVarName,$varName, $value) { |
|
| 2040 | 2038 | $_SESSION[$localVarName."_".$varName] = $value; |
| 2041 | - } |
|
| 2039 | + } |
|
| 2042 | 2040 | |
| 2043 | - /**INTERNAL FUNCTION returns a session variable that is local to the listview, |
|
| 2041 | + /**INTERNAL FUNCTION returns a session variable that is local to the listview, |
|
| 2044 | 2042 | not the current_module |
| 2045 | 2043 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
| 2046 | 2044 | * All Rights Reserved. |
| 2047 | 2045 | * Contributor(s): ______________________________________. |
| 2048 | 2046 | */ |
| 2049 | - function getLocalSessionVariable($localVarName,$varName) { |
|
| 2047 | + function getLocalSessionVariable($localVarName,$varName) { |
|
| 2050 | 2048 | if(isset($_SESSION[$localVarName."_".$varName])) { |
| 2051 | 2049 | return $_SESSION[$localVarName."_".$varName]; |
| 2052 | 2050 | } |
| 2053 | 2051 | else{ |
| 2054 | 2052 | return ""; |
| 2055 | 2053 | } |
| 2056 | - } |
|
| 2054 | + } |
|
| 2057 | 2055 | |
| 2058 | - /* Set to true if you want Additional Details to appear in the listview |
|
| 2056 | + /* Set to true if you want Additional Details to appear in the listview |
|
| 2059 | 2057 | */ |
| 2060 | - function setAdditionalDetails($value = true, $function = '') { |
|
| 2058 | + function setAdditionalDetails($value = true, $function = '') { |
|
| 2061 | 2059 | if(!empty($function)) $this->additionalDetailsFunction = $function; |
| 2062 | 2060 | $this->_additionalDetails = $value; |
| 2063 | - } |
|
| 2061 | + } |
|
| 2064 | 2062 | |
| 2065 | 2063 | } |
| 2066 | 2064 | ?> |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | class ListView |
| 47 | 47 | { |
| 48 | - var $local_theme= null; |
|
| 49 | - var $local_app_strings= null; |
|
| 48 | + var $local_theme = null; |
|
| 49 | + var $local_app_strings = null; |
|
| 50 | 50 | var $local_image_path = null; |
| 51 | 51 | var $local_current_module = null; |
| 52 | 52 | var $local_mod_strings = null; |
@@ -81,12 +81,12 @@ discard block |
||
| 81 | 81 | var $child_focus = ''; |
| 82 | 82 | var $layout_manager = null; |
| 83 | 83 | var $process_for_popups = false; |
| 84 | - var $multi_select_popup=false; |
|
| 84 | + var $multi_select_popup = false; |
|
| 85 | 85 | var $_additionalDetails = false; |
| 86 | 86 | var $additionalDetailsFunction = null; |
| 87 | 87 | var $sort_order = ''; |
| 88 | - var $force_mass_update=false; |
|
| 89 | - var $keep_mass_update_form_open=false; |
|
| 88 | + var $force_mass_update = false; |
|
| 89 | + var $keep_mass_update_form_open = false; |
|
| 90 | 90 | var $ignorePopulateOnly = false; |
| 91 | 91 | |
| 92 | 92 | function setDataArray($value) { |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | echo "<form name='MassUpdate' method='post' action='index.php'>"; |
| 101 | 101 | $this->processListViewTwo($seed, $xTemplateSection, $html_varName); |
| 102 | 102 | |
| 103 | - echo "<a href='javascript:" . ((!$this->multi_select_popup) ? 'sListView.' : ''). "check_all(document.MassUpdate, \"mass[]\", true)'>".translate('LBL_CHECKALL')."</a> - <a href='javascript:sListView.check_all(document.MassUpdate, \"mass[]\", false);'>".translate('LBL_CLEARALL')."</a>"; |
|
| 103 | + echo "<a href='javascript:".((!$this->multi_select_popup) ? 'sListView.' : '')."check_all(document.MassUpdate, \"mass[]\", true)'>".translate('LBL_CHECKALL')."</a> - <a href='javascript:sListView.check_all(document.MassUpdate, \"mass[]\", false);'>".translate('LBL_CLEARALL')."</a>"; |
|
| 104 | 104 | echo '<br><br>'; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,109 +110,109 @@ discard block |
||
| 110 | 110 | global $sugar_config; |
| 111 | 111 | |
| 112 | 112 | $populateOnly = $this->ignorePopulateOnly ? FALSE : (!empty($sugar_config['save_query']) && $sugar_config['save_query'] == 'populate_only'); |
| 113 | - if(isset($seed->module_dir) && $populateOnly) { |
|
| 114 | - if(empty($GLOBALS['displayListView']) && strcmp(strtolower($_REQUEST['action']), 'popup') != 0 && (!empty($_REQUEST['clear_query']) || $_REQUEST['module'] == $seed->module_dir && ((empty($_REQUEST['query']) || $_REQUEST['query'] == 'MSI')&& (empty($_SESSION['last_search_mod']) || $_SESSION['last_search_mod'] != $seed->module_dir)))) { |
|
| 115 | - $_SESSION['last_search_mod'] = $_REQUEST['module'] ; |
|
| 113 | + if (isset($seed->module_dir) && $populateOnly) { |
|
| 114 | + if (empty($GLOBALS['displayListView']) && strcmp(strtolower($_REQUEST['action']), 'popup') != 0 && (!empty($_REQUEST['clear_query']) || $_REQUEST['module'] == $seed->module_dir && ((empty($_REQUEST['query']) || $_REQUEST['query'] == 'MSI') && (empty($_SESSION['last_search_mod']) || $_SESSION['last_search_mod'] != $seed->module_dir)))) { |
|
| 115 | + $_SESSION['last_search_mod'] = $_REQUEST['module']; |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | - if(strcmp(strtolower($_REQUEST['action']), 'popup') != 0){ |
|
| 120 | - $_SESSION['last_search_mod'] = $_REQUEST['module'] ; |
|
| 119 | + if (strcmp(strtolower($_REQUEST['action']), 'popup') != 0) { |
|
| 120 | + $_SESSION['last_search_mod'] = $_REQUEST['module']; |
|
| 121 | 121 | } |
| 122 | 122 | //following session variable will track the detail view navigation history. |
| 123 | 123 | //needs to the reset after each search. |
| 124 | - $this->setLocalSessionVariable($html_varName,"DETAIL_NAV_HISTORY",false); |
|
| 124 | + $this->setLocalSessionVariable($html_varName, "DETAIL_NAV_HISTORY", false); |
|
| 125 | 125 | |
| 126 | 126 | require_once('include/MassUpdate.php'); |
| 127 | 127 | $mass = new MassUpdate(); |
| 128 | 128 | $add_acl_javascript = false; |
| 129 | - if(!isset($_REQUEST['action'])) { |
|
| 130 | - $this->shouldProcess=false; |
|
| 129 | + if (!isset($_REQUEST['action'])) { |
|
| 130 | + $this->shouldProcess = false; |
|
| 131 | 131 | } else { |
| 132 | 132 | $this->shouldProcess = is_subclass_of($seed, "SugarBean") |
| 133 | - && (($_REQUEST['action'] == 'index') || ('ListView' == substr($_REQUEST['action'],0,8)) /* cn: to include all ListViewXXX.php type views */) |
|
| 133 | + && (($_REQUEST['action'] == 'index') || ('ListView' == substr($_REQUEST['action'], 0, 8)) /* cn: to include all ListViewXXX.php type views */) |
|
| 134 | 134 | && ($_REQUEST['module'] == $seed->module_dir); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | //when processing a multi-select popup. |
| 138 | - if($this->process_for_popups && $this->multi_select_popup) $this->shouldProcess =true; |
|
| 138 | + if ($this->process_for_popups && $this->multi_select_popup) $this->shouldProcess = true; |
|
| 139 | 139 | //mass update turned off? |
| 140 | - if(!$this->show_mass_update) $this->shouldProcess = false; |
|
| 141 | - if(is_subclass_of($seed, "SugarBean")) { |
|
| 142 | - if($seed->bean_implements('ACL')) { |
|
| 143 | - if(!ACLController::checkAccess($seed->module_dir,'list',true)) { |
|
| 144 | - if($_REQUEST['module'] != 'Home') { |
|
| 140 | + if (!$this->show_mass_update) $this->shouldProcess = false; |
|
| 141 | + if (is_subclass_of($seed, "SugarBean")) { |
|
| 142 | + if ($seed->bean_implements('ACL')) { |
|
| 143 | + if (!ACLController::checkAccess($seed->module_dir, 'list', true)) { |
|
| 144 | + if ($_REQUEST['module'] != 'Home') { |
|
| 145 | 145 | ACLController::displayNoAccess(); |
| 146 | 146 | } |
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | - if(!ACLController::checkAccess($seed->module_dir,'export',true)) { |
|
| 150 | - $sugar_config['disable_export']= true; |
|
| 149 | + if (!ACLController::checkAccess($seed->module_dir, 'export', true)) { |
|
| 150 | + $sugar_config['disable_export'] = true; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | //force mass update form if requested. |
| 157 | - if($this->force_mass_update) { |
|
| 157 | + if ($this->force_mass_update) { |
|
| 158 | 158 | $this->shouldProcess = true; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if($this->shouldProcess) { |
|
| 161 | + if ($this->shouldProcess) { |
|
| 162 | 162 | echo $mass->getDisplayMassUpdateForm(true, $this->multi_select_popup); |
| 163 | 163 | echo $mass->getMassUpdateFormHeader($this->multi_select_popup); |
| 164 | 164 | $mass->setSugarBean($seed); |
| 165 | 165 | |
| 166 | 166 | //C.L. Fix for 10048, do not process handleMassUpdate for multi select popups |
| 167 | - if(!$this->multi_select_popup) { |
|
| 167 | + if (!$this->multi_select_popup) { |
|
| 168 | 168 | $mass->handleMassUpdate(); |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - $this->processListViewTwo($seed,$xTemplateSection, $html_varName); |
|
| 172 | + $this->processListViewTwo($seed, $xTemplateSection, $html_varName); |
|
| 173 | 173 | |
| 174 | - if($this->shouldProcess && empty($this->process_for_popups)) { |
|
| 174 | + if ($this->shouldProcess && empty($this->process_for_popups)) { |
|
| 175 | 175 | //echo "<a href='javascript:sListView.clear_all(document.MassUpdate, \"mass[]\");'>".translate('LBL_CLEARALL')."</a>"; |
| 176 | 176 | // cn: preserves current functionality, exception is InboundEmail |
| 177 | - if($this->show_mass_update_form) { |
|
| 177 | + if ($this->show_mass_update_form) { |
|
| 178 | 178 | echo $mass->getMassUpdateForm(); |
| 179 | 179 | } |
| 180 | - if(!$this->keep_mass_update_form_open) { |
|
| 180 | + if (!$this->keep_mass_update_form_open) { |
|
| 181 | 181 | echo $mass->endMassUpdateForm(); |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
| 187 | -function process_dynamic_listview($source_module, $sugarbean,$subpanel_def) |
|
| 187 | +function process_dynamic_listview($source_module, $sugarbean, $subpanel_def) |
|
| 188 | 188 | { |
| 189 | 189 | $this->source_module = $source_module; |
| 190 | 190 | $this->subpanel_module = $subpanel_def->name; |
| 191 | - if(!isset($this->xTemplate)) |
|
| 191 | + if (!isset($this->xTemplate)) |
|
| 192 | 192 | $this->createXTemplate(); |
| 193 | 193 | |
| 194 | - $html_var = $this->subpanel_module . "_CELL"; |
|
| 194 | + $html_var = $this->subpanel_module."_CELL"; |
|
| 195 | 195 | |
| 196 | - $list_data = $this->processUnionBeans($sugarbean,$subpanel_def, $html_var); |
|
| 196 | + $list_data = $this->processUnionBeans($sugarbean, $subpanel_def, $html_var); |
|
| 197 | 197 | |
| 198 | 198 | $list = $list_data['list']; |
| 199 | 199 | $parent_data = $list_data['parent_data']; |
| 200 | 200 | |
| 201 | - if($subpanel_def->isCollection()) { |
|
| 202 | - $thepanel=$subpanel_def->get_header_panel_def(); |
|
| 201 | + if ($subpanel_def->isCollection()) { |
|
| 202 | + $thepanel = $subpanel_def->get_header_panel_def(); |
|
| 203 | 203 | } else { |
| 204 | - $thepanel=$subpanel_def; |
|
| 204 | + $thepanel = $subpanel_def; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
| 208 | 208 | |
| 209 | 209 | $this->process_dynamic_listview_header($thepanel->get_module_name(), $thepanel, $html_var); |
| 210 | - $this->process_dynamic_listview_rows($list,$parent_data, 'dyn_list_view', $html_var,$subpanel_def); |
|
| 210 | + $this->process_dynamic_listview_rows($list, $parent_data, 'dyn_list_view', $html_var, $subpanel_def); |
|
| 211 | 211 | |
| 212 | - if($this->display_header_and_footer) |
|
| 212 | + if ($this->display_header_and_footer) |
|
| 213 | 213 | { |
| 214 | 214 | $this->getAdditionalHeader(); |
| 215 | - if(!empty($this->header_title)) |
|
| 215 | + if (!empty($this->header_title)) |
|
| 216 | 216 | { |
| 217 | 217 | echo get_form_header($this->header_title, $this->header_text, false); |
| 218 | 218 | } |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | |
| 221 | 221 | $this->xTemplate->out('dyn_list_view'); |
| 222 | 222 | |
| 223 | - if(isset($_SESSION['validation'])) |
|
| 223 | + if (isset($_SESSION['validation'])) |
|
| 224 | 224 | { |
| 225 | 225 | print base64_decode('PGEgaHJlZj0naHR0cDovL3d3dy5zdWdhcmNybS5jb20nPlBPV0VSRUQmbmJzcDtCWSZuYnNwO1NVR0FSQ1JNPC9hPg=='); |
| 226 | 226 | } |
| 227 | - if(isset($list_data['query'])) { |
|
| 227 | + if (isset($list_data['query'])) { |
|
| 228 | 228 | return ($list_data['query']); |
| 229 | 229 | } |
| 230 | 230 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @param unknown $html_varName |
| 237 | 237 | * @desc INTERNAL FUNCTION handles the rows |
| 238 | 238 | */ |
| 239 | - function process_dynamic_listview_rows($data,$parent_data, $xtemplateSection, $html_varName, $subpanel_def) |
|
| 239 | + function process_dynamic_listview_rows($data, $parent_data, $xtemplateSection, $html_varName, $subpanel_def) |
|
| 240 | 240 | { |
| 241 | 241 | global $subpanel_item_count; |
| 242 | 242 | global $odd_bg; |
@@ -261,37 +261,37 @@ discard block |
||
| 261 | 261 | //Either retrieve the is_fill_in_additional_fields property from the lone |
| 262 | 262 | //subpanel or visit each subpanel's subpanels to retrieve the is_fill_in_addition_fields |
| 263 | 263 | //property |
| 264 | - $subpanel_list=array(); |
|
| 265 | - if($subpanel_def->isCollection()) { |
|
| 266 | - $subpanel_list=$subpanel_def->sub_subpanels; |
|
| 264 | + $subpanel_list = array(); |
|
| 265 | + if ($subpanel_def->isCollection()) { |
|
| 266 | + $subpanel_list = $subpanel_def->sub_subpanels; |
|
| 267 | 267 | } else { |
| 268 | - $subpanel_list[]= $subpanel_def; |
|
| 268 | + $subpanel_list[] = $subpanel_def; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - foreach($subpanel_list as $this_subpanel) |
|
| 271 | + foreach ($subpanel_list as $this_subpanel) |
|
| 272 | 272 | { |
| 273 | - if($this_subpanel->is_fill_in_additional_fields()) |
|
| 273 | + if ($this_subpanel->is_fill_in_additional_fields()) |
|
| 274 | 274 | { |
| 275 | 275 | $fill_additional_fields[] = $this_subpanel->bean_name; |
| 276 | 276 | $fill_additional_fields[$this_subpanel->bean_name] = true; |
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - if ( empty($data) ) { |
|
| 280 | + if (empty($data)) { |
|
| 281 | 281 | $this->xTemplate->assign("ROW_COLOR", 'oddListRow'); |
| 282 | - $thepanel=$subpanel_def; |
|
| 283 | - if($subpanel_def->isCollection()) |
|
| 284 | - $thepanel=$subpanel_def->get_header_panel_def(); |
|
| 282 | + $thepanel = $subpanel_def; |
|
| 283 | + if ($subpanel_def->isCollection()) |
|
| 284 | + $thepanel = $subpanel_def->get_header_panel_def(); |
|
| 285 | 285 | $this->xTemplate->assign("COL_COUNT", count($thepanel->get_list_fields())); |
| 286 | 286 | $this->xTemplate->parse($xtemplateSection.".nodata"); |
| 287 | 287 | } |
| 288 | - while(list($aVal, $aItem) = each($data)) |
|
| 288 | + while (list($aVal, $aItem) = each($data)) |
|
| 289 | 289 | { |
| 290 | 290 | $subpanel_item_count++; |
| 291 | 291 | $aItem->check_date_relationships_load(); |
| 292 | 292 | // TODO: expensive and needs to be removed and done better elsewhere |
| 293 | 293 | |
| 294 | - if(!empty($fill_additional_fields[$aItem->object_name]) |
|
| 294 | + if (!empty($fill_additional_fields[$aItem->object_name]) |
|
| 295 | 295 | || ($aItem->object_name == 'Case' && !empty($fill_additional_fields['aCase'])) |
| 296 | 296 | ) |
| 297 | 297 | { |
@@ -301,15 +301,15 @@ discard block |
||
| 301 | 301 | //rrs bug: 25343 |
| 302 | 302 | $aItem->call_custom_logic("process_record"); |
| 303 | 303 | |
| 304 | - if(isset($parent_data[$aItem->id])) { |
|
| 304 | + if (isset($parent_data[$aItem->id])) { |
|
| 305 | 305 | |
| 306 | 306 | $aItem->parent_name = $parent_data[$aItem->id]['parent_name']; |
| 307 | - if(!empty($parent_data[$aItem->id]['parent_name_owner'])) { |
|
| 308 | - $aItem->parent_name_owner = $parent_data[$aItem->id]['parent_name_owner']; |
|
| 309 | - $aItem->parent_name_mod = $parent_data[$aItem->id]['parent_name_mod']; |
|
| 307 | + if (!empty($parent_data[$aItem->id]['parent_name_owner'])) { |
|
| 308 | + $aItem->parent_name_owner = $parent_data[$aItem->id]['parent_name_owner']; |
|
| 309 | + $aItem->parent_name_mod = $parent_data[$aItem->id]['parent_name_mod']; |
|
| 310 | 310 | }} |
| 311 | 311 | $fields = $aItem->get_list_view_data(); |
| 312 | - if(isset($processed_ids[$aItem->id])) { |
|
| 312 | + if (isset($processed_ids[$aItem->id])) { |
|
| 313 | 313 | continue; |
| 314 | 314 | |
| 315 | 315 | } else { |
@@ -320,50 +320,50 @@ discard block |
||
| 320 | 320 | //ADD OFFSET TO ARRAY |
| 321 | 321 | $fields['OFFSET'] = ($offset + $count + 1); |
| 322 | 322 | |
| 323 | - if($this->shouldProcess) { |
|
| 324 | - if($aItem->ACLAccess('EditView')) { |
|
| 325 | - $this->xTemplate->assign('PREROW', "<input type='checkbox' class='checkbox' name='mass[]' value='". $fields['ID']. "' />"); |
|
| 323 | + if ($this->shouldProcess) { |
|
| 324 | + if ($aItem->ACLAccess('EditView')) { |
|
| 325 | + $this->xTemplate->assign('PREROW', "<input type='checkbox' class='checkbox' name='mass[]' value='".$fields['ID']."' />"); |
|
| 326 | 326 | } else { |
| 327 | 327 | $this->xTemplate->assign('PREROW', ''); |
| 328 | 328 | |
| 329 | 329 | } |
| 330 | - if($aItem->ACLAccess('DetailView')) { |
|
| 331 | - $this->xTemplate->assign('TAG_NAME','a'); |
|
| 330 | + if ($aItem->ACLAccess('DetailView')) { |
|
| 331 | + $this->xTemplate->assign('TAG_NAME', 'a'); |
|
| 332 | 332 | } else { |
| 333 | - $this->xTemplate->assign('TAG_NAME','span'); |
|
| 333 | + $this->xTemplate->assign('TAG_NAME', 'span'); |
|
| 334 | 334 | } |
| 335 | 335 | $this->xTemplate->assign('CHECKALL', "<input type='checkbox' title='".$GLOBALS['app_strings']['LBL_SELECT_ALL_TITLE']."' class='checkbox' name='massall' id='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked);' />"); |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - if($oddRow) |
|
| 338 | + if ($oddRow) |
|
| 339 | 339 | { |
| 340 | 340 | $ROW_COLOR = 'oddListRow'; |
| 341 | - $BG_COLOR = $odd_bg; |
|
| 341 | + $BG_COLOR = $odd_bg; |
|
| 342 | 342 | } |
| 343 | 343 | else |
| 344 | 344 | { |
| 345 | 345 | $ROW_COLOR = 'evenListRow'; |
| 346 | - $BG_COLOR = $even_bg; |
|
| 346 | + $BG_COLOR = $even_bg; |
|
| 347 | 347 | } |
| 348 | 348 | $oddRow = !$oddRow; |
| 349 | 349 | $button_contents = array(); |
| 350 | 350 | $this->xTemplate->assign("ROW_COLOR", $ROW_COLOR); |
| 351 | 351 | $this->xTemplate->assign("BG_COLOR", $BG_COLOR); |
| 352 | 352 | $layout_manager = $this->getLayoutManager(); |
| 353 | - $layout_manager->setAttribute('context','List'); |
|
| 354 | - $layout_manager->setAttribute('image_path',$this->local_image_path); |
|
| 353 | + $layout_manager->setAttribute('context', 'List'); |
|
| 354 | + $layout_manager->setAttribute('image_path', $this->local_image_path); |
|
| 355 | 355 | $layout_manager->setAttribute('module_name', $subpanel_def->_instance_properties['module']); |
| 356 | - if(!empty($this->child_focus)) |
|
| 357 | - $layout_manager->setAttribute('related_module_name',$this->child_focus->module_dir); |
|
| 356 | + if (!empty($this->child_focus)) |
|
| 357 | + $layout_manager->setAttribute('related_module_name', $this->child_focus->module_dir); |
|
| 358 | 358 | |
| 359 | 359 | //AG$subpanel_data = $this->list_field_defs; |
| 360 | 360 | //$bla = array_pop($subpanel_data); |
| 361 | 361 | //select which sub-panel to display here, the decision will be made based on the type of |
| 362 | 362 | //the sub-panel and panel in the bean being processed. |
| 363 | - if($subpanel_def->isCollection()) { |
|
| 364 | - $thepanel=$subpanel_def->sub_subpanels[$aItem->panel_name]; |
|
| 363 | + if ($subpanel_def->isCollection()) { |
|
| 364 | + $thepanel = $subpanel_def->sub_subpanels[$aItem->panel_name]; |
|
| 365 | 365 | } else { |
| 366 | - $thepanel=$subpanel_def; |
|
| 366 | + $thepanel = $subpanel_def; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /* BEGIN - SECURITY GROUPS */ |
@@ -374,22 +374,22 @@ discard block |
||
| 374 | 374 | $aclaccess_in_group = false; |
| 375 | 375 | |
| 376 | 376 | global $current_user; |
| 377 | - if(is_admin($current_user)) { |
|
| 377 | + if (is_admin($current_user)) { |
|
| 378 | 378 | $aclaccess_is_owner = true; |
| 379 | 379 | } else { |
| 380 | 380 | $aclaccess_is_owner = $aItem->isOwner($current_user->id); |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | require_once("modules/SecurityGroups/SecurityGroup.php"); |
| 384 | - $aclaccess_in_group = SecurityGroup::groupHasAccess($aItem->module_dir,$aItem->id); |
|
| 384 | + $aclaccess_in_group = SecurityGroup::groupHasAccess($aItem->module_dir, $aItem->id); |
|
| 385 | 385 | |
| 386 | 386 | /* END - SECURITY GROUPS */ |
| 387 | 387 | |
| 388 | 388 | //get data source name |
| 389 | - $linked_field=$thepanel->get_data_source_name(); |
|
| 390 | - $linked_field_set=$thepanel->get_data_source_name(true); |
|
| 389 | + $linked_field = $thepanel->get_data_source_name(); |
|
| 390 | + $linked_field_set = $thepanel->get_data_source_name(true); |
|
| 391 | 391 | static $count; |
| 392 | - if(!isset($count))$count = 0; |
|
| 392 | + if (!isset($count))$count = 0; |
|
| 393 | 393 | /* BEGIN - SECURITY GROUPS */ |
| 394 | 394 | /** |
| 395 | 395 | $field_acl['DetailView'] = $aItem->ACLAccess('DetailView'); |
@@ -398,19 +398,19 @@ discard block |
||
| 398 | 398 | $field_acl['Delete'] = $aItem->ACLAccess('Delete'); |
| 399 | 399 | */ |
| 400 | 400 | //pass is_owner, in_group...vars defined above |
| 401 | - $field_acl['DetailView'] = $aItem->ACLAccess('DetailView',$aclaccess_is_owner,$aclaccess_in_group); |
|
| 402 | - $field_acl['ListView'] = $aItem->ACLAccess('ListView',$aclaccess_is_owner,$aclaccess_in_group); |
|
| 403 | - $field_acl['EditView'] = $aItem->ACLAccess('EditView',$aclaccess_is_owner,$aclaccess_in_group); |
|
| 404 | - $field_acl['Delete'] = $aItem->ACLAccess('Delete',$aclaccess_is_owner,$aclaccess_in_group); |
|
| 401 | + $field_acl['DetailView'] = $aItem->ACLAccess('DetailView', $aclaccess_is_owner, $aclaccess_in_group); |
|
| 402 | + $field_acl['ListView'] = $aItem->ACLAccess('ListView', $aclaccess_is_owner, $aclaccess_in_group); |
|
| 403 | + $field_acl['EditView'] = $aItem->ACLAccess('EditView', $aclaccess_is_owner, $aclaccess_in_group); |
|
| 404 | + $field_acl['Delete'] = $aItem->ACLAccess('Delete', $aclaccess_is_owner, $aclaccess_in_group); |
|
| 405 | 405 | /* END - SECURITY GROUPS */ |
| 406 | - foreach($thepanel->get_list_fields() as $field_name=>$list_field) |
|
| 406 | + foreach ($thepanel->get_list_fields() as $field_name=>$list_field) |
|
| 407 | 407 | { |
| 408 | 408 | //add linked field attribute to the array. |
| 409 | - $list_field['linked_field']=$linked_field; |
|
| 410 | - $list_field['linked_field_set']=$linked_field_set; |
|
| 409 | + $list_field['linked_field'] = $linked_field; |
|
| 410 | + $list_field['linked_field_set'] = $linked_field_set; |
|
| 411 | 411 | |
| 412 | 412 | $usage = empty($list_field['usage']) ? '' : $list_field['usage']; |
| 413 | - if($usage == 'query_only' && !empty($list_field['force_query_only_display'])){ |
|
| 413 | + if ($usage == 'query_only' && !empty($list_field['force_query_only_display'])) { |
|
| 414 | 414 | //if you are here you have column that is query only but needs to be displayed as blank. This is helpful |
| 415 | 415 | //for collections such as Activities where you have a field in only one object and wish to show it in the subpanel list |
| 416 | 416 | $count++; |
@@ -420,13 +420,13 @@ discard block |
||
| 420 | 420 | $this->xTemplate->assign('CELL', $widget_contents); |
| 421 | 421 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 422 | 422 | |
| 423 | - }else if($usage != 'query_only') |
|
| 423 | + } else if ($usage != 'query_only') |
|
| 424 | 424 | { |
| 425 | - $list_field['name']=$field_name; |
|
| 425 | + $list_field['name'] = $field_name; |
|
| 426 | 426 | |
| 427 | 427 | $module_field = $field_name.'_mod'; |
| 428 | 428 | $owner_field = $field_name.'_owner'; |
| 429 | - if(!empty($aItem->$module_field)) { |
|
| 429 | + if (!empty($aItem->$module_field)) { |
|
| 430 | 430 | |
| 431 | 431 | $list_field['owner_id'] = $aItem->$owner_field; |
| 432 | 432 | $list_field['owner_module'] = $aItem->$module_field; |
@@ -435,71 +435,71 @@ discard block |
||
| 435 | 435 | $list_field['owner_id'] = false; |
| 436 | 436 | $list_field['owner_module'] = false; |
| 437 | 437 | } |
| 438 | - if(isset($list_field['alias'])) $list_field['name'] = $list_field['alias']; |
|
| 439 | - else $list_field['name']=$field_name; |
|
| 438 | + if (isset($list_field['alias'])) $list_field['name'] = $list_field['alias']; |
|
| 439 | + else $list_field['name'] = $field_name; |
|
| 440 | 440 | $list_field['fields'] = $fields; |
| 441 | 441 | $list_field['module'] = $aItem->module_dir; |
| 442 | 442 | $list_field['start_link_wrapper'] = $this->start_link_wrapper; |
| 443 | 443 | $list_field['end_link_wrapper'] = $this->end_link_wrapper; |
| 444 | 444 | $list_field['subpanel_id'] = $this->subpanel_id; |
| 445 | 445 | $list_field += $field_acl; |
| 446 | - if ( isset($aItem->field_defs[strtolower($list_field['name'])])) { |
|
| 446 | + if (isset($aItem->field_defs[strtolower($list_field['name'])])) { |
|
| 447 | 447 | require_once('include/SugarFields/SugarFieldHandler.php'); |
| 448 | 448 | // We need to see if a sugar field exists for this field type first, |
| 449 | 449 | // if it doesn't, toss it at the old sugarWidgets. This is for |
| 450 | 450 | // backwards compatibility and will be removed in a future release |
| 451 | 451 | $vardef = $aItem->field_defs[strtolower($list_field['name'])]; |
| 452 | - if ( isset($vardef['type']) ) { |
|
| 453 | - $fieldType = isset($vardef['custom_type'])?$vardef['custom_type']:$vardef['type']; |
|
| 454 | - $tmpField = SugarFieldHandler::getSugarField($fieldType,true); |
|
| 452 | + if (isset($vardef['type'])) { |
|
| 453 | + $fieldType = isset($vardef['custom_type']) ? $vardef['custom_type'] : $vardef['type']; |
|
| 454 | + $tmpField = SugarFieldHandler::getSugarField($fieldType, true); |
|
| 455 | 455 | } else { |
| 456 | 456 | $tmpField = NULL; |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - if ( $tmpField != NULL ) { |
|
| 460 | - $widget_contents = SugarFieldHandler::displaySmarty($list_field['fields'],$vardef,'ListView',$list_field); |
|
| 459 | + if ($tmpField != NULL) { |
|
| 460 | + $widget_contents = SugarFieldHandler::displaySmarty($list_field['fields'], $vardef, 'ListView', $list_field); |
|
| 461 | 461 | } else { |
| 462 | 462 | // No SugarField for this particular type |
| 463 | 463 | // Use the old, icky, SugarWidget for now |
| 464 | 464 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if ( isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelDetailViewLink' ) { |
|
| 467 | + if (isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelDetailViewLink') { |
|
| 468 | 468 | // We need to call into the old SugarWidgets for the time being, so it can generate a proper link with all the various corner-cases handled |
| 469 | 469 | // So we'll populate the field data with the pre-rendered display for the field |
| 470 | 470 | $list_field['fields'][$field_name] = $widget_contents; |
| 471 | - if('full_name' == $field_name){//bug #32465 |
|
| 471 | + if ('full_name' == $field_name) {//bug #32465 |
|
| 472 | 472 | $list_field['fields'][strtoupper($field_name)] = $widget_contents; |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | //vardef source is non db, assign the field name to varname for processing of column. |
| 476 | - if(!empty($vardef['source']) && $vardef['source']=='non-db'){ |
|
| 476 | + if (!empty($vardef['source']) && $vardef['source'] == 'non-db') { |
|
| 477 | 477 | $list_field['varname'] = $field_name; |
| 478 | 478 | |
| 479 | 479 | } |
| 480 | 480 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 481 | - } else if(isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelEmailLink' ) { |
|
| 481 | + } else if (isset($list_field['widget_class']) && $list_field['widget_class'] == 'SubPanelEmailLink') { |
|
| 482 | 482 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | $count++; |
| 486 | 486 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 487 | 487 | $this->xTemplate->assign('CLASS', ""); |
| 488 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 488 | + if (empty($widget_contents)) $widget_contents = ' '; |
|
| 489 | 489 | $this->xTemplate->assign('CELL', $widget_contents); |
| 490 | 490 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 491 | 491 | } else { |
| 492 | 492 | // This handles the edit and remove buttons and icon widget |
| 493 | - if( isset($list_field['widget_class']) && $list_field['widget_class'] == "SubPanelIcon") { |
|
| 493 | + if (isset($list_field['widget_class']) && $list_field['widget_class'] == "SubPanelIcon") { |
|
| 494 | 494 | $count++; |
| 495 | 495 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 496 | 496 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 497 | 497 | $this->xTemplate->assign('CLASS', ""); |
| 498 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 498 | + if (empty($widget_contents)) $widget_contents = ' '; |
|
| 499 | 499 | $this->xTemplate->assign('CELL', $widget_contents); |
| 500 | 500 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 501 | 501 | } elseif (preg_match("/button/i", $list_field['name'])) { |
| 502 | - if ((($list_field['name'] === 'edit_button' && $field_acl['EditView']) || ($list_field['name'] === 'close_button' && $field_acl['EditView']) || ($list_field['name'] === 'remove_button' && $field_acl['Delete'])) && '' != ($_content = $layout_manager->widgetDisplay($list_field)) ) |
|
| 502 | + if ((($list_field['name'] === 'edit_button' && $field_acl['EditView']) || ($list_field['name'] === 'close_button' && $field_acl['EditView']) || ($list_field['name'] === 'remove_button' && $field_acl['Delete'])) && '' != ($_content = $layout_manager->widgetDisplay($list_field))) |
|
| 503 | 503 | { |
| 504 | 504 | $button_contents[] = $_content; |
| 505 | 505 | unset($_content); |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | $this->xTemplate->assign('CLASS', ""); |
| 514 | 514 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 515 | 515 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 516 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 516 | + if (empty($widget_contents)) $widget_contents = ' '; |
|
| 517 | 517 | $this->xTemplate->assign('CELL', $widget_contents); |
| 518 | 518 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 519 | 519 | } |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | |
| 526 | 526 | // Make sure we have at least one button before rendering a column for |
| 527 | 527 | // the action buttons in a list view. Relevant bugs: #51647 and #51640. |
| 528 | - if(!empty($button_contents)) |
|
| 528 | + if (!empty($button_contents)) |
|
| 529 | 529 | { |
| 530 | 530 | $button_contents = array_filter($button_contents); |
| 531 | 531 | if (!empty($button_contents)) |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | // bug#51275: smarty widget to help provide the action menu functionality as it is currently sprinkled throughout the app with html |
| 535 | 535 | require_once('include/Smarty/plugins/function.sugar_action_menu.php'); |
| 536 | 536 | $tempid = create_guid(); |
| 537 | - array_unshift($button_contents, "<div style='display: inline' id='$tempid'>" . array_shift($button_contents) . "</div>"); |
|
| 537 | + array_unshift($button_contents, "<div style='display: inline' id='$tempid'>".array_shift($button_contents)."</div>"); |
|
| 538 | 538 | $action_button = smarty_function_sugar_action_menu(array( |
| 539 | 539 | 'id' => $tempid, |
| 540 | 540 | 'buttons' => $button_contents, |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | $this->xTemplate->assign('CELL_COUNT', ++$count); |
| 551 | 551 | //Bug#51275 for beta3 pre_script is not required any more |
| 552 | 552 | $this->xTemplate->assign('CELL', $action_button); |
| 553 | - $this->xTemplate->parse($xtemplateSection . ".row.cell"); |
|
| 553 | + $this->xTemplate->parse($xtemplateSection.".row.cell"); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -582,13 +582,13 @@ discard block |
||
| 582 | 582 | function ListView() { |
| 583 | 583 | |
| 584 | 584 | |
| 585 | - if(!$this->initialized) { |
|
| 585 | + if (!$this->initialized) { |
|
| 586 | 586 | global $sugar_config; |
| 587 | 587 | $this->records_per_page = $sugar_config['list_max_entries_per_page'] + 0; |
| 588 | 588 | $this->initialized = true; |
| 589 | 589 | global $app_strings, $currentModule; |
| 590 | 590 | $this->local_theme = SugarThemeRegistry::current()->__toString(); |
| 591 | - $this->local_app_strings =$app_strings; |
|
| 591 | + $this->local_app_strings = $app_strings; |
|
| 592 | 592 | $this->local_image_path = SugarThemeRegistry::current()->getImagePath(); |
| 593 | 593 | $this->local_current_module = $currentModule; |
| 594 | 594 | } |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | * Contributor(s): ______________________________________. |
| 620 | 620 | */ |
| 621 | 621 | function setXTemplatePath($value) { |
| 622 | - $this->xTemplatePath= $value; |
|
| 622 | + $this->xTemplatePath = $value; |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /**this is a helper function for allowing ListView to create a new XTemplate it groups parameters that should be set into a single function |
@@ -629,22 +629,22 @@ discard block |
||
| 629 | 629 | */ |
| 630 | 630 | function initNewXTemplate($XTemplatePath, $modString, $imagePath = null) { |
| 631 | 631 | $this->setXTemplatePath($XTemplatePath); |
| 632 | - if(isset($modString)) |
|
| 632 | + if (isset($modString)) |
|
| 633 | 633 | $this->setModStrings($modString); |
| 634 | - if(isset($imagePath)) |
|
| 634 | + if (isset($imagePath)) |
|
| 635 | 635 | $this->setImagePath($imagePath); |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | |
| 639 | -function getOrderBy($varName, $defaultOrderBy='', $force_sortorder='') { |
|
| 640 | - $sortBy = $this->getSessionVariable($varName, "ORDER_BY") ; |
|
| 639 | +function getOrderBy($varName, $defaultOrderBy = '', $force_sortorder = '') { |
|
| 640 | + $sortBy = $this->getSessionVariable($varName, "ORDER_BY"); |
|
| 641 | 641 | |
| 642 | 642 | $orderByDirection = $this->getSessionVariableName($varName, "order_by_direction"); |
| 643 | 643 | $orderByColumn = $this->getSessionVariableName($varName, "ORDER_BY"); |
| 644 | 644 | $lastEqualsSortBy = false; |
| 645 | 645 | $defaultOrder = false; //ascending |
| 646 | 646 | |
| 647 | - if(empty($sortBy)) { |
|
| 647 | + if (empty($sortBy)) { |
|
| 648 | 648 | $this->setUserVariable($varName, "ORDER_BY", $defaultOrderBy); |
| 649 | 649 | $sortBy = $defaultOrderBy; |
| 650 | 650 | } else { |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | } |
| 683 | 683 | $desc = $orderByValue == 'desc'; |
| 684 | 684 | $orderByDirectionValue = false; |
| 685 | - $this->setSessionVariable($varName, $sortBy . "S", $desc); |
|
| 685 | + $this->setSessionVariable($varName, $sortBy."S", $desc); |
|
| 686 | 686 | if (!empty($sortBy)) |
| 687 | 687 | { |
| 688 | 688 | if (empty($force_sortorder)) |
@@ -693,11 +693,11 @@ discard block |
||
| 693 | 693 | { |
| 694 | 694 | $orderByDirectionValue = $desc ? 'asc' : 'desc'; |
| 695 | 695 | } |
| 696 | - $this->query_orderby = $sortBy . ' ' . $orderByValue; |
|
| 696 | + $this->query_orderby = $sortBy.' '.$orderByValue; |
|
| 697 | 697 | } |
| 698 | 698 | } else |
| 699 | 699 | { |
| 700 | - $this->query_orderby = $sortBy . ' ' . $force_sortorder; |
|
| 700 | + $this->query_orderby = $sortBy.' '.$force_sortorder; |
|
| 701 | 701 | } |
| 702 | 702 | if (!isset($this->appendToBaseUrl)) |
| 703 | 703 | { |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | } |
| 715 | 715 | //Just clear from url... |
| 716 | 716 | $this->appendToBaseUrl[$orderByColumn] = false; |
| 717 | - }else { |
|
| 717 | + } else { |
|
| 718 | 718 | $this->query_orderby = ""; |
| 719 | 719 | } |
| 720 | 720 | $this->sortby = $sortBy; |
@@ -728,15 +728,15 @@ discard block |
||
| 728 | 728 | * All Rights Reserved. |
| 729 | 729 | * Contributor(s): ______________________________________. |
| 730 | 730 | */ |
| 731 | - function setQuery($where, $limit, $orderBy, $varName, $allowOrderByOveride=true) { |
|
| 731 | + function setQuery($where, $limit, $orderBy, $varName, $allowOrderByOveride = true) { |
|
| 732 | 732 | $this->query_where = $where; |
| 733 | - if($this->getSessionVariable("query", "where") != $where) { |
|
| 733 | + if ($this->getSessionVariable("query", "where") != $where) { |
|
| 734 | 734 | $this->query_where_has_changed = true; |
| 735 | 735 | $this->setSessionVariable("query", "where", $where); |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | $this->query_limit = $limit; |
| 739 | - if(!$allowOrderByOveride) { |
|
| 739 | + if (!$allowOrderByOveride) { |
|
| 740 | 740 | $this->query_orderby = $orderBy; |
| 741 | 741 | return; |
| 742 | 742 | } |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | */ |
| 760 | 760 | function setTheme($theme) { |
| 761 | 761 | $this->local_theme = $theme; |
| 762 | - if(isset($this->xTemplate))$this->xTemplate->assign("THEME", $this->local_theme); |
|
| 762 | + if (isset($this->xTemplate))$this->xTemplate->assign("THEME", $this->local_theme); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /**sets the AppStrings used only use if it is different from the global |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | function setAppStrings($app_strings) { |
| 771 | 771 | unset($this->local_app_strings); |
| 772 | 772 | $this->local_app_strings = $app_strings; |
| 773 | - if(isset($this->xTemplate))$this->xTemplate->assign("APP", $this->local_app_strings); |
|
| 773 | + if (isset($this->xTemplate))$this->xTemplate->assign("APP", $this->local_app_strings); |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /**sets the ModStrings used |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | function setModStrings($mod_strings) { |
| 782 | 782 | unset($this->local_module_strings); |
| 783 | 783 | $this->local_mod_strings = $mod_strings; |
| 784 | - if(isset($this->xTemplate))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 784 | + if (isset($this->xTemplate))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | /**sets the ImagePath used |
@@ -791,10 +791,10 @@ discard block |
||
| 791 | 791 | */ |
| 792 | 792 | function setImagePath($image_path) { |
| 793 | 793 | $this->local_image_path = $image_path; |
| 794 | - if(empty($this->local_image_path)) { |
|
| 794 | + if (empty($this->local_image_path)) { |
|
| 795 | 795 | $this->local_image_path = SugarThemeRegistry::get($this->local_theme)->getImagePath(); |
| 796 | 796 | } |
| 797 | - if(isset($this->xTemplate))$this->xTemplate->assign("IMAGE_PATH", $this->local_image_path); |
|
| 797 | + if (isset($this->xTemplate))$this->xTemplate->assign("IMAGE_PATH", $this->local_image_path); |
|
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | /**sets the currentModule only use if this is different from the global |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | function setCurrentModule($currentModule) { |
| 806 | 806 | unset($this->local_current_module); |
| 807 | 807 | $this->local_current_module = $currentModule; |
| 808 | - if(isset($this->xTemplate))$this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
|
| 808 | + if (isset($this->xTemplate))$this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /**INTERNAL FUNCTION creates an XTemplate DO NOT CALL THIS THIS IS AN INTERNAL FUNCTION |
@@ -814,12 +814,12 @@ discard block |
||
| 814 | 814 | * Contributor(s): ______________________________________. |
| 815 | 815 | */ |
| 816 | 816 | function createXTemplate() { |
| 817 | - if(!isset($this->xTemplate)) { |
|
| 818 | - if(isset($this->xTemplatePath)) { |
|
| 817 | + if (!isset($this->xTemplate)) { |
|
| 818 | + if (isset($this->xTemplatePath)) { |
|
| 819 | 819 | |
| 820 | 820 | $this->xTemplate = new XTemplate($this->xTemplatePath); |
| 821 | 821 | $this->xTemplate->assign("APP", $this->local_app_strings); |
| 822 | - if(isset($this->local_mod_strings))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 822 | + if (isset($this->local_mod_strings))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 823 | 823 | $this->xTemplate->assign("THEME", $this->local_theme); |
| 824 | 824 | $this->xTemplate->assign("IMAGE_PATH", $this->local_image_path); |
| 825 | 825 | $this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | */ |
| 855 | 855 | function xTemplateAssign($name, $value) { |
| 856 | 856 | |
| 857 | - if(!isset($this->xTemplate)) { |
|
| 857 | + if (!isset($this->xTemplate)) { |
|
| 858 | 858 | $this->createXTemplate(); |
| 859 | 859 | } |
| 860 | 860 | $this->xTemplate->assign($name, $value); |
@@ -867,11 +867,11 @@ discard block |
||
| 867 | 867 | * Contributor(s): ______________________________________. |
| 868 | 868 | */ |
| 869 | 869 | function getOffset($localVarName) { |
| 870 | - if($this->query_where_has_changed || isset($GLOBALS['record_has_changed'])) { |
|
| 871 | - $this->setSessionVariable($localVarName,"offset", 0); |
|
| 870 | + if ($this->query_where_has_changed || isset($GLOBALS['record_has_changed'])) { |
|
| 871 | + $this->setSessionVariable($localVarName, "offset", 0); |
|
| 872 | 872 | } |
| 873 | - $offset = $this->getSessionVariable($localVarName,"offset"); |
|
| 874 | - if(isset($offset)) { |
|
| 873 | + $offset = $this->getSessionVariable($localVarName, "offset"); |
|
| 874 | + if (isset($offset)) { |
|
| 875 | 875 | return $offset; |
| 876 | 876 | } |
| 877 | 877 | return 0; |
@@ -891,12 +891,12 @@ discard block |
||
| 891 | 891 | * All Rights Reserved. |
| 892 | 892 | * Contributor(s): ______________________________________. |
| 893 | 893 | */ |
| 894 | - function setSessionVariable($localVarName,$varName, $value) { |
|
| 894 | + function setSessionVariable($localVarName, $varName, $value) { |
|
| 895 | 895 | $_SESSION[$this->local_current_module."_".$localVarName."_".$varName] = $value; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | -function setUserVariable($localVarName,$varName, $value) { |
|
| 899 | - if($this->is_dynamic || $localVarName == 'CELL')return; |
|
| 898 | +function setUserVariable($localVarName, $varName, $value) { |
|
| 899 | + if ($this->is_dynamic || $localVarName == 'CELL')return; |
|
| 900 | 900 | global $current_user; |
| 901 | 901 | $current_user->setPreference($this->local_current_module."_".$localVarName."_".$varName, $value); |
| 902 | 902 | } |
@@ -906,13 +906,13 @@ discard block |
||
| 906 | 906 | * All Rights Reserved. |
| 907 | 907 | * Contributor(s): ______________________________________. |
| 908 | 908 | */ |
| 909 | - function getSessionVariable($localVarName,$varName) { |
|
| 909 | + function getSessionVariable($localVarName, $varName) { |
|
| 910 | 910 | //Set any variables pass in through request first |
| 911 | - if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
|
| 912 | - $this->setSessionVariable($localVarName,$varName,$_REQUEST[$this->getSessionVariableName($localVarName, $varName)]); |
|
| 911 | + if (isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
|
| 912 | + $this->setSessionVariable($localVarName, $varName, $_REQUEST[$this->getSessionVariableName($localVarName, $varName)]); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | - if(isset($_SESSION[$this->getSessionVariableName($localVarName, $varName)])) { |
|
| 915 | + if (isset($_SESSION[$this->getSessionVariableName($localVarName, $varName)])) { |
|
| 916 | 916 | return $_SESSION[$this->getSessionVariableName($localVarName, $varName)]; |
| 917 | 917 | } |
| 918 | 918 | return ""; |
@@ -920,10 +920,10 @@ discard block |
||
| 920 | 920 | |
| 921 | 921 | function getUserVariable($localVarName, $varName) { |
| 922 | 922 | global $current_user; |
| 923 | - if($this->is_dynamic || $localVarName == 'CELL')return; |
|
| 924 | - if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
|
| 923 | + if ($this->is_dynamic || $localVarName == 'CELL')return; |
|
| 924 | + if (isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
|
| 925 | 925 | |
| 926 | - $this->setUserVariable($localVarName,$varName,$_REQUEST[$this->getSessionVariableName($localVarName, $varName)]); |
|
| 926 | + $this->setUserVariable($localVarName, $varName, $_REQUEST[$this->getSessionVariableName($localVarName, $varName)]); |
|
| 927 | 927 | } |
| 928 | 928 | return $current_user->getPreference($this->getSessionVariableName($localVarName, $varName)); |
| 929 | 929 | } |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | 'default', |
| 948 | 948 | ); |
| 949 | 949 | |
| 950 | - foreach($priority_map as $p) { |
|
| 950 | + foreach ($priority_map as $p) { |
|
| 951 | 951 | if (key_exists($p, $sortOrderList)) { |
| 952 | 952 | $order = strtolower($sortOrderList[$p]); |
| 953 | 953 | if (in_array($order, array('asc', 'desc'))) { |
@@ -969,7 +969,7 @@ discard block |
||
| 969 | 969 | * All Rights Reserved. |
| 970 | 970 | * Contributor(s): ______________________________________.. |
| 971 | 971 | */ |
| 972 | - function getSessionVariableName($localVarName,$varName) { |
|
| 972 | + function getSessionVariableName($localVarName, $varName) { |
|
| 973 | 973 | return $this->local_current_module."_".$localVarName."_".$varName; |
| 974 | 974 | } |
| 975 | 975 | |
@@ -997,22 +997,22 @@ discard block |
||
| 997 | 997 | SugarVCR::erase($seed->module_dir); |
| 998 | 998 | $params = array(); |
| 999 | 999 | //$filter = array('id', 'full_name'); |
| 1000 | - $filter=array(); |
|
| 1000 | + $filter = array(); |
|
| 1001 | 1001 | $ret_array = $seed->create_new_list_query($this->query_orderby, $this->query_where, $filter, $params, 0, '', true, $seed, true); |
| 1002 | - if(!is_array($params)) $params = array(); |
|
| 1003 | - if(!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
| 1004 | - if(!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
| 1005 | - if(!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
| 1006 | - if(!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
| 1007 | - $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
|
| 1008 | - SugarVCR::store($seed->module_dir, $main_query); |
|
| 1002 | + if (!is_array($params)) $params = array(); |
|
| 1003 | + if (!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
| 1004 | + if (!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
| 1005 | + if (!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
| 1006 | + if (!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
| 1007 | + $main_query = $ret_array['select'].$params['custom_select'].$ret_array['from'].$params['custom_from'].$ret_array['where'].$params['custom_where'].$ret_array['order_by'].$params['custom_order_by']; |
|
| 1008 | + SugarVCR::store($seed->module_dir, $main_query); |
|
| 1009 | 1009 | //ADDING VCR CONTROL |
| 1010 | 1010 | |
| 1011 | - if(empty($this->related_field_name)) { |
|
| 1011 | + if (empty($this->related_field_name)) { |
|
| 1012 | 1012 | $response = $seed->get_list($this->query_orderby, $this->query_where, $current_offset, $this->query_limit); |
| 1013 | 1013 | } else { |
| 1014 | 1014 | $related_field_name = $this->related_field_name; |
| 1015 | - $response = $seed->get_related_list($this->child_focus,$related_field_name, $this->query_orderby, |
|
| 1015 | + $response = $seed->get_related_list($this->child_focus, $related_field_name, $this->query_orderby, |
|
| 1016 | 1016 | $this->query_where, $current_offset, $this->query_limit); |
| 1017 | 1017 | } |
| 1018 | 1018 | |
@@ -1021,12 +1021,12 @@ discard block |
||
| 1021 | 1021 | $next_offset = $response['next_offset']; |
| 1022 | 1022 | $previous_offset = $response['previous_offset']; |
| 1023 | 1023 | |
| 1024 | - if(!empty($response['current_offset'])) { |
|
| 1024 | + if (!empty($response['current_offset'])) { |
|
| 1025 | 1025 | $current_offset = $response['current_offset']; |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | $list_view_row_count = $row_count; |
| 1029 | - $this->processListNavigation($xtemplateSection,$html_varName, $current_offset, $next_offset, $previous_offset, $row_count, null, null, empty($seed->column_fields) ? null : count($seed->column_fields)); |
|
| 1029 | + $this->processListNavigation($xtemplateSection, $html_varName, $current_offset, $next_offset, $previous_offset, $row_count, null, null, empty($seed->column_fields) ? null : count($seed->column_fields)); |
|
| 1030 | 1030 | |
| 1031 | 1031 | return $list; |
| 1032 | 1032 | } |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | function processUnionBeans($sugarbean, $subpanel_def, $html_var = 'CELL') { |
| 1037 | 1037 | |
| 1038 | 1038 | $last_detailview_record = $this->getSessionVariable("detailview", "record"); |
| 1039 | - if(!empty($last_detailview_record) && $last_detailview_record != $sugarbean->id){ |
|
| 1039 | + if (!empty($last_detailview_record) && $last_detailview_record != $sugarbean->id) { |
|
| 1040 | 1040 | $GLOBALS['record_has_changed'] = true; |
| 1041 | 1041 | } |
| 1042 | 1042 | $this->setSessionVariable("detailview", "record", $sugarbean->id); |
@@ -1053,14 +1053,14 @@ discard block |
||
| 1053 | 1053 | $sort_order['request'] = isset($_REQUEST['sort_order']) ? $_REQUEST['sort_order'] : null; |
| 1054 | 1054 | |
| 1055 | 1055 | // see if the session data has a sort order |
| 1056 | - if (isset($_SESSION['last_sub' . $this->subpanel_module . '_order'])) |
|
| 1056 | + if (isset($_SESSION['last_sub'.$this->subpanel_module.'_order'])) |
|
| 1057 | 1057 | { |
| 1058 | - $sort_order['session'] = $_SESSION['last_sub' . $this->subpanel_module . '_order']; |
|
| 1058 | + $sort_order['session'] = $_SESSION['last_sub'.$this->subpanel_module.'_order']; |
|
| 1059 | 1059 | |
| 1060 | 1060 | // We swap the order when the request contains an offset (indicating a column sort issued); |
| 1061 | 1061 | // otherwise we do not sort. If we don't make this check, then the subpanel listview will |
| 1062 | 1062 | // swap ordering each time a new record is entered via quick create forms |
| 1063 | - if (isset($_REQUEST[$module . '_' . $html_var . '_offset'])) |
|
| 1063 | + if (isset($_REQUEST[$module.'_'.$html_var.'_offset'])) |
|
| 1064 | 1064 | { |
| 1065 | 1065 | $sort_order['session'] = $sort_order['session'] == 'asc' ? 'desc' : 'asc'; |
| 1066 | 1066 | } |
@@ -1083,10 +1083,10 @@ discard block |
||
| 1083 | 1083 | $this->query_orderby = 'id'; |
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | - $this->getOrderBy($html_var,$this->query_orderby, $this->sort_order); |
|
| 1086 | + $this->getOrderBy($html_var, $this->query_orderby, $this->sort_order); |
|
| 1087 | 1087 | |
| 1088 | - $_SESSION['last_sub' .$this->subpanel_module. '_order'] = $this->sort_order; |
|
| 1089 | - $_SESSION['last_sub' .$this->subpanel_module. '_url'] = $this->getBaseURL($html_var); |
|
| 1088 | + $_SESSION['last_sub'.$this->subpanel_module.'_order'] = $this->sort_order; |
|
| 1089 | + $_SESSION['last_sub'.$this->subpanel_module.'_url'] = $this->getBaseURL($html_var); |
|
| 1090 | 1090 | |
| 1091 | 1091 | // Bug 8139 - Correct Subpanel sorting on 'name', when subpanel sorting default is 'last_name, first_name' |
| 1092 | 1092 | if (($this->sortby == 'name' || $this->sortby == 'last_name') && |
@@ -1094,21 +1094,21 @@ discard block |
||
| 1094 | 1094 | $this->sortby = 'last_name '.$this->sort_order.', first_name '; |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | - if(!empty($this->response)){ |
|
| 1098 | - $response =& $this->response; |
|
| 1097 | + if (!empty($this->response)) { |
|
| 1098 | + $response = & $this->response; |
|
| 1099 | 1099 | echo 'cached'; |
| 1100 | - }else{ |
|
| 1101 | - $response = SugarBean::get_union_related_list($sugarbean,$this->sortby, $this->sort_order, $this->query_where, $current_offset, -1, $this->records_per_page,$this->query_limit,$subpanel_def); |
|
| 1102 | - $this->response =& $response; |
|
| 1100 | + } else { |
|
| 1101 | + $response = SugarBean::get_union_related_list($sugarbean, $this->sortby, $this->sort_order, $this->query_where, $current_offset, -1, $this->records_per_page, $this->query_limit, $subpanel_def); |
|
| 1102 | + $this->response = & $response; |
|
| 1103 | 1103 | } |
| 1104 | 1104 | $list = $response['list']; |
| 1105 | 1105 | $row_count = $response['row_count']; |
| 1106 | 1106 | $next_offset = $response['next_offset']; |
| 1107 | 1107 | $previous_offset = $response['previous_offset']; |
| 1108 | - if(!empty($response['current_offset']))$current_offset = $response['current_offset']; |
|
| 1108 | + if (!empty($response['current_offset']))$current_offset = $response['current_offset']; |
|
| 1109 | 1109 | global $list_view_row_count; |
| 1110 | 1110 | $list_view_row_count = $row_count; |
| 1111 | - $this->processListNavigation('dyn_list_view', $html_var, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean,$subpanel_def); |
|
| 1111 | + $this->processListNavigation('dyn_list_view', $html_var, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean, $subpanel_def); |
|
| 1112 | 1112 | |
| 1113 | 1113 | return array('list'=>$list, 'parent_data'=>$response['parent_data'], 'query'=>$response['query']); |
| 1114 | 1114 | } |
@@ -1116,34 +1116,34 @@ discard block |
||
| 1116 | 1116 | function getBaseURL($html_varName) { |
| 1117 | 1117 | static $cache = array(); |
| 1118 | 1118 | |
| 1119 | - if(!empty($cache[$html_varName]))return $cache[$html_varName]; |
|
| 1120 | - $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount','current_query_by_page'); |
|
| 1121 | - if(!empty($this->base_URL)) { |
|
| 1119 | + if (!empty($cache[$html_varName]))return $cache[$html_varName]; |
|
| 1120 | + $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'current_query_by_page'); |
|
| 1121 | + if (!empty($this->base_URL)) { |
|
| 1122 | 1122 | return $this->base_URL; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | $baseurl = $_SERVER['PHP_SELF']; |
| 1126 | - if(empty($baseurl)) { |
|
| 1126 | + if (empty($baseurl)) { |
|
| 1127 | 1127 | $baseurl = 'index.php'; |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | /*fixes an issue with deletes when doing a search*/ |
| 1131 | - foreach(array_merge($_GET, $_POST) as $name=>$value) { |
|
| 1131 | + foreach (array_merge($_GET, $_POST) as $name=>$value) { |
|
| 1132 | 1132 | //echo ("$name = $value <br/>"); |
| 1133 | - if(!empty($value) && $name != 'sort_order' //&& $name != ListView::getSessionVariableName($html_varName,"ORDER_BY") |
|
| 1134 | - && $name != ListView::getSessionVariableName($html_varName,"offset") |
|
| 1133 | + if (!empty($value) && $name != 'sort_order' //&& $name != ListView::getSessionVariableName($html_varName,"ORDER_BY") |
|
| 1134 | + && $name != ListView::getSessionVariableName($html_varName, "offset") |
|
| 1135 | 1135 | /*&& substr_count($name, "ORDER_BY")==0*/ && !in_array($name, $blockVariables)) |
| 1136 | 1136 | { |
| 1137 | - if(is_array($value)) { |
|
| 1138 | - foreach($value as $valuename=>$valuevalue) { |
|
| 1139 | - if(substr_count($baseurl, '?') > 0) |
|
| 1137 | + if (is_array($value)) { |
|
| 1138 | + foreach ($value as $valuename=>$valuevalue) { |
|
| 1139 | + if (substr_count($baseurl, '?') > 0) |
|
| 1140 | 1140 | $baseurl .= "&{$name}[]=".$valuevalue; |
| 1141 | 1141 | else |
| 1142 | 1142 | $baseurl .= "?{$name}[]=".$valuevalue; |
| 1143 | 1143 | } |
| 1144 | 1144 | } else { |
| 1145 | 1145 | $value = urlencode($value); |
| 1146 | - if(substr_count($baseurl, '?') > 0) { |
|
| 1146 | + if (substr_count($baseurl, '?') > 0) { |
|
| 1147 | 1147 | $baseurl .= "&$name=$value"; |
| 1148 | 1148 | } else { |
| 1149 | 1149 | $baseurl .= "?$name=$value"; |
@@ -1153,17 +1153,17 @@ discard block |
||
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | |
| 1156 | - if($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1156 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1157 | 1157 | // at this point it is possible that the above foreach already executed resulting in double ?'s in the url |
| 1158 | - if(substr_count($baseurl, '?') == 0) { |
|
| 1158 | + if (substr_count($baseurl, '?') == 0) { |
|
| 1159 | 1159 | $baseurl .= '?'; |
| 1160 | 1160 | } |
| 1161 | - if(isset($_REQUEST['action'])) $baseurl.= '&action='.$_REQUEST['action']; |
|
| 1162 | - if(isset($_REQUEST['record'])) $baseurl .= '&record='.$_REQUEST['record']; |
|
| 1163 | - if(isset($_REQUEST['module'])) $baseurl .= '&module='.$_REQUEST['module']; |
|
| 1161 | + if (isset($_REQUEST['action'])) $baseurl .= '&action='.$_REQUEST['action']; |
|
| 1162 | + if (isset($_REQUEST['record'])) $baseurl .= '&record='.$_REQUEST['record']; |
|
| 1163 | + if (isset($_REQUEST['module'])) $baseurl .= '&module='.$_REQUEST['module']; |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | - $baseurl .= "&".ListView::getSessionVariableName($html_varName,"offset")."="; |
|
| 1166 | + $baseurl .= "&".ListView::getSessionVariableName($html_varName, "offset")."="; |
|
| 1167 | 1167 | $cache[$html_varName] = $baseurl; |
| 1168 | 1168 | return $baseurl; |
| 1169 | 1169 | } |
@@ -1177,7 +1177,7 @@ discard block |
||
| 1177 | 1177 | * All Rights Reserved. |
| 1178 | 1178 | * Contributor(s): ______________________________________.. |
| 1179 | 1179 | */ |
| 1180 | - function processListNavigation($xtemplateSection, $html_varName, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean=null, $subpanel_def=null, $col_count = 20) { |
|
| 1180 | + function processListNavigation($xtemplateSection, $html_varName, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean = null, $subpanel_def = null, $col_count = 20) { |
|
| 1181 | 1181 | |
| 1182 | 1182 | global $export_module; |
| 1183 | 1183 | global $sugar_config; |
@@ -1187,40 +1187,40 @@ discard block |
||
| 1187 | 1187 | |
| 1188 | 1188 | $start_record = $current_offset + 1; |
| 1189 | 1189 | |
| 1190 | - if(!is_numeric($col_count)) |
|
| 1190 | + if (!is_numeric($col_count)) |
|
| 1191 | 1191 | $col_count = 20; |
| 1192 | 1192 | |
| 1193 | - if($row_count == 0) |
|
| 1193 | + if ($row_count == 0) |
|
| 1194 | 1194 | $start_record = 0; |
| 1195 | 1195 | |
| 1196 | 1196 | $end_record = $start_record + $this->records_per_page; |
| 1197 | 1197 | // back up the the last page. |
| 1198 | - if($end_record > $row_count+1) { |
|
| 1199 | - $end_record = $row_count+1; |
|
| 1198 | + if ($end_record > $row_count + 1) { |
|
| 1199 | + $end_record = $row_count + 1; |
|
| 1200 | 1200 | } |
| 1201 | 1201 | // Determine the start location of the last page |
| 1202 | - if($row_count == 0) |
|
| 1202 | + if ($row_count == 0) |
|
| 1203 | 1203 | $number_pages = 0; |
| 1204 | 1204 | else |
| 1205 | 1205 | $number_pages = floor(($row_count - 1) / $this->records_per_page); |
| 1206 | 1206 | |
| 1207 | 1207 | $last_offset = $number_pages * $this->records_per_page; |
| 1208 | 1208 | |
| 1209 | - if(empty($this->query_limit) || $this->query_limit > $this->records_per_page) { |
|
| 1209 | + if (empty($this->query_limit) || $this->query_limit > $this->records_per_page) { |
|
| 1210 | 1210 | $this->base_URL = $this->getBaseURL($html_varName); |
| 1211 | 1211 | $dynamic_url = ''; |
| 1212 | 1212 | |
| 1213 | - if($this->is_dynamic) { |
|
| 1214 | - $dynamic_url .='&'. $this->getSessionVariableName($html_varName,'ORDER_BY') . '='. $this->getSessionVariable($html_varName,'ORDER_BY').'&sort_order='.$this->sort_order.'&to_pdf=true&action=SubPanelViewer&subpanel=' . $this->subpanel_module; |
|
| 1213 | + if ($this->is_dynamic) { |
|
| 1214 | + $dynamic_url .= '&'.$this->getSessionVariableName($html_varName, 'ORDER_BY').'='.$this->getSessionVariable($html_varName, 'ORDER_BY').'&sort_order='.$this->sort_order.'&to_pdf=true&action=SubPanelViewer&subpanel='.$this->subpanel_module; |
|
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | $current_URL = htmlentities($this->base_URL.$current_offset.$dynamic_url); |
| 1218 | 1218 | $start_URL = htmlentities($this->base_URL."0".$dynamic_url); |
| 1219 | - $previous_URL = htmlentities($this->base_URL.$previous_offset.$dynamic_url); |
|
| 1219 | + $previous_URL = htmlentities($this->base_URL.$previous_offset.$dynamic_url); |
|
| 1220 | 1220 | $next_URL = htmlentities($this->base_URL.$next_offset.$dynamic_url); |
| 1221 | - $end_URL = htmlentities($this->base_URL.'end'.$dynamic_url); |
|
| 1221 | + $end_URL = htmlentities($this->base_URL.'end'.$dynamic_url); |
|
| 1222 | 1222 | |
| 1223 | - if(!empty($this->start_link_wrapper)) { |
|
| 1223 | + if (!empty($this->start_link_wrapper)) { |
|
| 1224 | 1224 | $current_URL = $this->start_link_wrapper.$current_URL.$this->end_link_wrapper; |
| 1225 | 1225 | $start_URL = $this->start_link_wrapper.$start_URL.$this->end_link_wrapper; |
| 1226 | 1226 | $previous_URL = $this->start_link_wrapper.$previous_URL.$this->end_link_wrapper; |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | |
| 1231 | 1231 | $moduleString = htmlspecialchars("{$currentModule}_{$html_varName}_offset"); |
| 1232 | 1232 | $moduleStringOrder = htmlspecialchars("{$currentModule}_{$html_varName}_ORDER_BY"); |
| 1233 | - if($this->shouldProcess && !$this->multi_select_popup) { |
|
| 1233 | + if ($this->shouldProcess && !$this->multi_select_popup) { |
|
| 1234 | 1234 | // check the checkboxes onload |
| 1235 | 1235 | echo "<script>YAHOO.util.Event.addListener(window, \"load\", sListView.check_boxes);</script>\n"; |
| 1236 | 1236 | |
@@ -1238,7 +1238,7 @@ discard block |
||
| 1238 | 1238 | $uids = empty($_REQUEST['uid']) || $massUpdateRun ? '' : $_REQUEST['uid']; |
| 1239 | 1239 | $select_entire_list = ($massUpdateRun) ? 0 : (isset($_POST['select_entire_list']) ? $_POST['select_entire_list'] : (isset($_REQUEST['select_entire_list']) ? htmlspecialchars($_REQUEST['select_entire_list']) : 0)); |
| 1240 | 1240 | |
| 1241 | - echo "<textarea style='display: none' name='uid'>{$uids}</textarea>\n" . |
|
| 1241 | + echo "<textarea style='display: none' name='uid'>{$uids}</textarea>\n". |
|
| 1242 | 1242 | "<input type='hidden' name='select_entire_list' value='{$select_entire_list}'>\n". |
| 1243 | 1243 | "<input type='hidden' name='{$moduleString}' value='0'>\n". |
| 1244 | 1244 | "<input type='hidden' name='{$moduleStringOrder}' value='0'>\n"; |
@@ -1248,64 +1248,64 @@ discard block |
||
| 1248 | 1248 | |
| 1249 | 1249 | $GLOBALS['log']->debug("Offsets: (start, previous, next, last)(0, $previous_offset, $next_offset, $last_offset)"); |
| 1250 | 1250 | |
| 1251 | - if(0 == $current_offset) { |
|
| 1252 | - $start_link = "<button type='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("start_off","aborder='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1253 | - $previous_link = "<button type='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("previous_off","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1251 | + if (0 == $current_offset) { |
|
| 1252 | + $start_link = "<button type='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("start_off", "aborder='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1253 | + $previous_link = "<button type='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("previous_off", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1254 | 1254 | } else { |
| 1255 | - if($this->multi_select_popup) {// nav links for multiselect popup, submit form to save checks. |
|
| 1256 | - $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick='javascript:save_checks(0, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1257 | - $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick='javascript:save_checks($previous_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1258 | - } elseif($this->shouldProcess) { |
|
| 1259 | - $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick='location.href=\"$start_URL\"; sListView.save_checks(0, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1260 | - $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick='location.href=\"$previous_URL\"; sListView.save_checks($previous_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1255 | + if ($this->multi_select_popup) {// nav links for multiselect popup, submit form to save checks. |
|
| 1256 | + $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick='javascript:save_checks(0, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("start", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1257 | + $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick='javascript:save_checks($previous_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("previous", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1258 | + } elseif ($this->shouldProcess) { |
|
| 1259 | + $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick='location.href=\"$start_URL\"; sListView.save_checks(0, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("start", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1260 | + $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick='location.href=\"$previous_URL\"; sListView.save_checks($previous_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("previous", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1261 | 1261 | } else { |
| 1262 | 1262 | $onClick = ''; |
| 1263 | - if(0 != preg_match('/javascript.*/', $start_URL)){ |
|
| 1263 | + if (0 != preg_match('/javascript.*/', $start_URL)) { |
|
| 1264 | 1264 | $onClick = "\"$start_URL;\""; |
| 1265 | - }else{ |
|
| 1266 | - $onClick ="'location.href=\"$start_URL\";'"; |
|
| 1265 | + } else { |
|
| 1266 | + $onClick = "'location.href=\"$start_URL\";'"; |
|
| 1267 | 1267 | } |
| 1268 | - $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1268 | + $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("start", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_START'])."</button>"; |
|
| 1269 | 1269 | |
| 1270 | 1270 | $onClick = ''; |
| 1271 | - if(0 != preg_match('/javascript.*/', $previous_URL)){ |
|
| 1271 | + if (0 != preg_match('/javascript.*/', $previous_URL)) { |
|
| 1272 | 1272 | $onClick = "\"$previous_URL;\""; |
| 1273 | - }else{ |
|
| 1273 | + } else { |
|
| 1274 | 1274 | $onClick = "'location.href=\"$previous_URL\";'"; |
| 1275 | 1275 | } |
| 1276 | - $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1276 | + $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("previous", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
|
| 1277 | 1277 | } |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | - if($last_offset <= $current_offset) { |
|
| 1281 | - $end_link = "<button type='button' name='listViewEndButton' title='{$this->local_app_strings['LNK_LIST_END']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("end_off","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1282 | - $next_link = "<button type='button' name='listViewNextButton' title='{$this->local_app_strings['LNK_LIST_NEXT']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("next_off","aborder='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1280 | + if ($last_offset <= $current_offset) { |
|
| 1281 | + $end_link = "<button type='button' name='listViewEndButton' title='{$this->local_app_strings['LNK_LIST_END']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("end_off", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1282 | + $next_link = "<button type='button' name='listViewNextButton' title='{$this->local_app_strings['LNK_LIST_NEXT']}' class='button' disabled>".SugarThemeRegistry::current()->getImage("next_off", "aborder='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1283 | 1283 | } else { |
| 1284 | - if($this->multi_select_popup) { // nav links for multiselect popup, submit form to save checks. |
|
| 1285 | - $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick='javascript:save_checks($last_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1286 | - if(!empty($sugar_config['disable_count_query'])) { |
|
| 1284 | + if ($this->multi_select_popup) { // nav links for multiselect popup, submit form to save checks. |
|
| 1285 | + $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick='javascript:save_checks($last_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("end", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1286 | + if (!empty($sugar_config['disable_count_query'])) { |
|
| 1287 | 1287 | $end_link = ''; |
| 1288 | 1288 | } |
| 1289 | - $next_link = "<button type='button' name='listViewNextButton' title='{$this->local_app_strings['LNK_LIST_NEXT']}' class='button' onClick='javascript:save_checks($next_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1290 | - } elseif($this->shouldProcess) { |
|
| 1291 | - $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick='location.href=\"$end_URL\"; sListView.save_checks(\"end\", \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1292 | - $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick='location.href=\"$next_URL\"; sListView.save_checks($next_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1289 | + $next_link = "<button type='button' name='listViewNextButton' title='{$this->local_app_strings['LNK_LIST_NEXT']}' class='button' onClick='javascript:save_checks($next_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("next", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1290 | + } elseif ($this->shouldProcess) { |
|
| 1291 | + $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick='location.href=\"$end_URL\"; sListView.save_checks(\"end\", \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("end", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1292 | + $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick='location.href=\"$next_URL\"; sListView.save_checks($next_offset, \"{$moduleString}\");'>".SugarThemeRegistry::current()->getImage("next", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1293 | 1293 | } else { |
| 1294 | 1294 | $onClick = ''; |
| 1295 | - if(0 != preg_match('/javascript.*/', $next_URL)){ |
|
| 1295 | + if (0 != preg_match('/javascript.*/', $next_URL)) { |
|
| 1296 | 1296 | $onClick = "\"$next_URL;\""; |
| 1297 | - }else{ |
|
| 1298 | - $onClick ="'location.href=\"$next_URL\";'"; |
|
| 1297 | + } else { |
|
| 1298 | + $onClick = "'location.href=\"$next_URL\";'"; |
|
| 1299 | 1299 | } |
| 1300 | - $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1300 | + $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("next", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
|
| 1301 | 1301 | |
| 1302 | 1302 | $onClick = ''; |
| 1303 | - if(0 != preg_match('/javascript.*/', $end_URL)){ |
|
| 1303 | + if (0 != preg_match('/javascript.*/', $end_URL)) { |
|
| 1304 | 1304 | $onClick = "\"$end_URL;\""; |
| 1305 | - }else{ |
|
| 1305 | + } else { |
|
| 1306 | 1306 | $onClick = "'location.href=\"$end_URL\";'"; |
| 1307 | 1307 | } |
| 1308 | - $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1308 | + $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("end", "border='0' align='absmiddle'", null, null, '.gif', $this->local_app_strings['LNK_LIST_END'])."</button>"; |
|
| 1309 | 1309 | |
| 1310 | 1310 | } |
| 1311 | 1311 | } |
@@ -1313,7 +1313,7 @@ discard block |
||
| 1313 | 1313 | $GLOBALS['log']->info("Offset (next, current, prev)($next_offset, $current_offset, $previous_offset)"); |
| 1314 | 1314 | $GLOBALS['log']->info("Start/end records ($start_record, $end_record)"); |
| 1315 | 1315 | |
| 1316 | - $end_record = $end_record-1; |
|
| 1316 | + $end_record = $end_record - 1; |
|
| 1317 | 1317 | |
| 1318 | 1318 | $script_href = "<a style=\'width: 150px\' name=\"thispage\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'if (document.MassUpdate.select_entire_list.value==1){document.MassUpdate.select_entire_list.value=0;sListView.check_all(document.MassUpdate, \"mass[]\", true, $this->records_per_page)}else {sListView.check_all(document.MassUpdate, \"mass[]\", true)};\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_CURRENT']} ({$this->records_per_page})‎</a>" |
| 1319 | 1319 | . "<a style=\'width: 150px\' name=\"selectall\" class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'sListView.check_entire_list(document.MassUpdate, \"mass[]\",true,{$row_count});\' href=\'#\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']} ({$row_count})‎</a>" |
@@ -1336,14 +1336,14 @@ discard block |
||
| 1336 | 1336 | } |
| 1337 | 1337 | </script>"; |
| 1338 | 1338 | |
| 1339 | - if($this->show_select_menu) |
|
| 1339 | + if ($this->show_select_menu) |
|
| 1340 | 1340 | { |
| 1341 | 1341 | $total_label = ""; |
| 1342 | 1342 | $total = $row_count; |
| 1343 | 1343 | $pageTotal = ($row_count > 0) ? $end_record - $start_record + 1 : 0; |
| 1344 | 1344 | if (!empty($GLOBALS['sugar_config']['disable_count_query']) && $GLOBALS['sugar_config']['disable_count_query'] === true && $total > $pageTotal) { |
| 1345 | 1345 | $this->show_plus = true; |
| 1346 | - $total = $pageTotal; |
|
| 1346 | + $total = $pageTotal; |
|
| 1347 | 1347 | $total_label = $total.'+'; |
| 1348 | 1348 | } else { |
| 1349 | 1349 | $this->show_plus = false; |
@@ -1365,16 +1365,16 @@ discard block |
||
| 1365 | 1365 | 'id' => 'selectLink', |
| 1366 | 1366 | 'buttons' => $menuItems, |
| 1367 | 1367 | 'flat' => false, |
| 1368 | - ),$this->xTemplate); |
|
| 1368 | + ), $this->xTemplate); |
|
| 1369 | 1369 | |
| 1370 | 1370 | } else { |
| 1371 | 1371 | $select_link = " "; |
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | - $export_link = '<input class="button" type="button" value="'.$this->local_app_strings['LBL_EXPORT'].'" ' . |
|
| 1374 | + $export_link = '<input class="button" type="button" value="'.$this->local_app_strings['LBL_EXPORT'].'" '. |
|
| 1375 | 1375 | 'onclick="return sListView.send_form(true, \''.$_REQUEST['module'].'\', \'index.php?entryPoint=export\',\''.$this->local_app_strings['LBL_LISTVIEW_NO_SELECTED'].'\')">'; |
| 1376 | 1376 | |
| 1377 | - if($this->show_delete_button) { |
|
| 1377 | + if ($this->show_delete_button) { |
|
| 1378 | 1378 | $delete_link = '<input class="button" type="button" id="delete_button" name="Delete" value="'.$this->local_app_strings['LBL_DELETE_BUTTON_LABEL'].'" onclick="return sListView.send_mass_update(\'selected\',\''.$this->local_app_strings['LBL_LISTVIEW_NO_SELECTED'].'\', 1)">'; |
| 1379 | 1379 | } else { |
| 1380 | 1380 | $delete_link = ' '; |
@@ -1384,7 +1384,7 @@ discard block |
||
| 1384 | 1384 | $admin->retrieveSettings('system'); |
| 1385 | 1385 | |
| 1386 | 1386 | $user_merge = $current_user->getPreference('mailmerge_on'); |
| 1387 | - if($user_merge == 'on' && isset($admin->settings['system_mailmerge_on']) && $admin->settings['system_mailmerge_on']) { |
|
| 1387 | + if ($user_merge == 'on' && isset($admin->settings['system_mailmerge_on']) && $admin->settings['system_mailmerge_on']) { |
|
| 1388 | 1388 | echo "<script> |
| 1389 | 1389 | function mailmerge_dialog(el) { |
| 1390 | 1390 | var \$dialog = \$('<div></div>') |
@@ -1393,7 +1393,7 @@ discard block |
||
| 1393 | 1393 | . "<a style=\'width: 150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' href=\'index.php?action=index&module=MailMerge&entire=true\'>{$this->local_app_strings['LBL_LISTVIEW_OPTION_ENTIRE']}</a>') |
| 1394 | 1394 | .dialog({ |
| 1395 | 1395 | autoOpen: false, |
| 1396 | - title: '". $this->local_app_strings['LBL_MAILMERGE']."', |
|
| 1396 | + title: '".$this->local_app_strings['LBL_MAILMERGE']."', |
|
| 1397 | 1397 | width: 150, |
| 1398 | 1398 | position: { |
| 1399 | 1399 | my: myPos, |
@@ -1409,16 +1409,16 @@ discard block |
||
| 1409 | 1409 | $merge_link = " "; |
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | - $selected_objects_span = " | {$this->local_app_strings['LBL_LISTVIEW_SELECTED_OBJECTS']}<input style='border: 0px; background: transparent; font-size: inherit; color: inherit' type='text' readonly name='selectCount[]' value='" . ((isset($_POST['mass'])) ? count($_POST['mass']): 0) . "' />"; |
|
| 1412 | + $selected_objects_span = " | {$this->local_app_strings['LBL_LISTVIEW_SELECTED_OBJECTS']}<input style='border: 0px; background: transparent; font-size: inherit; color: inherit' type='text' readonly name='selectCount[]' value='".((isset($_POST['mass'])) ? count($_POST['mass']) : 0)."' />"; |
|
| 1413 | 1413 | |
| 1414 | - if($_REQUEST['module'] == 'Home' || $this->local_current_module == 'Import' |
|
| 1414 | + if ($_REQUEST['module'] == 'Home' || $this->local_current_module == 'Import' |
|
| 1415 | 1415 | || $this->show_export_button == false |
| 1416 | 1416 | || (!empty($sugar_config['disable_export'])) |
| 1417 | 1417 | || (!empty($sugar_config['admin_export_only']) |
| 1418 | 1418 | && !( |
| 1419 | 1419 | is_admin($current_user) |
| 1420 | 1420 | || (ACLController::moduleSupportsACL($_REQUEST['module']) |
| 1421 | - && ACLAction::getUserAccessLevel($current_user->id,$_REQUEST['module'], 'access') == ACL_ALLOW_ENABLED |
|
| 1421 | + && ACLAction::getUserAccessLevel($current_user->id, $_REQUEST['module'], 'access') == ACL_ALLOW_ENABLED |
|
| 1422 | 1422 | && (ACLAction::getUserAccessLevel($current_user->id, $_REQUEST['module'], 'admin') == ACL_ALLOW_ADMIN || |
| 1423 | 1423 | ACLAction::getUserAccessLevel($current_user->id, $_REQUEST['module'], 'admin') == ACL_ALLOW_ADMIN_DEV))))) |
| 1424 | 1424 | { |
@@ -1427,13 +1427,13 @@ discard block |
||
| 1427 | 1427 | } |
| 1428 | 1428 | $export_link = " "; |
| 1429 | 1429 | $merge_link = " "; |
| 1430 | - } elseif($_REQUEST['module'] != "Accounts" && $_REQUEST['module'] != "Cases" && $_REQUEST['module'] != "Contacts" && $_REQUEST['module'] != "Leads" && $_REQUEST['module'] != "Opportunities") { |
|
| 1430 | + } elseif ($_REQUEST['module'] != "Accounts" && $_REQUEST['module'] != "Cases" && $_REQUEST['module'] != "Contacts" && $_REQUEST['module'] != "Leads" && $_REQUEST['module'] != "Opportunities") { |
|
| 1431 | 1431 | $merge_link = " "; |
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | - if($this->show_paging == true) { |
|
| 1435 | - if(!empty($sugar_config['disable_count_query'])) { |
|
| 1436 | - if($row_count > $end_record) { |
|
| 1434 | + if ($this->show_paging == true) { |
|
| 1435 | + if (!empty($sugar_config['disable_count_query'])) { |
|
| 1436 | + if ($row_count > $end_record) { |
|
| 1437 | 1437 | $row_count .= '+'; |
| 1438 | 1438 | } |
| 1439 | 1439 | } |
@@ -1449,16 +1449,16 @@ discard block |
||
| 1449 | 1449 | $html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\" >"; |
| 1450 | 1450 | |
| 1451 | 1451 | //attempt to get the query to recreate this subpanel |
| 1452 | - if(!empty($this->response)){ |
|
| 1453 | - $response =& $this->response; |
|
| 1454 | - }else{ |
|
| 1455 | - $response = SugarBean::get_union_related_list($sugarbean,$this->sortby, $this->sort_order, $this->query_where, $current_offset, -1, $this->records_per_page,$this->query_limit,$subpanel_def); |
|
| 1452 | + if (!empty($this->response)) { |
|
| 1453 | + $response = & $this->response; |
|
| 1454 | + } else { |
|
| 1455 | + $response = SugarBean::get_union_related_list($sugarbean, $this->sortby, $this->sort_order, $this->query_where, $current_offset, -1, $this->records_per_page, $this->query_limit, $subpanel_def); |
|
| 1456 | 1456 | $this->response = $response; |
| 1457 | 1457 | } |
| 1458 | 1458 | //if query is present, then pass it in as parameter |
| 1459 | - if (isset($response['query']) && !empty($response['query'])){ |
|
| 1459 | + if (isset($response['query']) && !empty($response['query'])) { |
|
| 1460 | 1460 | $html_text .= $subpanelTiles->get_buttons($subpanel_def, $response['query']); |
| 1461 | - }else{ |
|
| 1461 | + } else { |
|
| 1462 | 1462 | $html_text .= $subpanelTiles->get_buttons($subpanel_def); |
| 1463 | 1463 | } |
| 1464 | 1464 | } |
@@ -1468,11 +1468,11 @@ discard block |
||
| 1468 | 1468 | $html_text .= "</td>\n<td nowrap align=\"right\">".$start_link." ".$previous_link." <span class='pageNumbers'>(".$start_record." - ".$end_record." ".$this->local_app_strings['LBL_LIST_OF']." ".$row_count.")</span> ".$next_link." ".$end_link."</td></tr></table>\n"; |
| 1469 | 1469 | $html_text .= "</td>\n"; |
| 1470 | 1470 | $html_text .= "</tr>\n"; |
| 1471 | - $this->xTemplate->assign("PAGINATION",$html_text); |
|
| 1471 | + $this->xTemplate->assign("PAGINATION", $html_text); |
|
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | //C.L. - Fix for 23461 |
| 1475 | - if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 1475 | + if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 1476 | 1476 | $_SESSION['export_where'] = $this->query_where; |
| 1477 | 1477 | } |
| 1478 | 1478 | $this->xTemplate->parse($xtemplateSection.".list_nav_row"); |
@@ -1481,24 +1481,24 @@ discard block |
||
| 1481 | 1481 | |
| 1482 | 1482 | function processOrderBy($html_varName) { |
| 1483 | 1483 | |
| 1484 | - if(!isset($this->base_URL)) { |
|
| 1484 | + if (!isset($this->base_URL)) { |
|
| 1485 | 1485 | $this->base_URL = $_SERVER['PHP_SELF']; |
| 1486 | 1486 | |
| 1487 | - if(isset($_SERVER['QUERY_STRING'])) { |
|
| 1488 | - $this->base_URL = preg_replace("/\&".$this->getSessionVariableName($html_varName,"ORDER_BY")."=[0-9a-zA-Z\_\.]*/","",$this->base_URL .'?'.$_SERVER['QUERY_STRING']); |
|
| 1489 | - $this->base_URL = preg_replace("/\&".$this->getSessionVariableName($html_varName,"offset")."=[0-9]*/","",$this->base_URL); |
|
| 1487 | + if (isset($_SERVER['QUERY_STRING'])) { |
|
| 1488 | + $this->base_URL = preg_replace("/\&".$this->getSessionVariableName($html_varName, "ORDER_BY")."=[0-9a-zA-Z\_\.]*/", "", $this->base_URL.'?'.$_SERVER['QUERY_STRING']); |
|
| 1489 | + $this->base_URL = preg_replace("/\&".$this->getSessionVariableName($html_varName, "offset")."=[0-9]*/", "", $this->base_URL); |
|
| 1490 | 1490 | } |
| 1491 | - if($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1491 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 1492 | 1492 | $this->base_URL .= '?'; |
| 1493 | - if(isset($_REQUEST['action'])) $this->base_URL .= '&action='.$_REQUEST['action']; |
|
| 1494 | - if(isset($_REQUEST['record'])) $this->base_URL .= '&record='.$_REQUEST['record']; |
|
| 1495 | - if(isset($_REQUEST['module'])) $this->base_URL .= '&module='.$_REQUEST['module']; |
|
| 1493 | + if (isset($_REQUEST['action'])) $this->base_URL .= '&action='.$_REQUEST['action']; |
|
| 1494 | + if (isset($_REQUEST['record'])) $this->base_URL .= '&record='.$_REQUEST['record']; |
|
| 1495 | + if (isset($_REQUEST['module'])) $this->base_URL .= '&module='.$_REQUEST['module']; |
|
| 1496 | 1496 | } |
| 1497 | - $this->base_URL .= "&".$this->getSessionVariableName($html_varName,"offset")."="; |
|
| 1497 | + $this->base_URL .= "&".$this->getSessionVariableName($html_varName, "offset")."="; |
|
| 1498 | 1498 | } |
| 1499 | 1499 | |
| 1500 | - if($this->is_dynamic) { |
|
| 1501 | - $this->base_URL.='&to_pdf=true&action=SubPanelViewer&subpanel=' . $this->source_module; |
|
| 1500 | + if ($this->is_dynamic) { |
|
| 1501 | + $this->base_URL .= '&to_pdf=true&action=SubPanelViewer&subpanel='.$this->source_module; |
|
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | 1504 | //bug43465 start |
@@ -1506,19 +1506,19 @@ discard block |
||
| 1506 | 1506 | { |
| 1507 | 1507 | foreach ($this->appendToBaseUrl as $key => $value) |
| 1508 | 1508 | { |
| 1509 | - $fullRequestString = $key . '=' . $value; |
|
| 1509 | + $fullRequestString = $key.'='.$value; |
|
| 1510 | 1510 | |
| 1511 | 1511 | if ($this->base_URL == "/index.php") |
| 1512 | 1512 | { |
| 1513 | 1513 | $this->base_URL .= "?"; |
| 1514 | 1514 | } else |
| 1515 | 1515 | { |
| 1516 | - if ($fullRequestString == substr($this->baseURL, '-' . strlen($fullRequestString))) |
|
| 1516 | + if ($fullRequestString == substr($this->baseURL, '-'.strlen($fullRequestString))) |
|
| 1517 | 1517 | { |
| 1518 | - $this->base_URL = preg_replace("/&" . $key . "\=.*/", "", $this->base_URL); |
|
| 1518 | + $this->base_URL = preg_replace("/&".$key."\=.*/", "", $this->base_URL); |
|
| 1519 | 1519 | } else |
| 1520 | 1520 | { |
| 1521 | - $this->base_URL = preg_replace("/&" . $key . "\=.*?&/", "&", $this->base_URL); |
|
| 1521 | + $this->base_URL = preg_replace("/&".$key."\=.*?&/", "&", $this->base_URL); |
|
| 1522 | 1522 | } |
| 1523 | 1523 | $this->base_URL .= "&"; |
| 1524 | 1524 | } |
@@ -1530,9 +1530,9 @@ discard block |
||
| 1530 | 1530 | } |
| 1531 | 1531 | //bug43465 end |
| 1532 | 1532 | |
| 1533 | - $sort_URL_base = $this->base_URL. "&".$this->getSessionVariableName($html_varName,"ORDER_BY")."="; |
|
| 1533 | + $sort_URL_base = $this->base_URL."&".$this->getSessionVariableName($html_varName, "ORDER_BY")."="; |
|
| 1534 | 1534 | |
| 1535 | - if($sort_URL_base !== "") |
|
| 1535 | + if ($sort_URL_base !== "") |
|
| 1536 | 1536 | { |
| 1537 | 1537 | $this->xTemplate->assign("ORDER_BY", $sort_URL_base); |
| 1538 | 1538 | return $sort_URL_base; |
@@ -1583,19 +1583,19 @@ discard block |
||
| 1583 | 1583 | $mergeList = array(); |
| 1584 | 1584 | $module = ''; |
| 1585 | 1585 | //todo what is this? It is using an array as a boolean |
| 1586 | - while(list($aVal, $aItem) = each($data)) |
|
| 1586 | + while (list($aVal, $aItem) = each($data)) |
|
| 1587 | 1587 | { |
| 1588 | - if(isset($this->data_array)) { |
|
| 1588 | + if (isset($this->data_array)) { |
|
| 1589 | 1589 | $fields = $this->data_array; |
| 1590 | 1590 | } else { |
| 1591 | 1591 | $aItem->check_date_relationships_load(); |
| 1592 | 1592 | $fields = $aItem->get_list_view_data(); |
| 1593 | 1593 | } |
| 1594 | 1594 | |
| 1595 | - if(is_object($aItem)) { // cn: bug 5349 |
|
| 1595 | + if (is_object($aItem)) { // cn: bug 5349 |
|
| 1596 | 1596 | //add item id to merge list, if the button is clicked |
| 1597 | 1597 | $mergeList[] = $aItem->id; |
| 1598 | - if(empty($module)) { |
|
| 1598 | + if (empty($module)) { |
|
| 1599 | 1599 | $module = $aItem->module_dir; |
| 1600 | 1600 | } |
| 1601 | 1601 | } |
@@ -1604,37 +1604,37 @@ discard block |
||
| 1604 | 1604 | $fields['OFFSET'] = ($offset + $count + 1); |
| 1605 | 1605 | |
| 1606 | 1606 | $fields['STAMP'] = $timeStamp; |
| 1607 | - if($this->shouldProcess) { |
|
| 1607 | + if ($this->shouldProcess) { |
|
| 1608 | 1608 | |
| 1609 | 1609 | $prerow = ''; |
| 1610 | - if(!isset($this->data_array)) { |
|
| 1611 | - $prerow .= "<input onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='". $fields['ID']. "'>"; |
|
| 1610 | + if (!isset($this->data_array)) { |
|
| 1611 | + $prerow .= "<input onclick='sListView.check_item(this, document.MassUpdate)' type='checkbox' class='checkbox' name='mass[]' value='".$fields['ID']."'>"; |
|
| 1612 | 1612 | } |
| 1613 | 1613 | $this->xTemplate->assign('PREROW', $prerow); |
| 1614 | 1614 | |
| 1615 | 1615 | $this->xTemplate->assign('CHECKALL', "<input type='checkbox' class='checkbox' title='".$GLOBALS['app_strings']['LBL_SELECT_ALL_TITLE']."' name='massall' id='massall' value='' onclick='sListView.check_all(document.MassUpdate, \"mass[]\", this.checked)'>"); |
| 1616 | 1616 | } |
| 1617 | - if(!isset($this->data_array)) { |
|
| 1617 | + if (!isset($this->data_array)) { |
|
| 1618 | 1618 | $tag = $aItem->listviewACLHelper(); |
| 1619 | - $this->xTemplate->assign('TAG',$tag) ; |
|
| 1619 | + $this->xTemplate->assign('TAG', $tag); |
|
| 1620 | 1620 | } |
| 1621 | 1621 | |
| 1622 | - if($oddRow) |
|
| 1622 | + if ($oddRow) |
|
| 1623 | 1623 | { |
| 1624 | 1624 | $ROW_COLOR = 'oddListRow'; |
| 1625 | - $BG_COLOR = $odd_bg; |
|
| 1625 | + $BG_COLOR = $odd_bg; |
|
| 1626 | 1626 | } |
| 1627 | 1627 | else |
| 1628 | 1628 | { |
| 1629 | 1629 | $ROW_COLOR = 'evenListRow'; |
| 1630 | - $BG_COLOR = $even_bg; |
|
| 1630 | + $BG_COLOR = $even_bg; |
|
| 1631 | 1631 | } |
| 1632 | 1632 | $oddRow = !$oddRow; |
| 1633 | 1633 | |
| 1634 | 1634 | $this->xTemplate->assign('ROW_COLOR', $ROW_COLOR); |
| 1635 | 1635 | $this->xTemplate->assign('BG_COLOR', $BG_COLOR); |
| 1636 | 1636 | |
| 1637 | - if(isset($this->data_array)) |
|
| 1637 | + if (isset($this->data_array)) |
|
| 1638 | 1638 | { |
| 1639 | 1639 | $this->xTemplate->assign('KEY', $aVal); |
| 1640 | 1640 | $this->xTemplate->assign('VALUE', $aItem); |
@@ -1645,23 +1645,23 @@ discard block |
||
| 1645 | 1645 | { |
| 1646 | 1646 | //AED -- some modules do not have their additionalDetails.php established. Add a check to ensure require_once does not fail |
| 1647 | 1647 | // Bug #2786 |
| 1648 | - if($this->_additionalDetails && $aItem->ACLAccess('DetailView') && (file_exists('modules/' . $aItem->module_dir . '/metadata/additionalDetails.php') || file_exists('custom/modules/' . $aItem->module_dir . '/metadata/additionalDetails.php'))) { |
|
| 1648 | + if ($this->_additionalDetails && $aItem->ACLAccess('DetailView') && (file_exists('modules/'.$aItem->module_dir.'/metadata/additionalDetails.php') || file_exists('custom/modules/'.$aItem->module_dir.'/metadata/additionalDetails.php'))) { |
|
| 1649 | 1649 | |
| 1650 | - $additionalDetailsFile = 'modules/' . $aItem->module_dir . '/metadata/additionalDetails.php'; |
|
| 1651 | - if(file_exists('custom/modules/' . $aItem->module_dir . '/metadata/additionalDetails.php')){ |
|
| 1652 | - $additionalDetailsFile = 'custom/modules/' . $aItem->module_dir . '/metadata/additionalDetails.php'; |
|
| 1650 | + $additionalDetailsFile = 'modules/'.$aItem->module_dir.'/metadata/additionalDetails.php'; |
|
| 1651 | + if (file_exists('custom/modules/'.$aItem->module_dir.'/metadata/additionalDetails.php')) { |
|
| 1652 | + $additionalDetailsFile = 'custom/modules/'.$aItem->module_dir.'/metadata/additionalDetails.php'; |
|
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | 1655 | require_once($additionalDetailsFile); |
| 1656 | - $ad_function = (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction) . $aItem->object_name; |
|
| 1656 | + $ad_function = (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction).$aItem->object_name; |
|
| 1657 | 1657 | $results = $ad_function($fields); |
| 1658 | 1658 | $results['string'] = str_replace(array("'", "'"), '\'', $results['string']); // no xss! |
| 1659 | 1659 | |
| 1660 | - if(trim($results['string']) == '') $results['string'] = $app_strings['LBL_NONE']; |
|
| 1660 | + if (trim($results['string']) == '') $results['string'] = $app_strings['LBL_NONE']; |
|
| 1661 | 1661 | $fields[$results['fieldToAddTo']] = $fields[$results['fieldToAddTo']].'</a>'; |
| 1662 | 1662 | } |
| 1663 | 1663 | |
| 1664 | - if($aItem->ACLAccess('Delete')) { |
|
| 1664 | + if ($aItem->ACLAccess('Delete')) { |
|
| 1665 | 1665 | $delete = '<a class="listViewTdToolsS1" onclick="return confirm(\''.$this->local_app_strings['NTC_DELETE_CONFIRMATION'].'\')" href="'.'index.php?action=Delete&module='.$aItem->module_dir.'&record='.$fields['ID'].'&return_module='.$aItem->module_dir.'&return_action=index&return_id=">'.$this->local_app_strings['LBL_DELETE_INLINE'].'</a>'; |
| 1666 | 1666 | require_once('include/Smarty/plugins/function.sugar_action_menu.php'); |
| 1667 | 1667 | $fields['DELETE_BUTTON'] = smarty_function_sugar_action_menu(array( |
@@ -1675,26 +1675,26 @@ discard block |
||
| 1675 | 1675 | $aItem->setupCustomFields($aItem->module_dir); |
| 1676 | 1676 | $aItem->custom_fields->populateAllXTPL($this->xTemplate, 'detail', $html_varName, $fields); |
| 1677 | 1677 | } |
| 1678 | - if(!isset($this->data_array) && $aItem->ACLAccess('DetailView')) { |
|
| 1678 | + if (!isset($this->data_array) && $aItem->ACLAccess('DetailView')) { |
|
| 1679 | 1679 | $count++; |
| 1680 | 1680 | } |
| 1681 | - if(isset($this->data_array)) { |
|
| 1681 | + if (isset($this->data_array)) { |
|
| 1682 | 1682 | $count++; |
| 1683 | 1683 | } |
| 1684 | - if(!isset($this->data_array)) { |
|
| 1684 | + if (!isset($this->data_array)) { |
|
| 1685 | 1685 | $aItem->list_view_parse_additional_sections($this->xTemplate, $xtemplateSection); |
| 1686 | 1686 | |
| 1687 | - if($this->xTemplate->exists($xtemplateSection.'.row.pro')) { |
|
| 1687 | + if ($this->xTemplate->exists($xtemplateSection.'.row.pro')) { |
|
| 1688 | 1688 | $this->xTemplate->parse($xtemplateSection.'.row.pro'); |
| 1689 | 1689 | } |
| 1690 | 1690 | } |
| 1691 | - $this->xTemplate->parse($xtemplateSection . '.row'); |
|
| 1691 | + $this->xTemplate->parse($xtemplateSection.'.row'); |
|
| 1692 | 1692 | |
| 1693 | - if(isset($fields['ID'])) { |
|
| 1693 | + if (isset($fields['ID'])) { |
|
| 1694 | 1694 | $associated_row_data[$fields['ID']] = $fields; |
| 1695 | 1695 | // Bug 38908: cleanup data for JS to avoid having shuffled around |
| 1696 | - foreach($fields as $key => $value) { |
|
| 1697 | - if($value == ' ') { |
|
| 1696 | + foreach ($fields as $key => $value) { |
|
| 1697 | + if ($value == ' ') { |
|
| 1698 | 1698 | $associated_row_data[$fields['ID']][$key] = ''; |
| 1699 | 1699 | } |
| 1700 | 1700 | } |
@@ -1703,21 +1703,21 @@ discard block |
||
| 1703 | 1703 | |
| 1704 | 1704 | $_SESSION['MAILMERGE_RECORDS'] = $mergeList; |
| 1705 | 1705 | $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = $module; |
| 1706 | - if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 1706 | + if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 1707 | 1707 | $_SESSION['MAILMERGE_MODULE'] = $module; |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | - if($this->process_for_popups) |
|
| 1710 | + if ($this->process_for_popups) |
|
| 1711 | 1711 | { |
| 1712 | 1712 | $json = getJSONobj(); |
| 1713 | 1713 | $is_show_fullname = showFullName() ? 1 : 0; |
| 1714 | - $associated_javascript_data = '<script type="text/javascript">' . "\n" |
|
| 1714 | + $associated_javascript_data = '<script type="text/javascript">'."\n" |
|
| 1715 | 1715 | //. '<!-- // associated javascript data generated by ListView' . "\n" |
| 1716 | 1716 | . 'var associated_javascript_data = ' |
| 1717 | - . $json->encode($associated_row_data) . ";\n" |
|
| 1717 | + . $json->encode($associated_row_data).";\n" |
|
| 1718 | 1718 | //. '-->' . "\n" |
| 1719 | 1719 | . 'var is_show_fullname = ' |
| 1720 | - . $is_show_fullname . ";\n" |
|
| 1720 | + . $is_show_fullname.";\n" |
|
| 1721 | 1721 | . '</script>'; |
| 1722 | 1722 | $this->xTemplate->assign('ASSOCIATED_JAVASCRIPT_DATA', $associated_javascript_data); |
| 1723 | 1723 | } |
@@ -1729,7 +1729,7 @@ discard block |
||
| 1729 | 1729 | function getLayoutManager() |
| 1730 | 1730 | { |
| 1731 | 1731 | require_once('include/generic/LayoutManager.php'); |
| 1732 | - if($this->layout_manager == null) |
|
| 1732 | + if ($this->layout_manager == null) |
|
| 1733 | 1733 | { |
| 1734 | 1734 | $this->layout_manager = new LayoutManager(); |
| 1735 | 1735 | } |
@@ -1742,36 +1742,36 @@ discard block |
||
| 1742 | 1742 | |
| 1743 | 1743 | |
| 1744 | 1744 | $layout_manager = $this->getLayoutManager(); |
| 1745 | - $layout_manager->setAttribute('order_by_link',$this->processOrderBy($html_var)); |
|
| 1746 | - $layout_manager->setAttribute('context','HeaderCell'); |
|
| 1747 | - $layout_manager->setAttribute('image_path',$this->local_image_path); |
|
| 1748 | - $layout_manager->setAttribute('html_varName',$html_var); |
|
| 1745 | + $layout_manager->setAttribute('order_by_link', $this->processOrderBy($html_var)); |
|
| 1746 | + $layout_manager->setAttribute('context', 'HeaderCell'); |
|
| 1747 | + $layout_manager->setAttribute('image_path', $this->local_image_path); |
|
| 1748 | + $layout_manager->setAttribute('html_varName', $html_var); |
|
| 1749 | 1749 | $layout_manager->setAttribute('module_name', $source_module); |
| 1750 | - list($orderBy,$desc) = $this->getOrderByInfo($html_var); |
|
| 1750 | + list($orderBy, $desc) = $this->getOrderByInfo($html_var); |
|
| 1751 | 1751 | |
| 1752 | - if($orderBy == 'amount*1') |
|
| 1752 | + if ($orderBy == 'amount*1') |
|
| 1753 | 1753 | { |
| 1754 | - $orderBy= 'amount'; |
|
| 1754 | + $orderBy = 'amount'; |
|
| 1755 | 1755 | } |
| 1756 | 1756 | $buttons = false; |
| 1757 | 1757 | $col_count = 0; |
| 1758 | - foreach($subpanel_def->get_list_fields() as $column_name=>$widget_args) |
|
| 1758 | + foreach ($subpanel_def->get_list_fields() as $column_name=>$widget_args) |
|
| 1759 | 1759 | { |
| 1760 | 1760 | $usage = empty($widget_args['usage']) ? '' : $widget_args['usage']; |
| 1761 | - if($usage != 'query_only' || !empty($widget_args['force_query_only_display'])) |
|
| 1761 | + if ($usage != 'query_only' || !empty($widget_args['force_query_only_display'])) |
|
| 1762 | 1762 | { |
| 1763 | 1763 | $imgArrow = ''; |
| 1764 | 1764 | |
| 1765 | - if($orderBy == $column_name || (isset($widget_args['sort_by']) && str_replace('.','_',$widget_args['sort_by']) == $orderBy)) |
|
| 1765 | + if ($orderBy == $column_name || (isset($widget_args['sort_by']) && str_replace('.', '_', $widget_args['sort_by']) == $orderBy)) |
|
| 1766 | 1766 | { |
| 1767 | 1767 | $imgArrow = "_down"; |
| 1768 | - if($this->sort_order == 'asc') { |
|
| 1768 | + if ($this->sort_order == 'asc') { |
|
| 1769 | 1769 | $imgArrow = "_up"; |
| 1770 | 1770 | } |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | if (!preg_match("/_button/i", $column_name)) { |
| 1774 | - $widget_args['name']=$column_name; |
|
| 1774 | + $widget_args['name'] = $column_name; |
|
| 1775 | 1775 | $widget_args['sort'] = $imgArrow; |
| 1776 | 1776 | $widget_args['start_link_wrapper'] = $this->start_link_wrapper; |
| 1777 | 1777 | $widget_args['end_link_wrapper'] = $this->end_link_wrapper; |
@@ -1781,8 +1781,8 @@ discard block |
||
| 1781 | 1781 | $cell_width = empty($widget_args['width']) ? '' : $widget_args['width']; |
| 1782 | 1782 | $this->xTemplate->assign('HEADER_CELL', $widget_contents); |
| 1783 | 1783 | static $count; |
| 1784 | - if(!isset($count))$count = 0; else $count++; |
|
| 1785 | - if($col_count == 0 || $column_name == 'name') $footable = 'data-toggle="true"'; |
|
| 1784 | + if (!isset($count))$count = 0; else $count++; |
|
| 1785 | + if ($col_count == 0 || $column_name == 'name') $footable = 'data-toggle="true"'; |
|
| 1786 | 1786 | else { |
| 1787 | 1787 | $footable = 'data-hide="phone"'; |
| 1788 | 1788 | if ($col_count > 2) $footable = 'data-hide="phone,phonelandscape"'; |
@@ -1799,7 +1799,7 @@ discard block |
||
| 1799 | 1799 | ++$col_count; |
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | - if($buttons) { |
|
| 1802 | + if ($buttons) { |
|
| 1803 | 1803 | $this->xTemplate->assign('FOOTABLE', ''); |
| 1804 | 1804 | $this->xTemplate->assign('HEADER_CELL', " "); |
| 1805 | 1805 | $this->xTemplate->assign('CELL_COUNT', $count); |
@@ -1827,37 +1827,37 @@ discard block |
||
| 1827 | 1827 | |
| 1828 | 1828 | function processListViewTwo($seed, $xTemplateSection, $html_varName) { |
| 1829 | 1829 | global $current_user; |
| 1830 | - if(!isset($this->xTemplate)) { |
|
| 1830 | + if (!isset($this->xTemplate)) { |
|
| 1831 | 1831 | $this->createXTemplate(); |
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | 1834 | $isSugarBean = is_subclass_of($seed, "SugarBean"); |
| 1835 | 1835 | $list = null; |
| 1836 | 1836 | |
| 1837 | - if($isSugarBean) { |
|
| 1837 | + if ($isSugarBean) { |
|
| 1838 | 1838 | $list = $this->processSugarBean($xTemplateSection, $html_varName, $seed); |
| 1839 | 1839 | } else { |
| 1840 | 1840 | $list = $seed; |
| 1841 | 1841 | } |
| 1842 | 1842 | |
| 1843 | 1843 | if (is_object($seed) && isset($seed->object_name) && $seed->object_name == 'WorkFlow') { |
| 1844 | - $tab=array(); |
|
| 1844 | + $tab = array(); |
|
| 1845 | 1845 | $access = get_workflow_admin_modules_for_user($current_user); |
| 1846 | 1846 | for ($i = 0; $i < count($list); $i++) { |
| 1847 | - if(!empty($access[$list[$i]->base_module])){ |
|
| 1848 | - $tab[]=$list[$i]; |
|
| 1847 | + if (!empty($access[$list[$i]->base_module])) { |
|
| 1848 | + $tab[] = $list[$i]; |
|
| 1849 | 1849 | } |
| 1850 | 1850 | } |
| 1851 | 1851 | $list = $tab; |
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | - if($this->is_dynamic) { |
|
| 1855 | - $this->processHeaderDynamic($xTemplateSection,$html_varName); |
|
| 1856 | - $this->processListRows($list,$xTemplateSection, $html_varName); |
|
| 1854 | + if ($this->is_dynamic) { |
|
| 1855 | + $this->processHeaderDynamic($xTemplateSection, $html_varName); |
|
| 1856 | + $this->processListRows($list, $xTemplateSection, $html_varName); |
|
| 1857 | 1857 | } else { |
| 1858 | 1858 | $this->processSortArrows($html_varName); |
| 1859 | 1859 | |
| 1860 | - if($isSugarBean) { |
|
| 1860 | + if ($isSugarBean) { |
|
| 1861 | 1861 | $seed->parse_additional_headers($this->xTemplate, $xTemplateSection); |
| 1862 | 1862 | } |
| 1863 | 1863 | $this->xTemplateAssign('CHECKALL', SugarThemeRegistry::current()->getImage('blank', '', 1, 1, ".gif", '')); |
@@ -1866,19 +1866,19 @@ discard block |
||
| 1866 | 1866 | $this->processOrderBy($html_varName); |
| 1867 | 1867 | |
| 1868 | 1868 | |
| 1869 | - $this->processListRows($list,$xTemplateSection, $html_varName); |
|
| 1869 | + $this->processListRows($list, $xTemplateSection, $html_varName); |
|
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | - if($this->display_header_and_footer) { |
|
| 1872 | + if ($this->display_header_and_footer) { |
|
| 1873 | 1873 | $this->getAdditionalHeader(); |
| 1874 | - if(!empty($this->header_title)) { |
|
| 1874 | + if (!empty($this->header_title)) { |
|
| 1875 | 1875 | echo get_form_header($this->header_title, $this->header_text, false); |
| 1876 | 1876 | } |
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | 1879 | $this->xTemplate->out($xTemplateSection); |
| 1880 | 1880 | |
| 1881 | - if(isset($_SESSION['validation'])) { |
|
| 1881 | + if (isset($_SESSION['validation'])) { |
|
| 1882 | 1882 | print base64_decode('PGEgaHJlZj0naHR0cDovL3d3dy5zdWdhcmNybS5jb20nPlBPV0VSRUQmbmJzcDtCWSZuYnNwO1NVR0FSQ1JNPC9hPg=='); |
| 1883 | 1883 | } |
| 1884 | 1884 | } |
@@ -1890,7 +1890,7 @@ discard block |
||
| 1890 | 1890 | } |
| 1891 | 1891 | |
| 1892 | 1892 | function getArrowUpDownStart($upDown) { |
| 1893 | - $ext = ( SugarThemeRegistry::current()->pngSupport ? "png" : "gif" ); |
|
| 1893 | + $ext = (SugarThemeRegistry::current()->pngSupport ? "png" : "gif"); |
|
| 1894 | 1894 | |
| 1895 | 1895 | if (!isset($upDown) || empty($upDown)) { |
| 1896 | 1896 | $upDown = ""; |
@@ -1901,7 +1901,7 @@ discard block |
||
| 1901 | 1901 | function getArrowEnd() { |
| 1902 | 1902 | $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow.gif")); |
| 1903 | 1903 | |
| 1904 | - list($width,$height) = ListView::getArrowImageSize(); |
|
| 1904 | + list($width, $height) = ListView::getArrowImageSize(); |
|
| 1905 | 1905 | |
| 1906 | 1906 | return '.'.$imgFileParts['extension']."' width='$width' height='$height' align='absmiddle' alt=".translate('LBL_SORT').">"; |
| 1907 | 1907 | } |
@@ -1912,13 +1912,13 @@ discard block |
||
| 1912 | 1912 | } |
| 1913 | 1913 | $imgFileParts = pathinfo(SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.gif")); |
| 1914 | 1914 | |
| 1915 | - list($width,$height) = ListView::getArrowUpDownImageSize($upDown); |
|
| 1915 | + list($width, $height) = ListView::getArrowUpDownImageSize($upDown); |
|
| 1916 | 1916 | |
| 1917 | 1917 | //get the right alt tag for the sort |
| 1918 | 1918 | $sortStr = translate('LBL_ALT_SORT'); |
| 1919 | - if($upDown == '_down'){ |
|
| 1919 | + if ($upDown == '_down') { |
|
| 1920 | 1920 | $sortStr = translate('LBL_ALT_SORT_DESC'); |
| 1921 | - }elseif($upDown == '_up'){ |
|
| 1921 | + }elseif ($upDown == '_up') { |
|
| 1922 | 1922 | $sortStr = translate('LBL_ALT_SORT_ASC'); |
| 1923 | 1923 | } |
| 1924 | 1924 | return " width='$width' height='$height' align='absmiddle' alt='$sortStr'>"; |
@@ -1926,13 +1926,13 @@ discard block |
||
| 1926 | 1926 | |
| 1927 | 1927 | function getArrowImageSize() { |
| 1928 | 1928 | // jbasicChartDashletsExpColust get the non-sort image's size.. the up and down have be the same. |
| 1929 | - $image = SugarThemeRegistry::current()->getImageURL("arrow.gif",false); |
|
| 1929 | + $image = SugarThemeRegistry::current()->getImageURL("arrow.gif", false); |
|
| 1930 | 1930 | |
| 1931 | 1931 | $cache_key = 'arrow_size.'.$image; |
| 1932 | 1932 | |
| 1933 | 1933 | // Check the cache |
| 1934 | 1934 | $result = sugar_cache_retrieve($cache_key); |
| 1935 | - if(!empty($result)) |
|
| 1935 | + if (!empty($result)) |
|
| 1936 | 1936 | return $result; |
| 1937 | 1937 | |
| 1938 | 1938 | // No cache hit. Calculate the value and return. |
@@ -1943,13 +1943,13 @@ discard block |
||
| 1943 | 1943 | |
| 1944 | 1944 | function getArrowUpDownImageSize($upDown) { |
| 1945 | 1945 | // just get the non-sort image's size.. the up and down have be the same. |
| 1946 | - $image = SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.gif",false); |
|
| 1946 | + $image = SugarThemeRegistry::current()->getImageURL("arrow{$upDown}.gif", false); |
|
| 1947 | 1947 | |
| 1948 | 1948 | $cache_key = 'arrowupdown_size.'.$image; |
| 1949 | 1949 | |
| 1950 | 1950 | // Check the cache |
| 1951 | 1951 | $result = sugar_cache_retrieve($cache_key); |
| 1952 | - if(!empty($result)) |
|
| 1952 | + if (!empty($result)) |
|
| 1953 | 1953 | return $result; |
| 1954 | 1954 | |
| 1955 | 1955 | // No cache hit. Calculate the value and return. |
@@ -1963,7 +1963,7 @@ discard block |
||
| 1963 | 1963 | $orderBy = $this->getSessionVariable($html_varName, "OBL"); |
| 1964 | 1964 | $desc = $this->getSessionVariable($html_varName, $orderBy.'S'); |
| 1965 | 1965 | $orderBy = str_replace('.', '_', $orderBy); |
| 1966 | - return array($orderBy,$desc); |
|
| 1966 | + return array($orderBy, $desc); |
|
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | 1969 | function processSortArrows($html_varName) |
@@ -1971,20 +1971,20 @@ discard block |
||
| 1971 | 1971 | |
| 1972 | 1972 | $this->xTemplateAssign("arrow_start", $this->getArrowStart()); |
| 1973 | 1973 | |
| 1974 | - list($orderBy,$desc) = $this->getOrderByInfo($html_varName); |
|
| 1974 | + list($orderBy, $desc) = $this->getOrderByInfo($html_varName); |
|
| 1975 | 1975 | |
| 1976 | 1976 | $imgArrow = "_up"; |
| 1977 | - if($desc) { |
|
| 1977 | + if ($desc) { |
|
| 1978 | 1978 | $imgArrow = "_down"; |
| 1979 | 1979 | } |
| 1980 | 1980 | /** |
| 1981 | 1981 | * @deprecated only used by legacy opportunites listview, nothing current. Leaving for BC |
| 1982 | 1982 | */ |
| 1983 | - if($orderBy == 'amount') |
|
| 1983 | + if ($orderBy == 'amount') |
|
| 1984 | 1984 | { |
| 1985 | 1985 | $this->xTemplateAssign('amount_arrow', $imgArrow); |
| 1986 | 1986 | } |
| 1987 | - else if($orderBy == 'amount_usdollar') |
|
| 1987 | + else if ($orderBy == 'amount_usdollar') |
|
| 1988 | 1988 | { |
| 1989 | 1989 | $this->xTemplateAssign('amount_usdollar_arrow', $imgArrow); |
| 1990 | 1990 | } |
@@ -1997,31 +1997,31 @@ discard block |
||
| 1997 | 1997 | } |
| 1998 | 1998 | |
| 1999 | 1999 | // this is where translation happens for dynamic list views |
| 2000 | - function loadListFieldDefs(&$subpanel_fields,&$child_focus) |
|
| 2000 | + function loadListFieldDefs(&$subpanel_fields, &$child_focus) |
|
| 2001 | 2001 | { |
| 2002 | 2002 | $this->list_field_defs = $subpanel_fields; |
| 2003 | 2003 | |
| 2004 | - for($i=0;$i < count($this->list_field_defs);$i++) |
|
| 2004 | + for ($i = 0; $i < count($this->list_field_defs); $i++) |
|
| 2005 | 2005 | { |
| 2006 | 2006 | $list_field = $this->list_field_defs[$i]; |
| 2007 | 2007 | $field_def = null; |
| 2008 | 2008 | $key = ''; |
| 2009 | - if(!empty($list_field['vname'])) |
|
| 2009 | + if (!empty($list_field['vname'])) |
|
| 2010 | 2010 | { |
| 2011 | 2011 | $key = $list_field['vname']; |
| 2012 | - } else if(isset($list_field['name']) && isset($child_focus->field_defs[$list_field['name']])) |
|
| 2012 | + } else if (isset($list_field['name']) && isset($child_focus->field_defs[$list_field['name']])) |
|
| 2013 | 2013 | { |
| 2014 | 2014 | $field_def = $child_focus->field_defs[$list_field['name']]; |
| 2015 | 2015 | $key = $field_def['vname']; |
| 2016 | 2016 | } |
| 2017 | - if(!empty($key)) |
|
| 2017 | + if (!empty($key)) |
|
| 2018 | 2018 | { |
| 2019 | - $list_field['label'] = translate($key,$child_focus->module_dir); |
|
| 2020 | - $this->list_field_defs[$i]['label'] = preg_replace('/:$/','',$list_field['label']); |
|
| 2019 | + $list_field['label'] = translate($key, $child_focus->module_dir); |
|
| 2020 | + $this->list_field_defs[$i]['label'] = preg_replace('/:$/', '', $list_field['label']); |
|
| 2021 | 2021 | } |
| 2022 | 2022 | else |
| 2023 | 2023 | { |
| 2024 | - $this->list_field_defs[$i]['label'] =' '; |
|
| 2024 | + $this->list_field_defs[$i]['label'] = ' '; |
|
| 2025 | 2025 | } |
| 2026 | 2026 | } |
| 2027 | 2027 | } |
@@ -2036,7 +2036,7 @@ discard block |
||
| 2036 | 2036 | * All Rights Reserved. |
| 2037 | 2037 | * Contributor(s): ______________________________________. |
| 2038 | 2038 | */ |
| 2039 | - function setLocalSessionVariable($localVarName,$varName, $value) { |
|
| 2039 | + function setLocalSessionVariable($localVarName, $varName, $value) { |
|
| 2040 | 2040 | $_SESSION[$localVarName."_".$varName] = $value; |
| 2041 | 2041 | } |
| 2042 | 2042 | |
@@ -2046,11 +2046,11 @@ discard block |
||
| 2046 | 2046 | * All Rights Reserved. |
| 2047 | 2047 | * Contributor(s): ______________________________________. |
| 2048 | 2048 | */ |
| 2049 | - function getLocalSessionVariable($localVarName,$varName) { |
|
| 2050 | - if(isset($_SESSION[$localVarName."_".$varName])) { |
|
| 2049 | + function getLocalSessionVariable($localVarName, $varName) { |
|
| 2050 | + if (isset($_SESSION[$localVarName."_".$varName])) { |
|
| 2051 | 2051 | return $_SESSION[$localVarName."_".$varName]; |
| 2052 | 2052 | } |
| 2053 | - else{ |
|
| 2053 | + else { |
|
| 2054 | 2054 | return ""; |
| 2055 | 2055 | } |
| 2056 | 2056 | } |
@@ -2058,7 +2058,7 @@ discard block |
||
| 2058 | 2058 | /* Set to true if you want Additional Details to appear in the listview |
| 2059 | 2059 | */ |
| 2060 | 2060 | function setAdditionalDetails($value = true, $function = '') { |
| 2061 | - if(!empty($function)) $this->additionalDetailsFunction = $function; |
|
| 2061 | + if (!empty($function)) $this->additionalDetailsFunction = $function; |
|
| 2062 | 2062 | $this->_additionalDetails = $value; |
| 2063 | 2063 | } |
| 2064 | 2064 | |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -135,9 +137,13 @@ discard block |
||
| 135 | 137 | } |
| 136 | 138 | |
| 137 | 139 | //when processing a multi-select popup. |
| 138 | - if($this->process_for_popups && $this->multi_select_popup) $this->shouldProcess =true; |
|
| 140 | + if($this->process_for_popups && $this->multi_select_popup) { |
|
| 141 | + $this->shouldProcess =true; |
|
| 142 | + } |
|
| 139 | 143 | //mass update turned off? |
| 140 | - if(!$this->show_mass_update) $this->shouldProcess = false; |
|
| 144 | + if(!$this->show_mass_update) { |
|
| 145 | + $this->shouldProcess = false; |
|
| 146 | + } |
|
| 141 | 147 | if(is_subclass_of($seed, "SugarBean")) { |
| 142 | 148 | if($seed->bean_implements('ACL')) { |
| 143 | 149 | if(!ACLController::checkAccess($seed->module_dir,'list',true)) { |
@@ -188,8 +194,9 @@ discard block |
||
| 188 | 194 | { |
| 189 | 195 | $this->source_module = $source_module; |
| 190 | 196 | $this->subpanel_module = $subpanel_def->name; |
| 191 | - if(!isset($this->xTemplate)) |
|
| 192 | - $this->createXTemplate(); |
|
| 197 | + if(!isset($this->xTemplate)) { |
|
| 198 | + $this->createXTemplate(); |
|
| 199 | + } |
|
| 193 | 200 | |
| 194 | 201 | $html_var = $this->subpanel_module . "_CELL"; |
| 195 | 202 | |
@@ -280,8 +287,9 @@ discard block |
||
| 280 | 287 | if ( empty($data) ) { |
| 281 | 288 | $this->xTemplate->assign("ROW_COLOR", 'oddListRow'); |
| 282 | 289 | $thepanel=$subpanel_def; |
| 283 | - if($subpanel_def->isCollection()) |
|
| 284 | - $thepanel=$subpanel_def->get_header_panel_def(); |
|
| 290 | + if($subpanel_def->isCollection()) { |
|
| 291 | + $thepanel=$subpanel_def->get_header_panel_def(); |
|
| 292 | + } |
|
| 285 | 293 | $this->xTemplate->assign("COL_COUNT", count($thepanel->get_list_fields())); |
| 286 | 294 | $this->xTemplate->parse($xtemplateSection.".nodata"); |
| 287 | 295 | } |
@@ -339,8 +347,7 @@ discard block |
||
| 339 | 347 | { |
| 340 | 348 | $ROW_COLOR = 'oddListRow'; |
| 341 | 349 | $BG_COLOR = $odd_bg; |
| 342 | - } |
|
| 343 | - else |
|
| 350 | + } else |
|
| 344 | 351 | { |
| 345 | 352 | $ROW_COLOR = 'evenListRow'; |
| 346 | 353 | $BG_COLOR = $even_bg; |
@@ -353,8 +360,9 @@ discard block |
||
| 353 | 360 | $layout_manager->setAttribute('context','List'); |
| 354 | 361 | $layout_manager->setAttribute('image_path',$this->local_image_path); |
| 355 | 362 | $layout_manager->setAttribute('module_name', $subpanel_def->_instance_properties['module']); |
| 356 | - if(!empty($this->child_focus)) |
|
| 357 | - $layout_manager->setAttribute('related_module_name',$this->child_focus->module_dir); |
|
| 363 | + if(!empty($this->child_focus)) { |
|
| 364 | + $layout_manager->setAttribute('related_module_name',$this->child_focus->module_dir); |
|
| 365 | + } |
|
| 358 | 366 | |
| 359 | 367 | //AG$subpanel_data = $this->list_field_defs; |
| 360 | 368 | //$bla = array_pop($subpanel_data); |
@@ -389,7 +397,9 @@ discard block |
||
| 389 | 397 | $linked_field=$thepanel->get_data_source_name(); |
| 390 | 398 | $linked_field_set=$thepanel->get_data_source_name(true); |
| 391 | 399 | static $count; |
| 392 | - if(!isset($count))$count = 0; |
|
| 400 | + if(!isset($count)) { |
|
| 401 | + $count = 0; |
|
| 402 | + } |
|
| 393 | 403 | /* BEGIN - SECURITY GROUPS */ |
| 394 | 404 | /** |
| 395 | 405 | $field_acl['DetailView'] = $aItem->ACLAccess('DetailView'); |
@@ -420,7 +430,7 @@ discard block |
||
| 420 | 430 | $this->xTemplate->assign('CELL', $widget_contents); |
| 421 | 431 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 422 | 432 | |
| 423 | - }else if($usage != 'query_only') |
|
| 433 | + } else if($usage != 'query_only') |
|
| 424 | 434 | { |
| 425 | 435 | $list_field['name']=$field_name; |
| 426 | 436 | |
@@ -435,8 +445,11 @@ discard block |
||
| 435 | 445 | $list_field['owner_id'] = false; |
| 436 | 446 | $list_field['owner_module'] = false; |
| 437 | 447 | } |
| 438 | - if(isset($list_field['alias'])) $list_field['name'] = $list_field['alias']; |
|
| 439 | - else $list_field['name']=$field_name; |
|
| 448 | + if(isset($list_field['alias'])) { |
|
| 449 | + $list_field['name'] = $list_field['alias']; |
|
| 450 | + } else { |
|
| 451 | + $list_field['name']=$field_name; |
|
| 452 | + } |
|
| 440 | 453 | $list_field['fields'] = $fields; |
| 441 | 454 | $list_field['module'] = $aItem->module_dir; |
| 442 | 455 | $list_field['start_link_wrapper'] = $this->start_link_wrapper; |
@@ -485,7 +498,9 @@ discard block |
||
| 485 | 498 | $count++; |
| 486 | 499 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 487 | 500 | $this->xTemplate->assign('CLASS', ""); |
| 488 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 501 | + if ( empty($widget_contents) ) { |
|
| 502 | + $widget_contents = ' '; |
|
| 503 | + } |
|
| 489 | 504 | $this->xTemplate->assign('CELL', $widget_contents); |
| 490 | 505 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 491 | 506 | } else { |
@@ -495,7 +510,9 @@ discard block |
||
| 495 | 510 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 496 | 511 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 497 | 512 | $this->xTemplate->assign('CLASS', ""); |
| 498 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 513 | + if ( empty($widget_contents) ) { |
|
| 514 | + $widget_contents = ' '; |
|
| 515 | + } |
|
| 499 | 516 | $this->xTemplate->assign('CELL', $widget_contents); |
| 500 | 517 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 501 | 518 | } elseif (preg_match("/button/i", $list_field['name'])) { |
@@ -503,8 +520,7 @@ discard block |
||
| 503 | 520 | { |
| 504 | 521 | $button_contents[] = $_content; |
| 505 | 522 | unset($_content); |
| 506 | - } |
|
| 507 | - else |
|
| 523 | + } else |
|
| 508 | 524 | { |
| 509 | 525 | $button_contents[] = ''; |
| 510 | 526 | } |
@@ -513,7 +529,9 @@ discard block |
||
| 513 | 529 | $this->xTemplate->assign('CLASS', ""); |
| 514 | 530 | $widget_contents = $layout_manager->widgetDisplay($list_field); |
| 515 | 531 | $this->xTemplate->assign('CELL_COUNT', $count); |
| 516 | - if ( empty($widget_contents) ) $widget_contents = ' '; |
|
| 532 | + if ( empty($widget_contents) ) { |
|
| 533 | + $widget_contents = ' '; |
|
| 534 | + } |
|
| 517 | 535 | $this->xTemplate->assign('CELL', $widget_contents); |
| 518 | 536 | $this->xTemplate->parse($xtemplateSection.".row.cell"); |
| 519 | 537 | } |
@@ -541,8 +559,7 @@ discard block |
||
| 541 | 559 | 'class' => 'clickMenu subpanel records fancymenu button', |
| 542 | 560 | 'flat' => false //assign flat value as false to display dropdown menu at any other preferences. |
| 543 | 561 | ), $this->xTemplate); |
| 544 | - } |
|
| 545 | - else |
|
| 562 | + } else |
|
| 546 | 563 | { |
| 547 | 564 | $action_button = ''; |
| 548 | 565 | } |
@@ -629,11 +646,13 @@ discard block |
||
| 629 | 646 | */ |
| 630 | 647 | function initNewXTemplate($XTemplatePath, $modString, $imagePath = null) { |
| 631 | 648 | $this->setXTemplatePath($XTemplatePath); |
| 632 | - if(isset($modString)) |
|
| 633 | - $this->setModStrings($modString); |
|
| 634 | - if(isset($imagePath)) |
|
| 635 | - $this->setImagePath($imagePath); |
|
| 636 | -} |
|
| 649 | + if(isset($modString)) { |
|
| 650 | + $this->setModStrings($modString); |
|
| 651 | + } |
|
| 652 | + if(isset($imagePath)) { |
|
| 653 | + $this->setImagePath($imagePath); |
|
| 654 | + } |
|
| 655 | + } |
|
| 637 | 656 | |
| 638 | 657 | |
| 639 | 658 | function getOrderBy($varName, $defaultOrderBy='', $force_sortorder='') { |
@@ -714,7 +733,7 @@ discard block |
||
| 714 | 733 | } |
| 715 | 734 | //Just clear from url... |
| 716 | 735 | $this->appendToBaseUrl[$orderByColumn] = false; |
| 717 | - }else { |
|
| 736 | + } else { |
|
| 718 | 737 | $this->query_orderby = ""; |
| 719 | 738 | } |
| 720 | 739 | $this->sortby = $sortBy; |
@@ -759,8 +778,10 @@ discard block |
||
| 759 | 778 | */ |
| 760 | 779 | function setTheme($theme) { |
| 761 | 780 | $this->local_theme = $theme; |
| 762 | - if(isset($this->xTemplate))$this->xTemplate->assign("THEME", $this->local_theme); |
|
| 763 | -} |
|
| 781 | + if(isset($this->xTemplate)) { |
|
| 782 | + $this->xTemplate->assign("THEME", $this->local_theme); |
|
| 783 | + } |
|
| 784 | + } |
|
| 764 | 785 | |
| 765 | 786 | /**sets the AppStrings used only use if it is different from the global |
| 766 | 787 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -770,8 +791,10 @@ discard block |
||
| 770 | 791 | function setAppStrings($app_strings) { |
| 771 | 792 | unset($this->local_app_strings); |
| 772 | 793 | $this->local_app_strings = $app_strings; |
| 773 | - if(isset($this->xTemplate))$this->xTemplate->assign("APP", $this->local_app_strings); |
|
| 774 | -} |
|
| 794 | + if(isset($this->xTemplate)) { |
|
| 795 | + $this->xTemplate->assign("APP", $this->local_app_strings); |
|
| 796 | + } |
|
| 797 | + } |
|
| 775 | 798 | |
| 776 | 799 | /**sets the ModStrings used |
| 777 | 800 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -781,8 +804,10 @@ discard block |
||
| 781 | 804 | function setModStrings($mod_strings) { |
| 782 | 805 | unset($this->local_module_strings); |
| 783 | 806 | $this->local_mod_strings = $mod_strings; |
| 784 | - if(isset($this->xTemplate))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 785 | -} |
|
| 807 | + if(isset($this->xTemplate)) { |
|
| 808 | + $this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 809 | + } |
|
| 810 | + } |
|
| 786 | 811 | |
| 787 | 812 | /**sets the ImagePath used |
| 788 | 813 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -794,8 +819,10 @@ discard block |
||
| 794 | 819 | if(empty($this->local_image_path)) { |
| 795 | 820 | $this->local_image_path = SugarThemeRegistry::get($this->local_theme)->getImagePath(); |
| 796 | 821 | } |
| 797 | - if(isset($this->xTemplate))$this->xTemplate->assign("IMAGE_PATH", $this->local_image_path); |
|
| 798 | -} |
|
| 822 | + if(isset($this->xTemplate)) { |
|
| 823 | + $this->xTemplate->assign("IMAGE_PATH", $this->local_image_path); |
|
| 824 | + } |
|
| 825 | + } |
|
| 799 | 826 | |
| 800 | 827 | /**sets the currentModule only use if this is different from the global |
| 801 | 828 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -805,8 +832,10 @@ discard block |
||
| 805 | 832 | function setCurrentModule($currentModule) { |
| 806 | 833 | unset($this->local_current_module); |
| 807 | 834 | $this->local_current_module = $currentModule; |
| 808 | - if(isset($this->xTemplate))$this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
|
| 809 | -} |
|
| 835 | + if(isset($this->xTemplate)) { |
|
| 836 | + $this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
|
| 837 | + } |
|
| 838 | + } |
|
| 810 | 839 | |
| 811 | 840 | /**INTERNAL FUNCTION creates an XTemplate DO NOT CALL THIS THIS IS AN INTERNAL FUNCTION |
| 812 | 841 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -819,7 +848,9 @@ discard block |
||
| 819 | 848 | |
| 820 | 849 | $this->xTemplate = new XTemplate($this->xTemplatePath); |
| 821 | 850 | $this->xTemplate->assign("APP", $this->local_app_strings); |
| 822 | - if(isset($this->local_mod_strings))$this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 851 | + if(isset($this->local_mod_strings)) { |
|
| 852 | + $this->xTemplate->assign("MOD", $this->local_mod_strings); |
|
| 853 | + } |
|
| 823 | 854 | $this->xTemplate->assign("THEME", $this->local_theme); |
| 824 | 855 | $this->xTemplate->assign("IMAGE_PATH", $this->local_image_path); |
| 825 | 856 | $this->xTemplate->assign("MODULE_NAME", $this->local_current_module); |
@@ -896,7 +927,9 @@ discard block |
||
| 896 | 927 | } |
| 897 | 928 | |
| 898 | 929 | function setUserVariable($localVarName,$varName, $value) { |
| 899 | - if($this->is_dynamic || $localVarName == 'CELL')return; |
|
| 930 | + if($this->is_dynamic || $localVarName == 'CELL') { |
|
| 931 | + return; |
|
| 932 | + } |
|
| 900 | 933 | global $current_user; |
| 901 | 934 | $current_user->setPreference($this->local_current_module."_".$localVarName."_".$varName, $value); |
| 902 | 935 | } |
@@ -920,7 +953,9 @@ discard block |
||
| 920 | 953 | |
| 921 | 954 | function getUserVariable($localVarName, $varName) { |
| 922 | 955 | global $current_user; |
| 923 | - if($this->is_dynamic || $localVarName == 'CELL')return; |
|
| 956 | + if($this->is_dynamic || $localVarName == 'CELL') { |
|
| 957 | + return; |
|
| 958 | + } |
|
| 924 | 959 | if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
| 925 | 960 | |
| 926 | 961 | $this->setUserVariable($localVarName,$varName,$_REQUEST[$this->getSessionVariableName($localVarName, $varName)]); |
@@ -999,11 +1034,21 @@ discard block |
||
| 999 | 1034 | //$filter = array('id', 'full_name'); |
| 1000 | 1035 | $filter=array(); |
| 1001 | 1036 | $ret_array = $seed->create_new_list_query($this->query_orderby, $this->query_where, $filter, $params, 0, '', true, $seed, true); |
| 1002 | - if(!is_array($params)) $params = array(); |
|
| 1003 | - if(!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
| 1004 | - if(!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
| 1005 | - if(!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
| 1006 | - if(!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
| 1037 | + if(!is_array($params)) { |
|
| 1038 | + $params = array(); |
|
| 1039 | + } |
|
| 1040 | + if(!isset($params['custom_select'])) { |
|
| 1041 | + $params['custom_select'] = ''; |
|
| 1042 | + } |
|
| 1043 | + if(!isset($params['custom_from'])) { |
|
| 1044 | + $params['custom_from'] = ''; |
|
| 1045 | + } |
|
| 1046 | + if(!isset($params['custom_where'])) { |
|
| 1047 | + $params['custom_where'] = ''; |
|
| 1048 | + } |
|
| 1049 | + if(!isset($params['custom_order_by'])) { |
|
| 1050 | + $params['custom_order_by'] = ''; |
|
| 1051 | + } |
|
| 1007 | 1052 | $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
| 1008 | 1053 | SugarVCR::store($seed->module_dir, $main_query); |
| 1009 | 1054 | //ADDING VCR CONTROL |
@@ -1064,8 +1109,7 @@ discard block |
||
| 1064 | 1109 | { |
| 1065 | 1110 | $sort_order['session'] = $sort_order['session'] == 'asc' ? 'desc' : 'asc'; |
| 1066 | 1111 | } |
| 1067 | - } |
|
| 1068 | - else |
|
| 1112 | + } else |
|
| 1069 | 1113 | { |
| 1070 | 1114 | $sort_order['session'] = null; |
| 1071 | 1115 | } |
@@ -1097,7 +1141,7 @@ discard block |
||
| 1097 | 1141 | if(!empty($this->response)){ |
| 1098 | 1142 | $response =& $this->response; |
| 1099 | 1143 | echo 'cached'; |
| 1100 | - }else{ |
|
| 1144 | + } else{ |
|
| 1101 | 1145 | $response = SugarBean::get_union_related_list($sugarbean,$this->sortby, $this->sort_order, $this->query_where, $current_offset, -1, $this->records_per_page,$this->query_limit,$subpanel_def); |
| 1102 | 1146 | $this->response =& $response; |
| 1103 | 1147 | } |
@@ -1105,7 +1149,9 @@ discard block |
||
| 1105 | 1149 | $row_count = $response['row_count']; |
| 1106 | 1150 | $next_offset = $response['next_offset']; |
| 1107 | 1151 | $previous_offset = $response['previous_offset']; |
| 1108 | - if(!empty($response['current_offset']))$current_offset = $response['current_offset']; |
|
| 1152 | + if(!empty($response['current_offset'])) { |
|
| 1153 | + $current_offset = $response['current_offset']; |
|
| 1154 | + } |
|
| 1109 | 1155 | global $list_view_row_count; |
| 1110 | 1156 | $list_view_row_count = $row_count; |
| 1111 | 1157 | $this->processListNavigation('dyn_list_view', $html_var, $current_offset, $next_offset, $previous_offset, $row_count, $sugarbean,$subpanel_def); |
@@ -1116,7 +1162,9 @@ discard block |
||
| 1116 | 1162 | function getBaseURL($html_varName) { |
| 1117 | 1163 | static $cache = array(); |
| 1118 | 1164 | |
| 1119 | - if(!empty($cache[$html_varName]))return $cache[$html_varName]; |
|
| 1165 | + if(!empty($cache[$html_varName])) { |
|
| 1166 | + return $cache[$html_varName]; |
|
| 1167 | + } |
|
| 1120 | 1168 | $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount','current_query_by_page'); |
| 1121 | 1169 | if(!empty($this->base_URL)) { |
| 1122 | 1170 | return $this->base_URL; |
@@ -1136,10 +1184,11 @@ discard block |
||
| 1136 | 1184 | { |
| 1137 | 1185 | if(is_array($value)) { |
| 1138 | 1186 | foreach($value as $valuename=>$valuevalue) { |
| 1139 | - if(substr_count($baseurl, '?') > 0) |
|
| 1140 | - $baseurl .= "&{$name}[]=".$valuevalue; |
|
| 1141 | - else |
|
| 1142 | - $baseurl .= "?{$name}[]=".$valuevalue; |
|
| 1187 | + if(substr_count($baseurl, '?') > 0) { |
|
| 1188 | + $baseurl .= "&{$name}[]=".$valuevalue; |
|
| 1189 | + } else { |
|
| 1190 | + $baseurl .= "?{$name}[]=".$valuevalue; |
|
| 1191 | + } |
|
| 1143 | 1192 | } |
| 1144 | 1193 | } else { |
| 1145 | 1194 | $value = urlencode($value); |
@@ -1158,9 +1207,15 @@ discard block |
||
| 1158 | 1207 | if(substr_count($baseurl, '?') == 0) { |
| 1159 | 1208 | $baseurl .= '?'; |
| 1160 | 1209 | } |
| 1161 | - if(isset($_REQUEST['action'])) $baseurl.= '&action='.$_REQUEST['action']; |
|
| 1162 | - if(isset($_REQUEST['record'])) $baseurl .= '&record='.$_REQUEST['record']; |
|
| 1163 | - if(isset($_REQUEST['module'])) $baseurl .= '&module='.$_REQUEST['module']; |
|
| 1210 | + if(isset($_REQUEST['action'])) { |
|
| 1211 | + $baseurl.= '&action='.$_REQUEST['action']; |
|
| 1212 | + } |
|
| 1213 | + if(isset($_REQUEST['record'])) { |
|
| 1214 | + $baseurl .= '&record='.$_REQUEST['record']; |
|
| 1215 | + } |
|
| 1216 | + if(isset($_REQUEST['module'])) { |
|
| 1217 | + $baseurl .= '&module='.$_REQUEST['module']; |
|
| 1218 | + } |
|
| 1164 | 1219 | } |
| 1165 | 1220 | |
| 1166 | 1221 | $baseurl .= "&".ListView::getSessionVariableName($html_varName,"offset")."="; |
@@ -1187,11 +1242,13 @@ discard block |
||
| 1187 | 1242 | |
| 1188 | 1243 | $start_record = $current_offset + 1; |
| 1189 | 1244 | |
| 1190 | - if(!is_numeric($col_count)) |
|
| 1191 | - $col_count = 20; |
|
| 1245 | + if(!is_numeric($col_count)) { |
|
| 1246 | + $col_count = 20; |
|
| 1247 | + } |
|
| 1192 | 1248 | |
| 1193 | - if($row_count == 0) |
|
| 1194 | - $start_record = 0; |
|
| 1249 | + if($row_count == 0) { |
|
| 1250 | + $start_record = 0; |
|
| 1251 | + } |
|
| 1195 | 1252 | |
| 1196 | 1253 | $end_record = $start_record + $this->records_per_page; |
| 1197 | 1254 | // back up the the last page. |
@@ -1199,10 +1256,11 @@ discard block |
||
| 1199 | 1256 | $end_record = $row_count+1; |
| 1200 | 1257 | } |
| 1201 | 1258 | // Determine the start location of the last page |
| 1202 | - if($row_count == 0) |
|
| 1203 | - $number_pages = 0; |
|
| 1204 | - else |
|
| 1205 | - $number_pages = floor(($row_count - 1) / $this->records_per_page); |
|
| 1259 | + if($row_count == 0) { |
|
| 1260 | + $number_pages = 0; |
|
| 1261 | + } else { |
|
| 1262 | + $number_pages = floor(($row_count - 1) / $this->records_per_page); |
|
| 1263 | + } |
|
| 1206 | 1264 | |
| 1207 | 1265 | $last_offset = $number_pages * $this->records_per_page; |
| 1208 | 1266 | |
@@ -1262,7 +1320,7 @@ discard block |
||
| 1262 | 1320 | $onClick = ''; |
| 1263 | 1321 | if(0 != preg_match('/javascript.*/', $start_URL)){ |
| 1264 | 1322 | $onClick = "\"$start_URL;\""; |
| 1265 | - }else{ |
|
| 1323 | + } else{ |
|
| 1266 | 1324 | $onClick ="'location.href=\"$start_URL\";'"; |
| 1267 | 1325 | } |
| 1268 | 1326 | $start_link = "<button type='button' class='button' name='listViewStartButton' title='{$this->local_app_strings['LNK_LIST_START']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("start","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_START'])."</button>"; |
@@ -1270,7 +1328,7 @@ discard block |
||
| 1270 | 1328 | $onClick = ''; |
| 1271 | 1329 | if(0 != preg_match('/javascript.*/', $previous_URL)){ |
| 1272 | 1330 | $onClick = "\"$previous_URL;\""; |
| 1273 | - }else{ |
|
| 1331 | + } else{ |
|
| 1274 | 1332 | $onClick = "'location.href=\"$previous_URL\";'"; |
| 1275 | 1333 | } |
| 1276 | 1334 | $previous_link = "<button type='button' class='button' name='listViewPrevButton' title='{$this->local_app_strings['LNK_LIST_PREVIOUS']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("previous","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_PREVIOUS'])."</button>"; |
@@ -1294,7 +1352,7 @@ discard block |
||
| 1294 | 1352 | $onClick = ''; |
| 1295 | 1353 | if(0 != preg_match('/javascript.*/', $next_URL)){ |
| 1296 | 1354 | $onClick = "\"$next_URL;\""; |
| 1297 | - }else{ |
|
| 1355 | + } else{ |
|
| 1298 | 1356 | $onClick ="'location.href=\"$next_URL\";'"; |
| 1299 | 1357 | } |
| 1300 | 1358 | $next_link = "<button type='button' name='listViewNextButton' class='button' title='{$this->local_app_strings['LNK_LIST_NEXT']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("next","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_NEXT'])."</button>"; |
@@ -1302,7 +1360,7 @@ discard block |
||
| 1302 | 1360 | $onClick = ''; |
| 1303 | 1361 | if(0 != preg_match('/javascript.*/', $end_URL)){ |
| 1304 | 1362 | $onClick = "\"$end_URL;\""; |
| 1305 | - }else{ |
|
| 1363 | + } else{ |
|
| 1306 | 1364 | $onClick = "'location.href=\"$end_URL\";'"; |
| 1307 | 1365 | } |
| 1308 | 1366 | $end_link = "<button type='button' name='listViewEndButton' class='button' title='{$this->local_app_strings['LNK_LIST_END']}' onClick=".$onClick.">".SugarThemeRegistry::current()->getImage("end","border='0' align='absmiddle'",null,null,'.gif',$this->local_app_strings['LNK_LIST_END'])."</button>"; |
@@ -1451,18 +1509,17 @@ discard block |
||
| 1451 | 1509 | //attempt to get the query to recreate this subpanel |
| 1452 | 1510 | if(!empty($this->response)){ |
| 1453 | 1511 | $response =& $this->response; |
| 1454 | - }else{ |
|
| 1512 | + } else{ |
|
| 1455 | 1513 | $response = SugarBean::get_union_related_list($sugarbean,$this->sortby, $this->sort_order, $this->query_where, $current_offset, -1, $this->records_per_page,$this->query_limit,$subpanel_def); |
| 1456 | 1514 | $this->response = $response; |
| 1457 | 1515 | } |
| 1458 | 1516 | //if query is present, then pass it in as parameter |
| 1459 | 1517 | if (isset($response['query']) && !empty($response['query'])){ |
| 1460 | 1518 | $html_text .= $subpanelTiles->get_buttons($subpanel_def, $response['query']); |
| 1461 | - }else{ |
|
| 1519 | + } else{ |
|
| 1462 | 1520 | $html_text .= $subpanelTiles->get_buttons($subpanel_def); |
| 1463 | 1521 | } |
| 1464 | - } |
|
| 1465 | - else { |
|
| 1522 | + } else { |
|
| 1466 | 1523 | $html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td align=\"left\" nowrap>$select_link $export_link $delete_link $selected_objects_span"; |
| 1467 | 1524 | } |
| 1468 | 1525 | $html_text .= "</td>\n<td nowrap align=\"right\">".$start_link." ".$previous_link." <span class='pageNumbers'>(".$start_record." - ".$end_record." ".$this->local_app_strings['LBL_LIST_OF']." ".$row_count.")</span> ".$next_link." ".$end_link."</td></tr></table>\n"; |
@@ -1490,9 +1547,15 @@ discard block |
||
| 1490 | 1547 | } |
| 1491 | 1548 | if($_SERVER['REQUEST_METHOD'] == 'POST') { |
| 1492 | 1549 | $this->base_URL .= '?'; |
| 1493 | - if(isset($_REQUEST['action'])) $this->base_URL .= '&action='.$_REQUEST['action']; |
|
| 1494 | - if(isset($_REQUEST['record'])) $this->base_URL .= '&record='.$_REQUEST['record']; |
|
| 1495 | - if(isset($_REQUEST['module'])) $this->base_URL .= '&module='.$_REQUEST['module']; |
|
| 1550 | + if(isset($_REQUEST['action'])) { |
|
| 1551 | + $this->base_URL .= '&action='.$_REQUEST['action']; |
|
| 1552 | + } |
|
| 1553 | + if(isset($_REQUEST['record'])) { |
|
| 1554 | + $this->base_URL .= '&record='.$_REQUEST['record']; |
|
| 1555 | + } |
|
| 1556 | + if(isset($_REQUEST['module'])) { |
|
| 1557 | + $this->base_URL .= '&module='.$_REQUEST['module']; |
|
| 1558 | + } |
|
| 1496 | 1559 | } |
| 1497 | 1560 | $this->base_URL .= "&".$this->getSessionVariableName($html_varName,"offset")."="; |
| 1498 | 1561 | } |
@@ -1623,8 +1686,7 @@ discard block |
||
| 1623 | 1686 | { |
| 1624 | 1687 | $ROW_COLOR = 'oddListRow'; |
| 1625 | 1688 | $BG_COLOR = $odd_bg; |
| 1626 | - } |
|
| 1627 | - else |
|
| 1689 | + } else |
|
| 1628 | 1690 | { |
| 1629 | 1691 | $ROW_COLOR = 'evenListRow'; |
| 1630 | 1692 | $BG_COLOR = $even_bg; |
@@ -1640,8 +1702,7 @@ discard block |
||
| 1640 | 1702 | $this->xTemplate->assign('VALUE', $aItem); |
| 1641 | 1703 | $this->xTemplate->assign('INDEX', $count); |
| 1642 | 1704 | |
| 1643 | - } |
|
| 1644 | - else |
|
| 1705 | + } else |
|
| 1645 | 1706 | { |
| 1646 | 1707 | //AED -- some modules do not have their additionalDetails.php established. Add a check to ensure require_once does not fail |
| 1647 | 1708 | // Bug #2786 |
@@ -1657,7 +1718,9 @@ discard block |
||
| 1657 | 1718 | $results = $ad_function($fields); |
| 1658 | 1719 | $results['string'] = str_replace(array("'", "'"), '\'', $results['string']); // no xss! |
| 1659 | 1720 | |
| 1660 | - if(trim($results['string']) == '') $results['string'] = $app_strings['LBL_NONE']; |
|
| 1721 | + if(trim($results['string']) == '') { |
|
| 1722 | + $results['string'] = $app_strings['LBL_NONE']; |
|
| 1723 | + } |
|
| 1661 | 1724 | $fields[$results['fieldToAddTo']] = $fields[$results['fieldToAddTo']].'</a>'; |
| 1662 | 1725 | } |
| 1663 | 1726 | |
@@ -1781,12 +1844,21 @@ discard block |
||
| 1781 | 1844 | $cell_width = empty($widget_args['width']) ? '' : $widget_args['width']; |
| 1782 | 1845 | $this->xTemplate->assign('HEADER_CELL', $widget_contents); |
| 1783 | 1846 | static $count; |
| 1784 | - if(!isset($count))$count = 0; else $count++; |
|
| 1785 | - if($col_count == 0 || $column_name == 'name') $footable = 'data-toggle="true"'; |
|
| 1786 | - else { |
|
| 1847 | + if(!isset($count)) { |
|
| 1848 | + $count = 0; |
|
| 1849 | + } else { |
|
| 1850 | + $count++; |
|
| 1851 | + } |
|
| 1852 | + if($col_count == 0 || $column_name == 'name') { |
|
| 1853 | + $footable = 'data-toggle="true"'; |
|
| 1854 | + } else { |
|
| 1787 | 1855 | $footable = 'data-hide="phone"'; |
| 1788 | - if ($col_count > 2) $footable = 'data-hide="phone,phonelandscape"'; |
|
| 1789 | - if ($col_count > 4) $footable = 'data-hide="phone,phonelandscape,tablet"'; |
|
| 1856 | + if ($col_count > 2) { |
|
| 1857 | + $footable = 'data-hide="phone,phonelandscape"'; |
|
| 1858 | + } |
|
| 1859 | + if ($col_count > 4) { |
|
| 1860 | + $footable = 'data-hide="phone,phonelandscape,tablet"'; |
|
| 1861 | + } |
|
| 1790 | 1862 | } |
| 1791 | 1863 | $this->xTemplate->assign('FOOTABLE', $footable); |
| 1792 | 1864 | $this->xTemplate->assign('CELL_COUNT', $count); |
@@ -1918,7 +1990,7 @@ discard block |
||
| 1918 | 1990 | $sortStr = translate('LBL_ALT_SORT'); |
| 1919 | 1991 | if($upDown == '_down'){ |
| 1920 | 1992 | $sortStr = translate('LBL_ALT_SORT_DESC'); |
| 1921 | - }elseif($upDown == '_up'){ |
|
| 1993 | + } elseif($upDown == '_up'){ |
|
| 1922 | 1994 | $sortStr = translate('LBL_ALT_SORT_ASC'); |
| 1923 | 1995 | } |
| 1924 | 1996 | return " width='$width' height='$height' align='absmiddle' alt='$sortStr'>"; |
@@ -1932,8 +2004,9 @@ discard block |
||
| 1932 | 2004 | |
| 1933 | 2005 | // Check the cache |
| 1934 | 2006 | $result = sugar_cache_retrieve($cache_key); |
| 1935 | - if(!empty($result)) |
|
| 1936 | - return $result; |
|
| 2007 | + if(!empty($result)) { |
|
| 2008 | + return $result; |
|
| 2009 | + } |
|
| 1937 | 2010 | |
| 1938 | 2011 | // No cache hit. Calculate the value and return. |
| 1939 | 2012 | $result = getimagesize($image); |
@@ -1949,8 +2022,9 @@ discard block |
||
| 1949 | 2022 | |
| 1950 | 2023 | // Check the cache |
| 1951 | 2024 | $result = sugar_cache_retrieve($cache_key); |
| 1952 | - if(!empty($result)) |
|
| 1953 | - return $result; |
|
| 2025 | + if(!empty($result)) { |
|
| 2026 | + return $result; |
|
| 2027 | + } |
|
| 1954 | 2028 | |
| 1955 | 2029 | // No cache hit. Calculate the value and return. |
| 1956 | 2030 | $result = getimagesize($image); |
@@ -1983,12 +2057,10 @@ discard block |
||
| 1983 | 2057 | if($orderBy == 'amount') |
| 1984 | 2058 | { |
| 1985 | 2059 | $this->xTemplateAssign('amount_arrow', $imgArrow); |
| 1986 | - } |
|
| 1987 | - else if($orderBy == 'amount_usdollar') |
|
| 2060 | + } else if($orderBy == 'amount_usdollar') |
|
| 1988 | 2061 | { |
| 1989 | 2062 | $this->xTemplateAssign('amount_usdollar_arrow', $imgArrow); |
| 1990 | - } |
|
| 1991 | - else |
|
| 2063 | + } else |
|
| 1992 | 2064 | { |
| 1993 | 2065 | $this->xTemplateAssign($orderBy.'_arrow', $imgArrow); |
| 1994 | 2066 | } |
@@ -2018,8 +2090,7 @@ discard block |
||
| 2018 | 2090 | { |
| 2019 | 2091 | $list_field['label'] = translate($key,$child_focus->module_dir); |
| 2020 | 2092 | $this->list_field_defs[$i]['label'] = preg_replace('/:$/','',$list_field['label']); |
| 2021 | - } |
|
| 2022 | - else |
|
| 2093 | + } else |
|
| 2023 | 2094 | { |
| 2024 | 2095 | $this->list_field_defs[$i]['label'] =' '; |
| 2025 | 2096 | } |
@@ -2049,8 +2120,7 @@ discard block |
||
| 2049 | 2120 | function getLocalSessionVariable($localVarName,$varName) { |
| 2050 | 2121 | if(isset($_SESSION[$localVarName."_".$varName])) { |
| 2051 | 2122 | return $_SESSION[$localVarName."_".$varName]; |
| 2052 | - } |
|
| 2053 | - else{ |
|
| 2123 | + } else{ |
|
| 2054 | 2124 | return ""; |
| 2055 | 2125 | } |
| 2056 | 2126 | } |
@@ -2058,7 +2128,9 @@ discard block |
||
| 2058 | 2128 | /* Set to true if you want Additional Details to appear in the listview |
| 2059 | 2129 | */ |
| 2060 | 2130 | function setAdditionalDetails($value = true, $function = '') { |
| 2061 | - if(!empty($function)) $this->additionalDetailsFunction = $function; |
|
| 2131 | + if(!empty($function)) { |
|
| 2132 | + $this->additionalDetailsFunction = $function; |
|
| 2133 | + } |
|
| 2062 | 2134 | $this->_additionalDetails = $value; |
| 2063 | 2135 | } |
| 2064 | 2136 | |
@@ -105,6 +105,9 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
| 108 | +/** |
|
| 109 | + * @param string $xTemplateSection |
|
| 110 | + */ |
|
| 108 | 111 | function processListView($seed, $xTemplateSection, $html_varName) |
| 109 | 112 | { |
| 110 | 113 | global $sugar_config; |
@@ -232,8 +235,8 @@ discard block |
||
| 232 | 235 | /** |
| 233 | 236 | * @return void |
| 234 | 237 | * @param unknown $data |
| 235 | - * @param unknown $xTemplateSection |
|
| 236 | - * @param unknown $html_varName |
|
| 238 | + * @param string $xtemplateSection |
|
| 239 | + * @param string $html_varName |
|
| 237 | 240 | * @desc INTERNAL FUNCTION handles the rows |
| 238 | 241 | */ |
| 239 | 242 | function process_dynamic_listview_rows($data,$parent_data, $xtemplateSection, $html_varName, $subpanel_def) |
@@ -610,6 +613,9 @@ discard block |
||
| 610 | 613 | * All Rights Reserved. |
| 611 | 614 | * Contributor(s): ______________________________________. |
| 612 | 615 | */ |
| 616 | + /** |
|
| 617 | + * @param string $value |
|
| 618 | + */ |
|
| 613 | 619 | function setHeaderText($value) { |
| 614 | 620 | $this->header_text = $value; |
| 615 | 621 | } |
@@ -728,6 +734,9 @@ discard block |
||
| 728 | 734 | * All Rights Reserved. |
| 729 | 735 | * Contributor(s): ______________________________________. |
| 730 | 736 | */ |
| 737 | + /** |
|
| 738 | + * @param string $where |
|
| 739 | + */ |
|
| 731 | 740 | function setQuery($where, $limit, $orderBy, $varName, $allowOrderByOveride=true) { |
| 732 | 741 | $this->query_where = $where; |
| 733 | 742 | if($this->getSessionVariable("query", "where") != $where) { |
@@ -834,6 +843,9 @@ discard block |
||
| 834 | 843 | * All Rights Reserved. |
| 835 | 844 | * Contributor(s): ______________________________________. |
| 836 | 845 | */ |
| 846 | + /** |
|
| 847 | + * @param XTemplate $newXTemplate |
|
| 848 | + */ |
|
| 837 | 849 | function setXTemplate($newXTemplate) { |
| 838 | 850 | $this->xTemplate = $newXTemplate; |
| 839 | 851 | } |
@@ -852,6 +864,9 @@ discard block |
||
| 852 | 864 | * All Rights Reserved. |
| 853 | 865 | * Contributor(s): ______________________________________. |
| 854 | 866 | */ |
| 867 | + /** |
|
| 868 | + * @param string $name |
|
| 869 | + */ |
|
| 855 | 870 | function xTemplateAssign($name, $value) { |
| 856 | 871 | |
| 857 | 872 | if(!isset($this->xTemplate)) { |
@@ -906,6 +921,9 @@ discard block |
||
| 906 | 921 | * All Rights Reserved. |
| 907 | 922 | * Contributor(s): ______________________________________. |
| 908 | 923 | */ |
| 924 | + /** |
|
| 925 | + * @param string $varName |
|
| 926 | + */ |
|
| 909 | 927 | function getSessionVariable($localVarName,$varName) { |
| 910 | 928 | //Set any variables pass in through request first |
| 911 | 929 | if(isset($_REQUEST[$this->getSessionVariableName($localVarName, $varName)])) { |
@@ -961,7 +979,7 @@ discard block |
||
| 961 | 979 | |
| 962 | 980 | /** |
| 963 | 981 | |
| 964 | - * @return void |
|
| 982 | + * @return string |
|
| 965 | 983 | * @param unknown $localVarName |
| 966 | 984 | * @param unknown $varName |
| 967 | 985 | * @desc INTERNAL FUNCTION returns the session/query variable name |
@@ -977,7 +995,7 @@ discard block |
||
| 977 | 995 | |
| 978 | 996 | * @return void |
| 979 | 997 | * @param unknown $seed |
| 980 | - * @param unknown $xTemplateSection |
|
| 998 | + * @param unknown $xtemplateSection |
|
| 981 | 999 | * @param unknown $html_varName |
| 982 | 1000 | * @desc INTERNAL FUNCTION Handles List Views using seeds that extend SugarBean |
| 983 | 1001 | $XTemplateSection is the section in the XTemplate file that should be parsed usually main |
@@ -1169,8 +1187,7 @@ discard block |
||
| 1169 | 1187 | } |
| 1170 | 1188 | /** |
| 1171 | 1189 | * @return void |
| 1172 | - * @param unknown $data |
|
| 1173 | - * @param unknown $xTemplateSection |
|
| 1190 | + * @param unknown $xtemplateSection |
|
| 1174 | 1191 | * @param unknown $html_varName |
| 1175 | 1192 | * @desc INTERNAL FUNCTION process the List Navigation |
| 1176 | 1193 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -1550,7 +1567,7 @@ discard block |
||
| 1550 | 1567 | /** |
| 1551 | 1568 | * @return void |
| 1552 | 1569 | * @param unknown $data |
| 1553 | - * @param unknown $xTemplateSection |
|
| 1570 | + * @param unknown $xtemplateSection |
|
| 1554 | 1571 | * @param unknown $html_varName |
| 1555 | 1572 | * @desc INTERNAL FUNCTION handles the rows |
| 1556 | 1573 | * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. |
@@ -2036,6 +2053,10 @@ discard block |
||
| 2036 | 2053 | * All Rights Reserved. |
| 2037 | 2054 | * Contributor(s): ______________________________________. |
| 2038 | 2055 | */ |
| 2056 | + |
|
| 2057 | + /** |
|
| 2058 | + * @param string $varName |
|
| 2059 | + */ |
|
| 2039 | 2060 | function setLocalSessionVariable($localVarName,$varName, $value) { |
| 2040 | 2061 | $_SESSION[$localVarName."_".$varName] = $value; |
| 2041 | 2062 | } |
@@ -2046,6 +2067,12 @@ discard block |
||
| 2046 | 2067 | * All Rights Reserved. |
| 2047 | 2068 | * Contributor(s): ______________________________________. |
| 2048 | 2069 | */ |
| 2070 | + |
|
| 2071 | + /** |
|
| 2072 | + * @param string $varName |
|
| 2073 | + * |
|
| 2074 | + * @return string |
|
| 2075 | + */ |
|
| 2049 | 2076 | function getLocalSessionVariable($localVarName,$varName) { |
| 2050 | 2077 | if(isset($_SESSION[$localVarName."_".$varName])) { |
| 2051 | 2078 | return $_SESSION[$localVarName."_".$varName]; |
@@ -46,9 +46,9 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | class ListViewData { |
| 48 | 48 | |
| 49 | - var $additionalDetails = true; |
|
| 49 | + var $additionalDetails = true; |
|
| 50 | 50 | var $listviewName = null; |
| 51 | - var $additionalDetailsAllow = null; |
|
| 51 | + var $additionalDetailsAllow = null; |
|
| 52 | 52 | var $additionalDetailsAjax = true; // leave this true when using filter fields |
| 53 | 53 | var $additionalDetailsFieldToAdd = 'NAME'; // where the span will be attached to |
| 54 | 54 | var $base_url = null; |
@@ -58,82 +58,82 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | var $count_query = ''; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Constructor sets the limitName to look up the limit in $sugar_config |
|
| 63 | - * |
|
| 64 | - * @return ListViewData |
|
| 65 | - */ |
|
| 66 | - function ListViewData() { |
|
| 67 | - $this->limitName = 'list_max_entries_per_page'; |
|
| 68 | - $this->db = DBManagerFactory::getInstance('listviews'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * checks the request for the order by and if that is not set then it checks the session for it |
|
| 73 | - * |
|
| 74 | - * @return array containing the keys orderBy => field being ordered off of and sortOrder => the sort order of that field |
|
| 75 | - */ |
|
| 76 | - function getOrderBy($orderBy = '', $direction = '') { |
|
| 77 | - if (!empty($orderBy) || !empty($_REQUEST[$this->var_order_by])) { |
|
| 61 | + /** |
|
| 62 | + * Constructor sets the limitName to look up the limit in $sugar_config |
|
| 63 | + * |
|
| 64 | + * @return ListViewData |
|
| 65 | + */ |
|
| 66 | + function ListViewData() { |
|
| 67 | + $this->limitName = 'list_max_entries_per_page'; |
|
| 68 | + $this->db = DBManagerFactory::getInstance('listviews'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * checks the request for the order by and if that is not set then it checks the session for it |
|
| 73 | + * |
|
| 74 | + * @return array containing the keys orderBy => field being ordered off of and sortOrder => the sort order of that field |
|
| 75 | + */ |
|
| 76 | + function getOrderBy($orderBy = '', $direction = '') { |
|
| 77 | + if (!empty($orderBy) || !empty($_REQUEST[$this->var_order_by])) { |
|
| 78 | 78 | if(!empty($_REQUEST[$this->var_order_by])) { |
| 79 | - $direction = 'ASC'; |
|
| 80 | - $orderBy = $_REQUEST[$this->var_order_by]; |
|
| 81 | - if(!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0) ){ |
|
| 82 | - $direction = $_REQUEST['lvso']; |
|
| 83 | - } |
|
| 79 | + $direction = 'ASC'; |
|
| 80 | + $orderBy = $_REQUEST[$this->var_order_by]; |
|
| 81 | + if(!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0) ){ |
|
| 82 | + $direction = $_REQUEST['lvso']; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | $_SESSION[$this->var_order_by] = array('orderBy'=>$orderBy, 'direction'=> $direction); |
| 86 | 86 | $_SESSION['lvd']['last_ob'] = $orderBy; |
| 87 | 87 | } |
| 88 | - else { |
|
| 88 | + else { |
|
| 89 | 89 | $userPreferenceOrder = $GLOBALS['current_user']->getPreference('listviewOrder', $this->var_name); |
| 90 | - if(!empty($_SESSION[$this->var_order_by])) { |
|
| 91 | - $orderBy = $_SESSION[$this->var_order_by]['orderBy']; |
|
| 92 | - $direction = $_SESSION[$this->var_order_by]['direction']; |
|
| 90 | + if(!empty($_SESSION[$this->var_order_by])) { |
|
| 91 | + $orderBy = $_SESSION[$this->var_order_by]['orderBy']; |
|
| 92 | + $direction = $_SESSION[$this->var_order_by]['direction']; |
|
| 93 | 93 | } elseif (!empty($userPreferenceOrder)) { |
| 94 | 94 | $orderBy = $userPreferenceOrder['orderBy']; |
| 95 | 95 | $direction = $userPreferenceOrder['sortOrder']; |
| 96 | 96 | } else { |
| 97 | - $orderBy = 'date_entered'; |
|
| 98 | - $direction = 'DESC'; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - if(!empty($direction)) { |
|
| 102 | - if(strtolower($direction) == "desc") { |
|
| 103 | - $direction = 'DESC'; |
|
| 104 | - } else { |
|
| 105 | - $direction = 'ASC'; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - return array('orderBy' => $orderBy, 'sortOrder' => $direction); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * gets the reverse of the sort order for use on links to reverse a sort order from what is currently used |
|
| 113 | - * |
|
| 114 | - * @param STRING (ASC or DESC) $current_order |
|
| 115 | - * @return STRING (ASC or DESC) |
|
| 116 | - */ |
|
| 117 | - function getReverseSortOrder($current_order){ |
|
| 118 | - return (strcmp(strtolower($current_order), 'asc') == 0)?'DESC':'ASC'; |
|
| 119 | - } |
|
| 120 | - /** |
|
| 121 | - * gets the limit of how many rows to show per page |
|
| 122 | - * |
|
| 123 | - * @return INT (the limit) |
|
| 124 | - */ |
|
| 125 | - function getLimit() { |
|
| 126 | - return $GLOBALS['sugar_config'][$this->limitName]; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * returns the current offset |
|
| 131 | - * |
|
| 132 | - * @return INT (current offset) |
|
| 133 | - */ |
|
| 134 | - function getOffset() { |
|
| 135 | - return (!empty($_REQUEST[$this->var_offset])) ? $_REQUEST[$this->var_offset] : 0; |
|
| 136 | - } |
|
| 97 | + $orderBy = 'date_entered'; |
|
| 98 | + $direction = 'DESC'; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + if(!empty($direction)) { |
|
| 102 | + if(strtolower($direction) == "desc") { |
|
| 103 | + $direction = 'DESC'; |
|
| 104 | + } else { |
|
| 105 | + $direction = 'ASC'; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + return array('orderBy' => $orderBy, 'sortOrder' => $direction); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * gets the reverse of the sort order for use on links to reverse a sort order from what is currently used |
|
| 113 | + * |
|
| 114 | + * @param STRING (ASC or DESC) $current_order |
|
| 115 | + * @return STRING (ASC or DESC) |
|
| 116 | + */ |
|
| 117 | + function getReverseSortOrder($current_order){ |
|
| 118 | + return (strcmp(strtolower($current_order), 'asc') == 0)?'DESC':'ASC'; |
|
| 119 | + } |
|
| 120 | + /** |
|
| 121 | + * gets the limit of how many rows to show per page |
|
| 122 | + * |
|
| 123 | + * @return INT (the limit) |
|
| 124 | + */ |
|
| 125 | + function getLimit() { |
|
| 126 | + return $GLOBALS['sugar_config'][$this->limitName]; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * returns the current offset |
|
| 131 | + * |
|
| 132 | + * @return INT (current offset) |
|
| 133 | + */ |
|
| 134 | + function getOffset() { |
|
| 135 | + return (!empty($_REQUEST[$this->var_offset])) ? $_REQUEST[$this->var_offset] : 0; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | 139 | * generates the base url without |
@@ -159,18 +159,18 @@ discard block |
||
| 159 | 159 | return $params; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * based off of a base name it sets base, offset, and order by variable names to retrieve them from requests and sessions |
|
| 164 | - * |
|
| 165 | - * @param unknown_type $baseName |
|
| 166 | - */ |
|
| 167 | - function setVariableName($baseName, $where, $listviewName = null){ |
|
| 162 | + /** |
|
| 163 | + * based off of a base name it sets base, offset, and order by variable names to retrieve them from requests and sessions |
|
| 164 | + * |
|
| 165 | + * @param unknown_type $baseName |
|
| 166 | + */ |
|
| 167 | + function setVariableName($baseName, $where, $listviewName = null){ |
|
| 168 | 168 | global $timedate; |
| 169 | 169 | $module = (!empty($listviewName)) ? $listviewName: $_REQUEST['module']; |
| 170 | 170 | $this->var_name = $module .'2_'. strtoupper($baseName); |
| 171 | 171 | |
| 172 | - $this->var_order_by = $this->var_name .'_ORDER_BY'; |
|
| 173 | - $this->var_offset = $this->var_name . '_offset'; |
|
| 172 | + $this->var_order_by = $this->var_name .'_ORDER_BY'; |
|
| 173 | + $this->var_offset = $this->var_name . '_offset'; |
|
| 174 | 174 | $timestamp = sugar_microtime(); |
| 175 | 175 | $this->stamp = $timestamp; |
| 176 | 176 | |
@@ -178,58 +178,58 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | $_SESSION[strtoupper($baseName) . "_FROM_LIST_VIEW"] = $timestamp; |
| 180 | 180 | $_SESSION[strtoupper($baseName) . "_DETAIL_NAV_HISTORY"] = false; |
| 181 | - } |
|
| 182 | - |
|
| 183 | - function getTotalCount($main_query){ |
|
| 184 | - if(!empty($this->count_query)){ |
|
| 185 | - $count_query = $this->count_query; |
|
| 186 | - }else{ |
|
| 187 | - $count_query = $this->seed->create_list_count_query($main_query); |
|
| 188 | - } |
|
| 189 | - $result = $this->db->query($count_query); |
|
| 190 | - if($row = $this->db->fetchByAssoc($result)){ |
|
| 191 | - return $row['c']; |
|
| 192 | - } |
|
| 193 | - return 0; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * takes in a seed and creates the list view query based off of that seed |
|
| 198 | - * if the $limit value is set to -1 then it will use the default limit and offset values |
|
| 199 | - * |
|
| 200 | - * it will return an array with two key values |
|
| 201 | - * 1. 'data'=> this is an array of row data |
|
| 202 | - * 2. 'pageData'=> this is an array containg three values |
|
| 203 | - * a.'ordering'=> array('orderBy'=> the field being ordered by , 'sortOrder'=> 'ASC' or 'DESC') |
|
| 204 | - * b.'urls'=>array('baseURL'=>url used to generate other urls , |
|
| 205 | - * 'orderBy'=> the base url for order by |
|
| 206 | - * //the following may not be set (so check empty to see if they are set) |
|
| 207 | - * 'nextPage'=> the url for the next group of results, |
|
| 208 | - * 'prevPage'=> the url for the prev group of results, |
|
| 209 | - * 'startPage'=> the url for the start of the group, |
|
| 210 | - * 'endPage'=> the url for the last set of results in the group |
|
| 211 | - * c.'offsets'=>array( |
|
| 212 | - * 'current'=>current offset |
|
| 213 | - * 'next'=> next group offset |
|
| 214 | - * 'prev'=> prev group offset |
|
| 215 | - * 'end'=> the offset of the last group |
|
| 216 | - * 'total'=> the total count (only accurate if totalCounted = true otherwise it is either the total count if less than the limit or the total count + 1 ) |
|
| 217 | - * 'totalCounted'=> if a count query was used to get the total count |
|
| 218 | - * |
|
| 219 | - * @param SugarBean $seed |
|
| 220 | - * @param string $where |
|
| 221 | - * @param int:0 $offset |
|
| 222 | - * @param int:-1 $limit |
|
| 223 | - * @param string[]:array() $filter_fields |
|
| 224 | - * @param array:array() $params |
|
| 225 | - * Potential $params are |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + function getTotalCount($main_query){ |
|
| 184 | + if(!empty($this->count_query)){ |
|
| 185 | + $count_query = $this->count_query; |
|
| 186 | + }else{ |
|
| 187 | + $count_query = $this->seed->create_list_count_query($main_query); |
|
| 188 | + } |
|
| 189 | + $result = $this->db->query($count_query); |
|
| 190 | + if($row = $this->db->fetchByAssoc($result)){ |
|
| 191 | + return $row['c']; |
|
| 192 | + } |
|
| 193 | + return 0; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * takes in a seed and creates the list view query based off of that seed |
|
| 198 | + * if the $limit value is set to -1 then it will use the default limit and offset values |
|
| 199 | + * |
|
| 200 | + * it will return an array with two key values |
|
| 201 | + * 1. 'data'=> this is an array of row data |
|
| 202 | + * 2. 'pageData'=> this is an array containg three values |
|
| 203 | + * a.'ordering'=> array('orderBy'=> the field being ordered by , 'sortOrder'=> 'ASC' or 'DESC') |
|
| 204 | + * b.'urls'=>array('baseURL'=>url used to generate other urls , |
|
| 205 | + * 'orderBy'=> the base url for order by |
|
| 206 | + * //the following may not be set (so check empty to see if they are set) |
|
| 207 | + * 'nextPage'=> the url for the next group of results, |
|
| 208 | + * 'prevPage'=> the url for the prev group of results, |
|
| 209 | + * 'startPage'=> the url for the start of the group, |
|
| 210 | + * 'endPage'=> the url for the last set of results in the group |
|
| 211 | + * c.'offsets'=>array( |
|
| 212 | + * 'current'=>current offset |
|
| 213 | + * 'next'=> next group offset |
|
| 214 | + * 'prev'=> prev group offset |
|
| 215 | + * 'end'=> the offset of the last group |
|
| 216 | + * 'total'=> the total count (only accurate if totalCounted = true otherwise it is either the total count if less than the limit or the total count + 1 ) |
|
| 217 | + * 'totalCounted'=> if a count query was used to get the total count |
|
| 218 | + * |
|
| 219 | + * @param SugarBean $seed |
|
| 220 | + * @param string $where |
|
| 221 | + * @param int:0 $offset |
|
| 222 | + * @param int:-1 $limit |
|
| 223 | + * @param string[]:array() $filter_fields |
|
| 224 | + * @param array:array() $params |
|
| 225 | + * Potential $params are |
|
| 226 | 226 | $params['distinct'] = use distinct key word |
| 227 | 227 | $params['include_custom_fields'] = (on by default) |
| 228 | 228 | $params['custom_XXXX'] = append custom statements to query |
| 229 | - * @param string:'id' $id_field |
|
| 230 | - * @return array('data'=> row data, 'pageData' => page data information, 'query' => original query string) |
|
| 231 | - */ |
|
| 232 | - function getListViewData($seed, $where, $offset=-1, $limit = -1, $filter_fields=array(),$params=array(),$id_field = 'id',$singleSelect=true) { |
|
| 229 | + * @param string:'id' $id_field |
|
| 230 | + * @return array('data'=> row data, 'pageData' => page data information, 'query' => original query string) |
|
| 231 | + */ |
|
| 232 | + function getListViewData($seed, $where, $offset=-1, $limit = -1, $filter_fields=array(),$params=array(),$id_field = 'id',$singleSelect=true) { |
|
| 233 | 233 | global $current_user; |
| 234 | 234 | SugarVCR::erase($seed->module_dir); |
| 235 | 235 | $this->seed =& $seed; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | $this->setVariableName($seed->object_name, $where, $this->listviewName); |
| 243 | 243 | |
| 244 | - $this->seed->id = '[SELECT_ID_LIST]'; |
|
| 244 | + $this->seed->id = '[SELECT_ID_LIST]'; |
|
| 245 | 245 | |
| 246 | 246 | // if $params tell us to override all ordering |
| 247 | 247 | if(!empty($params['overrideOrder']) && !empty($params['orderBy'])) { |
@@ -265,11 +265,11 @@ discard block |
||
| 265 | 265 | $orderby = substr($order['orderBy'],strpos($order['orderBy'],'.')+1); |
| 266 | 266 | } |
| 267 | 267 | if ($orderby != 'date_entered' && !in_array($orderby, array_keys($filter_fields))) { |
| 268 | - $order['orderBy'] = ''; |
|
| 269 | - $order['sortOrder'] = ''; |
|
| 268 | + $order['orderBy'] = ''; |
|
| 269 | + $order['sortOrder'] = ''; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if (empty($order['orderBy'])) { |
|
| 272 | + if (empty($order['orderBy'])) { |
|
| 273 | 273 | $orderBy = ''; |
| 274 | 274 | } else { |
| 275 | 275 | $orderBy = $order['orderBy'] . ' ' . $order['sortOrder']; |
@@ -282,40 +282,40 @@ discard block |
||
| 282 | 282 | $current_user->setPreference('listviewOrder', $order, 0, $this->var_name); // save preference |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - // If $params tells us to override for the special last_name, first_name sorting |
|
| 286 | - if (!empty($params['overrideLastNameOrder']) && $order['orderBy'] == 'last_name') { |
|
| 287 | - $orderBy = 'last_name '.$order['sortOrder'].', first_name '.$order['sortOrder']; |
|
| 288 | - } |
|
| 285 | + // If $params tells us to override for the special last_name, first_name sorting |
|
| 286 | + if (!empty($params['overrideLastNameOrder']) && $order['orderBy'] == 'last_name') { |
|
| 287 | + $orderBy = 'last_name '.$order['sortOrder'].', first_name '.$order['sortOrder']; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - $ret_array = $seed->create_new_list_query($orderBy, $where, $filter_fields, $params, 0, '', true, $seed, $singleSelect); |
|
| 290 | + $ret_array = $seed->create_new_list_query($orderBy, $where, $filter_fields, $params, 0, '', true, $seed, $singleSelect); |
|
| 291 | 291 | $ret_array['inner_join'] = ''; |
| 292 | 292 | if (!empty($this->seed->listview_inner_join)) { |
| 293 | 293 | $ret_array['inner_join'] = ' ' . implode(' ', $this->seed->listview_inner_join) . ' '; |
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if(!is_array($params)) $params = array(); |
|
| 296 | + if(!is_array($params)) $params = array(); |
|
| 297 | 297 | if(!isset($params['custom_select'])) $params['custom_select'] = ''; |
| 298 | 298 | if(!isset($params['custom_from'])) $params['custom_from'] = ''; |
| 299 | 299 | if(!isset($params['custom_where'])) $params['custom_where'] = ''; |
| 300 | 300 | if(!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
| 301 | - $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
|
| 302 | - //C.L. - Fix for 23461 |
|
| 303 | - if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 304 | - $_SESSION['export_where'] = $ret_array['where']; |
|
| 305 | - } |
|
| 306 | - if($limit < -1) { |
|
| 307 | - $result = $this->db->query($main_query); |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - if($limit == -1) { |
|
| 311 | - $limit = $this->getLimit(); |
|
| 301 | + $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
|
| 302 | + //C.L. - Fix for 23461 |
|
| 303 | + if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 304 | + $_SESSION['export_where'] = $ret_array['where']; |
|
| 305 | + } |
|
| 306 | + if($limit < -1) { |
|
| 307 | + $result = $this->db->query($main_query); |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + if($limit == -1) { |
|
| 311 | + $limit = $this->getLimit(); |
|
| 312 | 312 | } |
| 313 | - $dyn_offset = $this->getOffset(); |
|
| 314 | - if($dyn_offset > 0 || !is_int($dyn_offset))$offset = $dyn_offset; |
|
| 313 | + $dyn_offset = $this->getOffset(); |
|
| 314 | + if($dyn_offset > 0 || !is_int($dyn_offset))$offset = $dyn_offset; |
|
| 315 | 315 | |
| 316 | 316 | if(strcmp($offset, 'end') == 0){ |
| 317 | - $totalCount = $this->getTotalCount($main_query); |
|
| 318 | - $offset = (floor(($totalCount -1) / $limit)) * $limit; |
|
| 317 | + $totalCount = $this->getTotalCount($main_query); |
|
| 318 | + $offset = (floor(($totalCount -1) / $limit)) * $limit; |
|
| 319 | 319 | } |
| 320 | 320 | if($this->seed->ACLAccess('ListView')) { |
| 321 | 321 | $result = $this->db->limitQuery($main_query, $offset, $limit + 1); |
@@ -324,27 +324,27 @@ discard block |
||
| 324 | 324 | $result = array(); |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - $data = array(); |
|
| 329 | + $data = array(); |
|
| 330 | 330 | |
| 331 | - $temp = clone $seed; |
|
| 331 | + $temp = clone $seed; |
|
| 332 | 332 | |
| 333 | - $rows = array(); |
|
| 334 | - $count = 0; |
|
| 333 | + $rows = array(); |
|
| 334 | + $count = 0; |
|
| 335 | 335 | $idIndex = array(); |
| 336 | 336 | $id_list = ''; |
| 337 | 337 | |
| 338 | - while(($row = $this->db->fetchByAssoc($result)) != null) |
|
| 338 | + while(($row = $this->db->fetchByAssoc($result)) != null) |
|
| 339 | 339 | { |
| 340 | - if($count < $limit) |
|
| 340 | + if($count < $limit) |
|
| 341 | 341 | { |
| 342 | - $id_list .= ',\''.$row[$id_field].'\''; |
|
| 343 | - $idIndex[$row[$id_field]][] = count($rows); |
|
| 344 | - $rows[] = $seed->convertRow($row); |
|
| 345 | - } |
|
| 346 | - $count++; |
|
| 347 | - } |
|
| 342 | + $id_list .= ',\''.$row[$id_field].'\''; |
|
| 343 | + $idIndex[$row[$id_field]][] = count($rows); |
|
| 344 | + $rows[] = $seed->convertRow($row); |
|
| 345 | + } |
|
| 346 | + $count++; |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | 349 | if (!empty($id_list)) |
| 350 | 350 | { |
@@ -352,10 +352,10 @@ discard block |
||
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | SugarVCR::store($this->seed->module_dir, $main_query); |
| 355 | - if($count != 0) { |
|
| 356 | - //NOW HANDLE SECONDARY QUERIES |
|
| 357 | - if(!empty($ret_array['secondary_select'])) { |
|
| 358 | - $secondary_query = $ret_array['secondary_select'] . $ret_array['secondary_from'] . ' WHERE '.$this->seed->table_name.'.id IN ' .$id_list; |
|
| 355 | + if($count != 0) { |
|
| 356 | + //NOW HANDLE SECONDARY QUERIES |
|
| 357 | + if(!empty($ret_array['secondary_select'])) { |
|
| 358 | + $secondary_query = $ret_array['secondary_select'] . $ret_array['secondary_from'] . ' WHERE '.$this->seed->table_name.'.id IN ' .$id_list; |
|
| 359 | 359 | if(isset($ret_array['order_by'])) |
| 360 | 360 | { |
| 361 | 361 | $secondary_query .= ' ' . $ret_array['order_by']; |
@@ -364,23 +364,23 @@ discard block |
||
| 364 | 364 | $secondary_result = $this->db->query($secondary_query); |
| 365 | 365 | |
| 366 | 366 | $ref_id_count = array(); |
| 367 | - while($row = $this->db->fetchByAssoc($secondary_result)) { |
|
| 367 | + while($row = $this->db->fetchByAssoc($secondary_result)) { |
|
| 368 | 368 | |
| 369 | 369 | $ref_id_count[$row['ref_id']][] = true; |
| 370 | - foreach($row as $name=>$value) { |
|
| 371 | - //add it to every row with the given id |
|
| 372 | - foreach($idIndex[$row['ref_id']] as $index){ |
|
| 373 | - $rows[$index][$name]=$value; |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - } |
|
| 370 | + foreach($row as $name=>$value) { |
|
| 371 | + //add it to every row with the given id |
|
| 372 | + foreach($idIndex[$row['ref_id']] as $index){ |
|
| 373 | + $rows[$index][$name]=$value; |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | $rows_keys = array_keys($rows); |
| 379 | 379 | foreach($rows_keys as $key) |
| 380 | 380 | { |
| 381 | 381 | $rows[$key]['secondary_select_count'] = count($ref_id_count[$rows[$key]['ref_id']]); |
| 382 | 382 | } |
| 383 | - } |
|
| 383 | + } |
|
| 384 | 384 | |
| 385 | 385 | // retrieve parent names |
| 386 | 386 | if(!empty($filter_fields['parent_name']) && !empty($filter_fields['parent_id']) && !empty($filter_fields['parent_type'])) { |
@@ -394,47 +394,47 @@ discard block |
||
| 394 | 394 | $parent_fields = $seed->retrieve_parent_fields($post_retrieve); |
| 395 | 395 | foreach($parent_fields as $child_id => $parent_data) { |
| 396 | 396 | //add it to every row with the given id |
| 397 | - foreach($idIndex[$child_id] as $index){ |
|
| 398 | - $rows[$index]['parent_name']= $parent_data['parent_name']; |
|
| 399 | - } |
|
| 397 | + foreach($idIndex[$child_id] as $index){ |
|
| 398 | + $rows[$index]['parent_name']= $parent_data['parent_name']; |
|
| 399 | + } |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - $pageData = array(); |
|
| 404 | + $pageData = array(); |
|
| 405 | 405 | |
| 406 | - reset($rows); |
|
| 407 | - while($row = current($rows)){ |
|
| 406 | + reset($rows); |
|
| 407 | + while($row = current($rows)){ |
|
| 408 | 408 | |
| 409 | 409 | $temp = clone $seed; |
| 410 | - $dataIndex = count($data); |
|
| 411 | - |
|
| 412 | - $temp->setupCustomFields($temp->module_dir); |
|
| 413 | - $temp->loadFromRow($row); |
|
| 414 | - if (empty($this->seed->assigned_user_id) && !empty($temp->assigned_user_id)) { |
|
| 415 | - $this->seed->assigned_user_id = $temp->assigned_user_id; |
|
| 416 | - } |
|
| 417 | - if($idIndex[$row[$id_field]][0] == $dataIndex){ |
|
| 418 | - $pageData['tag'][$dataIndex] = $temp->listviewACLHelper(); |
|
| 419 | - }else{ |
|
| 420 | - $pageData['tag'][$dataIndex] = $pageData['tag'][$idIndex[$row[$id_field]][0]]; |
|
| 421 | - } |
|
| 422 | - $data[$dataIndex] = $temp->get_list_view_data($filter_fields); |
|
| 410 | + $dataIndex = count($data); |
|
| 411 | + |
|
| 412 | + $temp->setupCustomFields($temp->module_dir); |
|
| 413 | + $temp->loadFromRow($row); |
|
| 414 | + if (empty($this->seed->assigned_user_id) && !empty($temp->assigned_user_id)) { |
|
| 415 | + $this->seed->assigned_user_id = $temp->assigned_user_id; |
|
| 416 | + } |
|
| 417 | + if($idIndex[$row[$id_field]][0] == $dataIndex){ |
|
| 418 | + $pageData['tag'][$dataIndex] = $temp->listviewACLHelper(); |
|
| 419 | + }else{ |
|
| 420 | + $pageData['tag'][$dataIndex] = $pageData['tag'][$idIndex[$row[$id_field]][0]]; |
|
| 421 | + } |
|
| 422 | + $data[$dataIndex] = $temp->get_list_view_data($filter_fields); |
|
| 423 | 423 | $detailViewAccess = $temp->ACLAccess('DetailView'); |
| 424 | 424 | $editViewAccess = $temp->ACLAccess('EditView'); |
| 425 | 425 | $pageData['rowAccess'][$dataIndex] = array('view' => $detailViewAccess, 'edit' => $editViewAccess); |
| 426 | 426 | $additionalDetailsAllow = $this->additionalDetails && $detailViewAccess && (file_exists( |
| 427 | - 'modules/' . $temp->module_dir . '/metadata/additionalDetails.php' |
|
| 428 | - ) || file_exists('custom/modules/' . $temp->module_dir . '/metadata/additionalDetails.php')); |
|
| 427 | + 'modules/' . $temp->module_dir . '/metadata/additionalDetails.php' |
|
| 428 | + ) || file_exists('custom/modules/' . $temp->module_dir . '/metadata/additionalDetails.php')); |
|
| 429 | 429 | $additionalDetailsEdit = $editViewAccess; |
| 430 | 430 | if($additionalDetailsAllow) { |
| 431 | 431 | if($this->additionalDetailsAjax) { |
| 432 | - $ar = $this->getAdditionalDetailsAjax($data[$dataIndex]['ID']); |
|
| 432 | + $ar = $this->getAdditionalDetailsAjax($data[$dataIndex]['ID']); |
|
| 433 | 433 | } |
| 434 | 434 | else { |
| 435 | 435 | $additionalDetailsFile = 'modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
| 436 | 436 | if(file_exists('custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php')){ |
| 437 | - $additionalDetailsFile = 'custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
|
| 437 | + $additionalDetailsFile = 'custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
|
| 438 | 438 | } |
| 439 | 439 | require_once($additionalDetailsFile); |
| 440 | 440 | $ar = $this->getAdditionalDetails($data[$dataIndex], |
@@ -443,42 +443,42 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | $pageData['additionalDetails'][$dataIndex] = $ar['string']; |
| 445 | 445 | $pageData['additionalDetails']['fieldToAddTo'] = $ar['fieldToAddTo']; |
| 446 | - } |
|
| 447 | - next($rows); |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - $nextOffset = -1; |
|
| 451 | - $prevOffset = -1; |
|
| 452 | - $endOffset = -1; |
|
| 453 | - if($count > $limit) { |
|
| 454 | - $nextOffset = $offset + $limit; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if($offset > 0) { |
|
| 458 | - $prevOffset = $offset - $limit; |
|
| 459 | - if($prevOffset < 0)$prevOffset = 0; |
|
| 460 | - } |
|
| 461 | - $totalCount = $count + $offset; |
|
| 462 | - |
|
| 463 | - if( $count >= $limit && $totalCounted){ |
|
| 464 | - $totalCount = $this->getTotalCount($main_query); |
|
| 465 | - } |
|
| 466 | - SugarVCR::recordIDs($this->seed->module_dir, array_keys($idIndex), $offset, $totalCount); |
|
| 446 | + } |
|
| 447 | + next($rows); |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + $nextOffset = -1; |
|
| 451 | + $prevOffset = -1; |
|
| 452 | + $endOffset = -1; |
|
| 453 | + if($count > $limit) { |
|
| 454 | + $nextOffset = $offset + $limit; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if($offset > 0) { |
|
| 458 | + $prevOffset = $offset - $limit; |
|
| 459 | + if($prevOffset < 0)$prevOffset = 0; |
|
| 460 | + } |
|
| 461 | + $totalCount = $count + $offset; |
|
| 462 | + |
|
| 463 | + if( $count >= $limit && $totalCounted){ |
|
| 464 | + $totalCount = $this->getTotalCount($main_query); |
|
| 465 | + } |
|
| 466 | + SugarVCR::recordIDs($this->seed->module_dir, array_keys($idIndex), $offset, $totalCount); |
|
| 467 | 467 | $module_names = array( |
| 468 | 468 | 'Prospects' => 'Targets' |
| 469 | 469 | ); |
| 470 | - $endOffset = (floor(($totalCount - 1) / $limit)) * $limit; |
|
| 471 | - $pageData['ordering'] = $order; |
|
| 472 | - $pageData['ordering']['sortOrder'] = $this->getReverseSortOrder($pageData['ordering']['sortOrder']); |
|
| 470 | + $endOffset = (floor(($totalCount - 1) / $limit)) * $limit; |
|
| 471 | + $pageData['ordering'] = $order; |
|
| 472 | + $pageData['ordering']['sortOrder'] = $this->getReverseSortOrder($pageData['ordering']['sortOrder']); |
|
| 473 | 473 | //get url parameters as an array |
| 474 | 474 | $pageData['queries'] = $this->generateQueries($pageData['ordering']['sortOrder'], $offset, $prevOffset, $nextOffset, $endOffset, $totalCounted); |
| 475 | 475 | //join url parameters from array to a string |
| 476 | 476 | $pageData['urls'] = $this->generateURLS($pageData['queries']); |
| 477 | - $pageData['offsets'] = array( 'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted); |
|
| 478 | - $pageData['bean'] = array('objectName' => $seed->object_name, 'moduleDir' => $seed->module_dir, 'moduleName' => strtr($seed->module_dir, $module_names)); |
|
| 477 | + $pageData['offsets'] = array( 'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted); |
|
| 478 | + $pageData['bean'] = array('objectName' => $seed->object_name, 'moduleDir' => $seed->module_dir, 'moduleName' => strtr($seed->module_dir, $module_names)); |
|
| 479 | 479 | $pageData['stamp'] = $this->stamp; |
| 480 | 480 | $pageData['access'] = array('view' => $this->seed->ACLAccess('DetailView'), 'edit' => $this->seed->ACLAccess('EditView')); |
| 481 | - $pageData['idIndex'] = $idIndex; |
|
| 481 | + $pageData['idIndex'] = $idIndex; |
|
| 482 | 482 | if(!$this->seed->ACLAccess('ListView')) { |
| 483 | 483 | $pageData['error'] = 'ACL restricted access'; |
| 484 | 484 | } |
@@ -486,8 +486,8 @@ discard block |
||
| 486 | 486 | $queryString = ''; |
| 487 | 487 | |
| 488 | 488 | if( isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "advanced_search" || |
| 489 | - isset($_REQUEST["type_basic"]) && (count($_REQUEST["type_basic"] > 1) || $_REQUEST["type_basic"][0] != "") || |
|
| 490 | - isset($_REQUEST["module"]) && $_REQUEST["module"] == "MergeRecords") |
|
| 489 | + isset($_REQUEST["type_basic"]) && (count($_REQUEST["type_basic"] > 1) || $_REQUEST["type_basic"][0] != "") || |
|
| 490 | + isset($_REQUEST["module"]) && $_REQUEST["module"] == "MergeRecords") |
|
| 491 | 491 | { |
| 492 | 492 | $queryString = "-advanced_search"; |
| 493 | 493 | } |
@@ -514,8 +514,8 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - return array('data'=>$data , 'pageData'=>$pageData, 'query' => $queryString); |
|
| 518 | - } |
|
| 517 | + return array('data'=>$data , 'pageData'=>$pageData, 'query' => $queryString); |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | 520 | |
| 521 | 521 | /** |
@@ -582,13 +582,13 @@ discard block |
||
| 582 | 582 | return $queries; |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - /** |
|
| 586 | - * generates the additional details span to be retrieved via ajax |
|
| 587 | - * |
|
| 588 | - * @param GUID id id of the record |
|
| 589 | - * @return array string to attach to field |
|
| 590 | - */ |
|
| 591 | - function getAdditionalDetailsAjax($id) |
|
| 585 | + /** |
|
| 586 | + * generates the additional details span to be retrieved via ajax |
|
| 587 | + * |
|
| 588 | + * @param GUID id id of the record |
|
| 589 | + * @return array string to attach to field |
|
| 590 | + */ |
|
| 591 | + function getAdditionalDetailsAjax($id) |
|
| 592 | 592 | { |
| 593 | 593 | global $app_strings; |
| 594 | 594 | |
@@ -596,10 +596,10 @@ discard block |
||
| 596 | 596 | |
| 597 | 597 | $extra = "<span id='adspan_" . $id . "' " |
| 598 | 598 | . "onclick=\"lvg_dtails('$id')\" " |
| 599 | - . " style='position: relative;'><!--not_in_theme!--><img vertical-align='middle' class='info' border='0' alt='".$app_strings['LBL_ADDITIONAL_DETAILS']."' src='$jscalendarImage'></span>"; |
|
| 599 | + . " style='position: relative;'><!--not_in_theme!--><img vertical-align='middle' class='info' border='0' alt='".$app_strings['LBL_ADDITIONAL_DETAILS']."' src='$jscalendarImage'></span>"; |
|
| 600 | 600 | |
| 601 | 601 | return array('fieldToAddTo' => $this->additionalDetailsFieldToAdd, 'string' => $extra); |
| 602 | - } |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | 604 | /** |
| 605 | 605 | * generates the additional details values |
@@ -622,25 +622,25 @@ discard block |
||
| 622 | 622 | { |
| 623 | 623 | $results['string'] = $app_strings['LBL_NONE']; |
| 624 | 624 | } |
| 625 | - $close = false; |
|
| 625 | + $close = false; |
|
| 626 | 626 | $extra = "<img alt='{$app_strings['LBL_INFOINLINE']}' style='padding: 0px 5px 0px 2px' border='0' onclick=\"SUGAR.util.getStaticAdditionalDetails(this,'"; |
| 627 | 627 | |
| 628 | 628 | $extra .= str_replace(array("\rn", "\r", "\n"), array('','','<br />'), $results['string']) ; |
| 629 | 629 | $extra .= "','<div style=\'float:left\'>{$app_strings['LBL_ADDITIONAL_DETAILS']}</div><div style=\'float: right\'>"; |
| 630 | 630 | |
| 631 | - if($editAccess && !empty($results['editLink'])) |
|
| 632 | - { |
|
| 633 | - $extra .= "<a title=\'{$app_strings['LBL_EDIT_BUTTON']}\' href={$results['editLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('edit_inline.png')."\'></a>"; |
|
| 634 | - $close = true; |
|
| 635 | - } |
|
| 636 | - $close = (!empty($results['viewLink'])) ? true : $close; |
|
| 637 | - $extra .= (!empty($results['viewLink']) ? "<a title=\'{$app_strings['LBL_VIEW_BUTTON']}\' href={$results['viewLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=".SugarThemeRegistry::current()->getImageURL('view_inline.png')."></a>" : ''); |
|
| 631 | + if($editAccess && !empty($results['editLink'])) |
|
| 632 | + { |
|
| 633 | + $extra .= "<a title=\'{$app_strings['LBL_EDIT_BUTTON']}\' href={$results['editLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('edit_inline.png')."\'></a>"; |
|
| 634 | + $close = true; |
|
| 635 | + } |
|
| 636 | + $close = (!empty($results['viewLink'])) ? true : $close; |
|
| 637 | + $extra .= (!empty($results['viewLink']) ? "<a title=\'{$app_strings['LBL_VIEW_BUTTON']}\' href={$results['viewLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=".SugarThemeRegistry::current()->getImageURL('view_inline.png')."></a>" : ''); |
|
| 638 | 638 | |
| 639 | 639 | if($close == true) { |
| 640 | - $closeVal = "true"; |
|
| 641 | - $extra .= "<a title=\'{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}\' href=\'javascript: SUGAR.util.closeStaticAdditionalDetails();\'><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('close.png')."\'></a>"; |
|
| 640 | + $closeVal = "true"; |
|
| 641 | + $extra .= "<a title=\'{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}\' href=\'javascript: SUGAR.util.closeStaticAdditionalDetails();\'><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('close.png')."\'></a>"; |
|
| 642 | 642 | } else { |
| 643 | - $closeVal = "false"; |
|
| 643 | + $closeVal = "false"; |
|
| 644 | 644 | } |
| 645 | 645 | $extra .= "',".$closeVal.")\" src='".SugarThemeRegistry::current()->getImageURL('info_inline.png')."' class='info'>"; |
| 646 | 646 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -75,10 +75,10 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | function getOrderBy($orderBy = '', $direction = '') { |
| 77 | 77 | if (!empty($orderBy) || !empty($_REQUEST[$this->var_order_by])) { |
| 78 | - if(!empty($_REQUEST[$this->var_order_by])) { |
|
| 78 | + if (!empty($_REQUEST[$this->var_order_by])) { |
|
| 79 | 79 | $direction = 'ASC'; |
| 80 | 80 | $orderBy = $_REQUEST[$this->var_order_by]; |
| 81 | - if(!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0) ){ |
|
| 81 | + if (!empty($_REQUEST['lvso']) && (empty($_SESSION['lvd']['last_ob']) || strcmp($orderBy, $_SESSION['lvd']['last_ob']) == 0)) { |
|
| 82 | 82 | $direction = $_REQUEST['lvso']; |
| 83 | 83 | } |
| 84 | 84 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | else { |
| 89 | 89 | $userPreferenceOrder = $GLOBALS['current_user']->getPreference('listviewOrder', $this->var_name); |
| 90 | - if(!empty($_SESSION[$this->var_order_by])) { |
|
| 90 | + if (!empty($_SESSION[$this->var_order_by])) { |
|
| 91 | 91 | $orderBy = $_SESSION[$this->var_order_by]['orderBy']; |
| 92 | 92 | $direction = $_SESSION[$this->var_order_by]['direction']; |
| 93 | 93 | } elseif (!empty($userPreferenceOrder)) { |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | $direction = 'DESC'; |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | - if(!empty($direction)) { |
|
| 102 | - if(strtolower($direction) == "desc") { |
|
| 101 | + if (!empty($direction)) { |
|
| 102 | + if (strtolower($direction) == "desc") { |
|
| 103 | 103 | $direction = 'DESC'; |
| 104 | 104 | } else { |
| 105 | 105 | $direction = 'ASC'; |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | * @param STRING (ASC or DESC) $current_order |
| 115 | 115 | * @return STRING (ASC or DESC) |
| 116 | 116 | */ |
| 117 | - function getReverseSortOrder($current_order){ |
|
| 118 | - return (strcmp(strtolower($current_order), 'asc') == 0)?'DESC':'ASC'; |
|
| 117 | + function getReverseSortOrder($current_order) { |
|
| 118 | + return (strcmp(strtolower($current_order), 'asc') == 0) ? 'DESC' : 'ASC'; |
|
| 119 | 119 | } |
| 120 | 120 | /** |
| 121 | 121 | * gets the limit of how many rows to show per page |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | { |
| 146 | 146 | global $beanList; |
| 147 | 147 | |
| 148 | - $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount',$this->var_order_by, $this->var_offset, 'lvso', 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page'); |
|
| 149 | - foreach($beanList as $bean) |
|
| 148 | + $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', $this->var_order_by, $this->var_offset, 'lvso', 'sortOrder', 'orderBy', 'request_data', 'current_query_by_page'); |
|
| 149 | + foreach ($beanList as $bean) |
|
| 150 | 150 | { |
| 151 | 151 | $blockVariables[] = 'Home2_'.strtoupper($bean).'_ORDER_BY'; |
| 152 | 152 | } |
@@ -164,30 +164,30 @@ discard block |
||
| 164 | 164 | * |
| 165 | 165 | * @param unknown_type $baseName |
| 166 | 166 | */ |
| 167 | - function setVariableName($baseName, $where, $listviewName = null){ |
|
| 167 | + function setVariableName($baseName, $where, $listviewName = null) { |
|
| 168 | 168 | global $timedate; |
| 169 | - $module = (!empty($listviewName)) ? $listviewName: $_REQUEST['module']; |
|
| 170 | - $this->var_name = $module .'2_'. strtoupper($baseName); |
|
| 169 | + $module = (!empty($listviewName)) ? $listviewName : $_REQUEST['module']; |
|
| 170 | + $this->var_name = $module.'2_'.strtoupper($baseName); |
|
| 171 | 171 | |
| 172 | - $this->var_order_by = $this->var_name .'_ORDER_BY'; |
|
| 173 | - $this->var_offset = $this->var_name . '_offset'; |
|
| 172 | + $this->var_order_by = $this->var_name.'_ORDER_BY'; |
|
| 173 | + $this->var_offset = $this->var_name.'_offset'; |
|
| 174 | 174 | $timestamp = sugar_microtime(); |
| 175 | 175 | $this->stamp = $timestamp; |
| 176 | 176 | |
| 177 | - $_SESSION[$module .'2_QUERY_QUERY'] = $where; |
|
| 177 | + $_SESSION[$module.'2_QUERY_QUERY'] = $where; |
|
| 178 | 178 | |
| 179 | - $_SESSION[strtoupper($baseName) . "_FROM_LIST_VIEW"] = $timestamp; |
|
| 180 | - $_SESSION[strtoupper($baseName) . "_DETAIL_NAV_HISTORY"] = false; |
|
| 179 | + $_SESSION[strtoupper($baseName)."_FROM_LIST_VIEW"] = $timestamp; |
|
| 180 | + $_SESSION[strtoupper($baseName)."_DETAIL_NAV_HISTORY"] = false; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - function getTotalCount($main_query){ |
|
| 184 | - if(!empty($this->count_query)){ |
|
| 183 | + function getTotalCount($main_query) { |
|
| 184 | + if (!empty($this->count_query)) { |
|
| 185 | 185 | $count_query = $this->count_query; |
| 186 | - }else{ |
|
| 186 | + } else { |
|
| 187 | 187 | $count_query = $this->seed->create_list_count_query($main_query); |
| 188 | 188 | } |
| 189 | 189 | $result = $this->db->query($count_query); |
| 190 | - if($row = $this->db->fetchByAssoc($result)){ |
|
| 190 | + if ($row = $this->db->fetchByAssoc($result)) { |
|
| 191 | 191 | return $row['c']; |
| 192 | 192 | } |
| 193 | 193 | return 0; |
@@ -229,13 +229,13 @@ discard block |
||
| 229 | 229 | * @param string:'id' $id_field |
| 230 | 230 | * @return array('data'=> row data, 'pageData' => page data information, 'query' => original query string) |
| 231 | 231 | */ |
| 232 | - function getListViewData($seed, $where, $offset=-1, $limit = -1, $filter_fields=array(),$params=array(),$id_field = 'id',$singleSelect=true) { |
|
| 232 | + function getListViewData($seed, $where, $offset = -1, $limit = -1, $filter_fields = array(), $params = array(), $id_field = 'id', $singleSelect = true) { |
|
| 233 | 233 | global $current_user; |
| 234 | 234 | SugarVCR::erase($seed->module_dir); |
| 235 | - $this->seed =& $seed; |
|
| 235 | + $this->seed = & $seed; |
|
| 236 | 236 | $totalCounted = empty($GLOBALS['sugar_config']['disable_count_query']); |
| 237 | 237 | $_SESSION['MAILMERGE_MODULE_FROM_LISTVIEW'] = $seed->module_dir; |
| 238 | - if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup'){ |
|
| 238 | + if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 239 | 239 | $_SESSION['MAILMERGE_MODULE'] = $seed->module_dir; |
| 240 | 240 | } |
| 241 | 241 | |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | $this->seed->id = '[SELECT_ID_LIST]'; |
| 245 | 245 | |
| 246 | 246 | // if $params tell us to override all ordering |
| 247 | - if(!empty($params['overrideOrder']) && !empty($params['orderBy'])) { |
|
| 247 | + if (!empty($params['overrideOrder']) && !empty($params['orderBy'])) { |
|
| 248 | 248 | $order = $this->getOrderBy(strtolower($params['orderBy']), (empty($params['sortOrder']) ? '' : $params['sortOrder'])); // retreive from $_REQUEST |
| 249 | 249 | } |
| 250 | 250 | else { |
@@ -252,17 +252,17 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // still empty? try to use settings passed in $param |
| 255 | - if(empty($order['orderBy']) && !empty($params['orderBy'])) { |
|
| 255 | + if (empty($order['orderBy']) && !empty($params['orderBy'])) { |
|
| 256 | 256 | $order['orderBy'] = $params['orderBy']; |
| 257 | - $order['sortOrder'] = (empty($params['sortOrder']) ? '' : $params['sortOrder']); |
|
| 257 | + $order['sortOrder'] = (empty($params['sortOrder']) ? '' : $params['sortOrder']); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | //rrs - bug: 21788. Do not use Order by stmts with fields that are not in the query. |
| 261 | 261 | // Bug 22740 - Tweak this check to strip off the table name off the order by parameter. |
| 262 | 262 | // Samir Gandhi : Do not remove the report_cache.date_modified condition as the report list view is broken |
| 263 | 263 | $orderby = $order['orderBy']; |
| 264 | - if (strpos($order['orderBy'],'.') && ($order['orderBy'] != "report_cache.date_modified")) { |
|
| 265 | - $orderby = substr($order['orderBy'],strpos($order['orderBy'],'.')+1); |
|
| 264 | + if (strpos($order['orderBy'], '.') && ($order['orderBy'] != "report_cache.date_modified")) { |
|
| 265 | + $orderby = substr($order['orderBy'], strpos($order['orderBy'], '.') + 1); |
|
| 266 | 266 | } |
| 267 | 267 | if ($orderby != 'date_entered' && !in_array($orderby, array_keys($filter_fields))) { |
| 268 | 268 | $order['orderBy'] = ''; |
@@ -272,10 +272,10 @@ discard block |
||
| 272 | 272 | if (empty($order['orderBy'])) { |
| 273 | 273 | $orderBy = ''; |
| 274 | 274 | } else { |
| 275 | - $orderBy = $order['orderBy'] . ' ' . $order['sortOrder']; |
|
| 275 | + $orderBy = $order['orderBy'].' '.$order['sortOrder']; |
|
| 276 | 276 | //wdong, Bug 25476, fix the sorting problem of Oracle. |
| 277 | 277 | if (isset($params['custom_order_by_override']['ori_code']) && $order['orderBy'] == $params['custom_order_by_override']['ori_code']) |
| 278 | - $orderBy = $params['custom_order_by_override']['custom_code'] . ' ' . $order['sortOrder']; |
|
| 278 | + $orderBy = $params['custom_order_by_override']['custom_code'].' '.$order['sortOrder']; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | if (empty($params['skipOrderSave'])) { // don't save preferences if told so |
@@ -290,34 +290,34 @@ discard block |
||
| 290 | 290 | $ret_array = $seed->create_new_list_query($orderBy, $where, $filter_fields, $params, 0, '', true, $seed, $singleSelect); |
| 291 | 291 | $ret_array['inner_join'] = ''; |
| 292 | 292 | if (!empty($this->seed->listview_inner_join)) { |
| 293 | - $ret_array['inner_join'] = ' ' . implode(' ', $this->seed->listview_inner_join) . ' '; |
|
| 293 | + $ret_array['inner_join'] = ' '.implode(' ', $this->seed->listview_inner_join).' '; |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - if(!is_array($params)) $params = array(); |
|
| 297 | - if(!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
| 298 | - if(!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
| 299 | - if(!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
| 300 | - if(!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
| 301 | - $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
|
| 296 | + if (!is_array($params)) $params = array(); |
|
| 297 | + if (!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
| 298 | + if (!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
| 299 | + if (!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
| 300 | + if (!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
| 301 | + $main_query = $ret_array['select'].$params['custom_select'].$ret_array['from'].$params['custom_from'].$ret_array['inner_join'].$ret_array['where'].$params['custom_where'].$ret_array['order_by'].$params['custom_order_by']; |
|
| 302 | 302 | //C.L. - Fix for 23461 |
| 303 | - if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 303 | + if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
|
| 304 | 304 | $_SESSION['export_where'] = $ret_array['where']; |
| 305 | 305 | } |
| 306 | - if($limit < -1) { |
|
| 306 | + if ($limit < -1) { |
|
| 307 | 307 | $result = $this->db->query($main_query); |
| 308 | 308 | } |
| 309 | 309 | else { |
| 310 | - if($limit == -1) { |
|
| 310 | + if ($limit == -1) { |
|
| 311 | 311 | $limit = $this->getLimit(); |
| 312 | 312 | } |
| 313 | 313 | $dyn_offset = $this->getOffset(); |
| 314 | - if($dyn_offset > 0 || !is_int($dyn_offset))$offset = $dyn_offset; |
|
| 314 | + if ($dyn_offset > 0 || !is_int($dyn_offset))$offset = $dyn_offset; |
|
| 315 | 315 | |
| 316 | - if(strcmp($offset, 'end') == 0){ |
|
| 316 | + if (strcmp($offset, 'end') == 0) { |
|
| 317 | 317 | $totalCount = $this->getTotalCount($main_query); |
| 318 | - $offset = (floor(($totalCount -1) / $limit)) * $limit; |
|
| 318 | + $offset = (floor(($totalCount - 1) / $limit)) * $limit; |
|
| 319 | 319 | } |
| 320 | - if($this->seed->ACLAccess('ListView')) { |
|
| 320 | + if ($this->seed->ACLAccess('ListView')) { |
|
| 321 | 321 | $result = $this->db->limitQuery($main_query, $offset, $limit + 1); |
| 322 | 322 | } |
| 323 | 323 | else { |
@@ -335,9 +335,9 @@ discard block |
||
| 335 | 335 | $idIndex = array(); |
| 336 | 336 | $id_list = ''; |
| 337 | 337 | |
| 338 | - while(($row = $this->db->fetchByAssoc($result)) != null) |
|
| 338 | + while (($row = $this->db->fetchByAssoc($result)) != null) |
|
| 339 | 339 | { |
| 340 | - if($count < $limit) |
|
| 340 | + if ($count < $limit) |
|
| 341 | 341 | { |
| 342 | 342 | $id_list .= ',\''.$row[$id_field].'\''; |
| 343 | 343 | $idIndex[$row[$id_field]][] = count($rows); |
@@ -351,51 +351,51 @@ discard block |
||
| 351 | 351 | $id_list = '('.substr($id_list, 1).')'; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - SugarVCR::store($this->seed->module_dir, $main_query); |
|
| 355 | - if($count != 0) { |
|
| 354 | + SugarVCR::store($this->seed->module_dir, $main_query); |
|
| 355 | + if ($count != 0) { |
|
| 356 | 356 | //NOW HANDLE SECONDARY QUERIES |
| 357 | - if(!empty($ret_array['secondary_select'])) { |
|
| 358 | - $secondary_query = $ret_array['secondary_select'] . $ret_array['secondary_from'] . ' WHERE '.$this->seed->table_name.'.id IN ' .$id_list; |
|
| 359 | - if(isset($ret_array['order_by'])) |
|
| 357 | + if (!empty($ret_array['secondary_select'])) { |
|
| 358 | + $secondary_query = $ret_array['secondary_select'].$ret_array['secondary_from'].' WHERE '.$this->seed->table_name.'.id IN '.$id_list; |
|
| 359 | + if (isset($ret_array['order_by'])) |
|
| 360 | 360 | { |
| 361 | - $secondary_query .= ' ' . $ret_array['order_by']; |
|
| 361 | + $secondary_query .= ' '.$ret_array['order_by']; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | $secondary_result = $this->db->query($secondary_query); |
| 365 | 365 | |
| 366 | 366 | $ref_id_count = array(); |
| 367 | - while($row = $this->db->fetchByAssoc($secondary_result)) { |
|
| 367 | + while ($row = $this->db->fetchByAssoc($secondary_result)) { |
|
| 368 | 368 | |
| 369 | 369 | $ref_id_count[$row['ref_id']][] = true; |
| 370 | - foreach($row as $name=>$value) { |
|
| 370 | + foreach ($row as $name=>$value) { |
|
| 371 | 371 | //add it to every row with the given id |
| 372 | - foreach($idIndex[$row['ref_id']] as $index){ |
|
| 373 | - $rows[$index][$name]=$value; |
|
| 372 | + foreach ($idIndex[$row['ref_id']] as $index) { |
|
| 373 | + $rows[$index][$name] = $value; |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | $rows_keys = array_keys($rows); |
| 379 | - foreach($rows_keys as $key) |
|
| 379 | + foreach ($rows_keys as $key) |
|
| 380 | 380 | { |
| 381 | 381 | $rows[$key]['secondary_select_count'] = count($ref_id_count[$rows[$key]['ref_id']]); |
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | // retrieve parent names |
| 386 | - if(!empty($filter_fields['parent_name']) && !empty($filter_fields['parent_id']) && !empty($filter_fields['parent_type'])) { |
|
| 387 | - foreach($idIndex as $id => $rowIndex) { |
|
| 388 | - if(!isset($post_retrieve[$rows[$rowIndex[0]]['parent_type']])) { |
|
| 386 | + if (!empty($filter_fields['parent_name']) && !empty($filter_fields['parent_id']) && !empty($filter_fields['parent_type'])) { |
|
| 387 | + foreach ($idIndex as $id => $rowIndex) { |
|
| 388 | + if (!isset($post_retrieve[$rows[$rowIndex[0]]['parent_type']])) { |
|
| 389 | 389 | $post_retrieve[$rows[$rowIndex[0]]['parent_type']] = array(); |
| 390 | 390 | } |
| 391 | - if(!empty($rows[$rowIndex[0]]['parent_id'])) $post_retrieve[$rows[$rowIndex[0]]['parent_type']][] = array('child_id' => $id , 'parent_id'=> $rows[$rowIndex[0]]['parent_id'], 'parent_type' => $rows[$rowIndex[0]]['parent_type'], 'type' => 'parent'); |
|
| 391 | + if (!empty($rows[$rowIndex[0]]['parent_id'])) $post_retrieve[$rows[$rowIndex[0]]['parent_type']][] = array('child_id' => $id, 'parent_id'=> $rows[$rowIndex[0]]['parent_id'], 'parent_type' => $rows[$rowIndex[0]]['parent_type'], 'type' => 'parent'); |
|
| 392 | 392 | } |
| 393 | - if(isset($post_retrieve)) { |
|
| 393 | + if (isset($post_retrieve)) { |
|
| 394 | 394 | $parent_fields = $seed->retrieve_parent_fields($post_retrieve); |
| 395 | - foreach($parent_fields as $child_id => $parent_data) { |
|
| 395 | + foreach ($parent_fields as $child_id => $parent_data) { |
|
| 396 | 396 | //add it to every row with the given id |
| 397 | - foreach($idIndex[$child_id] as $index){ |
|
| 398 | - $rows[$index]['parent_name']= $parent_data['parent_name']; |
|
| 397 | + foreach ($idIndex[$child_id] as $index) { |
|
| 398 | + $rows[$index]['parent_name'] = $parent_data['parent_name']; |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | } |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $pageData = array(); |
| 405 | 405 | |
| 406 | 406 | reset($rows); |
| 407 | - while($row = current($rows)){ |
|
| 407 | + while ($row = current($rows)) { |
|
| 408 | 408 | |
| 409 | 409 | $temp = clone $seed; |
| 410 | 410 | $dataIndex = count($data); |
@@ -414,9 +414,9 @@ discard block |
||
| 414 | 414 | if (empty($this->seed->assigned_user_id) && !empty($temp->assigned_user_id)) { |
| 415 | 415 | $this->seed->assigned_user_id = $temp->assigned_user_id; |
| 416 | 416 | } |
| 417 | - if($idIndex[$row[$id_field]][0] == $dataIndex){ |
|
| 417 | + if ($idIndex[$row[$id_field]][0] == $dataIndex) { |
|
| 418 | 418 | $pageData['tag'][$dataIndex] = $temp->listviewACLHelper(); |
| 419 | - }else{ |
|
| 419 | + } else { |
|
| 420 | 420 | $pageData['tag'][$dataIndex] = $pageData['tag'][$idIndex[$row[$id_field]][0]]; |
| 421 | 421 | } |
| 422 | 422 | $data[$dataIndex] = $temp->get_list_view_data($filter_fields); |
@@ -424,21 +424,21 @@ discard block |
||
| 424 | 424 | $editViewAccess = $temp->ACLAccess('EditView'); |
| 425 | 425 | $pageData['rowAccess'][$dataIndex] = array('view' => $detailViewAccess, 'edit' => $editViewAccess); |
| 426 | 426 | $additionalDetailsAllow = $this->additionalDetails && $detailViewAccess && (file_exists( |
| 427 | - 'modules/' . $temp->module_dir . '/metadata/additionalDetails.php' |
|
| 428 | - ) || file_exists('custom/modules/' . $temp->module_dir . '/metadata/additionalDetails.php')); |
|
| 427 | + 'modules/'.$temp->module_dir.'/metadata/additionalDetails.php' |
|
| 428 | + ) || file_exists('custom/modules/'.$temp->module_dir.'/metadata/additionalDetails.php')); |
|
| 429 | 429 | $additionalDetailsEdit = $editViewAccess; |
| 430 | - if($additionalDetailsAllow) { |
|
| 431 | - if($this->additionalDetailsAjax) { |
|
| 430 | + if ($additionalDetailsAllow) { |
|
| 431 | + if ($this->additionalDetailsAjax) { |
|
| 432 | 432 | $ar = $this->getAdditionalDetailsAjax($data[$dataIndex]['ID']); |
| 433 | 433 | } |
| 434 | 434 | else { |
| 435 | - $additionalDetailsFile = 'modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
|
| 436 | - if(file_exists('custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php')){ |
|
| 437 | - $additionalDetailsFile = 'custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
|
| 435 | + $additionalDetailsFile = 'modules/'.$this->seed->module_dir.'/metadata/additionalDetails.php'; |
|
| 436 | + if (file_exists('custom/modules/'.$this->seed->module_dir.'/metadata/additionalDetails.php')) { |
|
| 437 | + $additionalDetailsFile = 'custom/modules/'.$this->seed->module_dir.'/metadata/additionalDetails.php'; |
|
| 438 | 438 | } |
| 439 | 439 | require_once($additionalDetailsFile); |
| 440 | 440 | $ar = $this->getAdditionalDetails($data[$dataIndex], |
| 441 | - (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction) . $this->seed->object_name, |
|
| 441 | + (empty($this->additionalDetailsFunction) ? 'additionalDetails' : $this->additionalDetailsFunction).$this->seed->object_name, |
|
| 442 | 442 | $additionalDetailsEdit); |
| 443 | 443 | } |
| 444 | 444 | $pageData['additionalDetails'][$dataIndex] = $ar['string']; |
@@ -450,18 +450,18 @@ discard block |
||
| 450 | 450 | $nextOffset = -1; |
| 451 | 451 | $prevOffset = -1; |
| 452 | 452 | $endOffset = -1; |
| 453 | - if($count > $limit) { |
|
| 453 | + if ($count > $limit) { |
|
| 454 | 454 | $nextOffset = $offset + $limit; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - if($offset > 0) { |
|
| 457 | + if ($offset > 0) { |
|
| 458 | 458 | $prevOffset = $offset - $limit; |
| 459 | - if($prevOffset < 0)$prevOffset = 0; |
|
| 459 | + if ($prevOffset < 0)$prevOffset = 0; |
|
| 460 | 460 | } |
| 461 | 461 | $totalCount = $count + $offset; |
| 462 | 462 | |
| 463 | - if( $count >= $limit && $totalCounted){ |
|
| 464 | - $totalCount = $this->getTotalCount($main_query); |
|
| 463 | + if ($count >= $limit && $totalCounted) { |
|
| 464 | + $totalCount = $this->getTotalCount($main_query); |
|
| 465 | 465 | } |
| 466 | 466 | SugarVCR::recordIDs($this->seed->module_dir, array_keys($idIndex), $offset, $totalCount); |
| 467 | 467 | $module_names = array( |
@@ -471,21 +471,21 @@ discard block |
||
| 471 | 471 | $pageData['ordering'] = $order; |
| 472 | 472 | $pageData['ordering']['sortOrder'] = $this->getReverseSortOrder($pageData['ordering']['sortOrder']); |
| 473 | 473 | //get url parameters as an array |
| 474 | - $pageData['queries'] = $this->generateQueries($pageData['ordering']['sortOrder'], $offset, $prevOffset, $nextOffset, $endOffset, $totalCounted); |
|
| 474 | + $pageData['queries'] = $this->generateQueries($pageData['ordering']['sortOrder'], $offset, $prevOffset, $nextOffset, $endOffset, $totalCounted); |
|
| 475 | 475 | //join url parameters from array to a string |
| 476 | 476 | $pageData['urls'] = $this->generateURLS($pageData['queries']); |
| 477 | - $pageData['offsets'] = array( 'current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted); |
|
| 477 | + $pageData['offsets'] = array('current'=>$offset, 'next'=>$nextOffset, 'prev'=>$prevOffset, 'end'=>$endOffset, 'total'=>$totalCount, 'totalCounted'=>$totalCounted); |
|
| 478 | 478 | $pageData['bean'] = array('objectName' => $seed->object_name, 'moduleDir' => $seed->module_dir, 'moduleName' => strtr($seed->module_dir, $module_names)); |
| 479 | 479 | $pageData['stamp'] = $this->stamp; |
| 480 | 480 | $pageData['access'] = array('view' => $this->seed->ACLAccess('DetailView'), 'edit' => $this->seed->ACLAccess('EditView')); |
| 481 | 481 | $pageData['idIndex'] = $idIndex; |
| 482 | - if(!$this->seed->ACLAccess('ListView')) { |
|
| 482 | + if (!$this->seed->ACLAccess('ListView')) { |
|
| 483 | 483 | $pageData['error'] = 'ACL restricted access'; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | $queryString = ''; |
| 487 | 487 | |
| 488 | - if( isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "advanced_search" || |
|
| 488 | + if (isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "advanced_search" || |
|
| 489 | 489 | isset($_REQUEST["type_basic"]) && (count($_REQUEST["type_basic"] > 1) || $_REQUEST["type_basic"][0] != "") || |
| 490 | 490 | isset($_REQUEST["module"]) && $_REQUEST["module"] == "MergeRecords") |
| 491 | 491 | { |
@@ -493,19 +493,19 @@ discard block |
||
| 493 | 493 | } |
| 494 | 494 | else if (isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "basic_search") |
| 495 | 495 | { |
| 496 | - if($seed->module_dir == "Reports") $searchMetaData = SearchFormReports::retrieveReportsSearchDefs(); |
|
| 496 | + if ($seed->module_dir == "Reports") $searchMetaData = SearchFormReports::retrieveReportsSearchDefs(); |
|
| 497 | 497 | else $searchMetaData = SearchForm::retrieveSearchDefs($seed->module_dir); |
| 498 | 498 | |
| 499 | 499 | $basicSearchFields = array(); |
| 500 | 500 | |
| 501 | - if( isset($searchMetaData['searchdefs']) && isset($searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search']) ) |
|
| 501 | + if (isset($searchMetaData['searchdefs']) && isset($searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search'])) |
|
| 502 | 502 | $basicSearchFields = $searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search']; |
| 503 | 503 | |
| 504 | - foreach( $basicSearchFields as $basicSearchField) |
|
| 504 | + foreach ($basicSearchFields as $basicSearchField) |
|
| 505 | 505 | { |
| 506 | 506 | $field_name = (is_array($basicSearchField) && isset($basicSearchField['name'])) ? $basicSearchField['name'] : $basicSearchField; |
| 507 | 507 | $field_name .= "_basic"; |
| 508 | - if( isset($_REQUEST[$field_name]) && ( !is_array($basicSearchField) || !isset($basicSearchField['type']) || $basicSearchField['type'] == 'text' || $basicSearchField['type'] == 'name') ) |
|
| 508 | + if (isset($_REQUEST[$field_name]) && (!is_array($basicSearchField) || !isset($basicSearchField['type']) || $basicSearchField['type'] == 'text' || $basicSearchField['type'] == 'name')) |
|
| 509 | 509 | { |
| 510 | 510 | // Ensure the encoding is UTF-8 |
| 511 | 511 | $queryString = htmlentities($_REQUEST[$field_name], null, 'UTF-8'); |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - return array('data'=>$data , 'pageData'=>$pageData, 'query' => $queryString); |
|
| 517 | + return array('data'=>$data, 'pageData'=>$pageData, 'query' => $queryString); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | { |
| 529 | 529 | foreach ($queries as $name => $value) |
| 530 | 530 | { |
| 531 | - $queries[$name] = 'index.php?' . http_build_query($value); |
|
| 531 | + $queries[$name] = 'index.php?'.http_build_query($value); |
|
| 532 | 532 | } |
| 533 | 533 | $this->base_url = $queries['baseURL']; |
| 534 | 534 | return $queries; |
@@ -554,22 +554,22 @@ discard block |
||
| 554 | 554 | $queries['orderBy'] = $queries['baseURL']; |
| 555 | 555 | $queries['orderBy'][$this->var_order_by] = ''; |
| 556 | 556 | |
| 557 | - if($nextOffset > -1) |
|
| 557 | + if ($nextOffset > -1) |
|
| 558 | 558 | { |
| 559 | 559 | $queries['nextPage'] = $queries['baseURL']; |
| 560 | 560 | $queries['nextPage'][$this->var_offset] = $nextOffset; |
| 561 | 561 | } |
| 562 | - if($offset > 0) |
|
| 562 | + if ($offset > 0) |
|
| 563 | 563 | { |
| 564 | 564 | $queries['startPage'] = $queries['baseURL']; |
| 565 | 565 | $queries['startPage'][$this->var_offset] = 0; |
| 566 | 566 | } |
| 567 | - if($prevOffset > -1) |
|
| 567 | + if ($prevOffset > -1) |
|
| 568 | 568 | { |
| 569 | 569 | $queries['prevPage'] = $queries['baseURL']; |
| 570 | 570 | $queries['prevPage'][$this->var_offset] = $prevOffset; |
| 571 | 571 | } |
| 572 | - if($totalCounted) |
|
| 572 | + if ($totalCounted) |
|
| 573 | 573 | { |
| 574 | 574 | $queries['endPage'] = $queries['baseURL']; |
| 575 | 575 | $queries['endPage'][$this->var_offset] = $endOffset; |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | |
| 595 | 595 | $jscalendarImage = SugarThemeRegistry::current()->getImageURL('info_inline.gif'); |
| 596 | 596 | |
| 597 | - $extra = "<span id='adspan_" . $id . "' " |
|
| 597 | + $extra = "<span id='adspan_".$id."' " |
|
| 598 | 598 | . "onclick=\"lvg_dtails('$id')\" " |
| 599 | 599 | . " style='position: relative;'><!--not_in_theme!--><img vertical-align='middle' class='info' border='0' alt='".$app_strings['LBL_ADDITIONAL_DETAILS']."' src='$jscalendarImage'></span>"; |
| 600 | 600 | |
@@ -618,27 +618,27 @@ discard block |
||
| 618 | 618 | |
| 619 | 619 | $results['string'] = str_replace(array("'", "'"), '\'', $results['string']); // no xss! |
| 620 | 620 | |
| 621 | - if(trim($results['string']) == '') |
|
| 621 | + if (trim($results['string']) == '') |
|
| 622 | 622 | { |
| 623 | 623 | $results['string'] = $app_strings['LBL_NONE']; |
| 624 | 624 | } |
| 625 | 625 | $close = false; |
| 626 | 626 | $extra = "<img alt='{$app_strings['LBL_INFOINLINE']}' style='padding: 0px 5px 0px 2px' border='0' onclick=\"SUGAR.util.getStaticAdditionalDetails(this,'"; |
| 627 | 627 | |
| 628 | - $extra .= str_replace(array("\rn", "\r", "\n"), array('','','<br />'), $results['string']) ; |
|
| 628 | + $extra .= str_replace(array("\rn", "\r", "\n"), array('', '', '<br />'), $results['string']); |
|
| 629 | 629 | $extra .= "','<div style=\'float:left\'>{$app_strings['LBL_ADDITIONAL_DETAILS']}</div><div style=\'float: right\'>"; |
| 630 | 630 | |
| 631 | - if($editAccess && !empty($results['editLink'])) |
|
| 631 | + if ($editAccess && !empty($results['editLink'])) |
|
| 632 | 632 | { |
| 633 | - $extra .= "<a title=\'{$app_strings['LBL_EDIT_BUTTON']}\' href={$results['editLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('edit_inline.png')."\'></a>"; |
|
| 633 | + $extra .= "<a title=\'{$app_strings['LBL_EDIT_BUTTON']}\' href={$results['editLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('edit_inline.png')."\'></a>"; |
|
| 634 | 634 | $close = true; |
| 635 | 635 | } |
| 636 | 636 | $close = (!empty($results['viewLink'])) ? true : $close; |
| 637 | 637 | $extra .= (!empty($results['viewLink']) ? "<a title=\'{$app_strings['LBL_VIEW_BUTTON']}\' href={$results['viewLink']}><img style=\'margin-left: 2px;\' border=\'0\' src=".SugarThemeRegistry::current()->getImageURL('view_inline.png')."></a>" : ''); |
| 638 | 638 | |
| 639 | - if($close == true) { |
|
| 639 | + if ($close == true) { |
|
| 640 | 640 | $closeVal = "true"; |
| 641 | - $extra .= "<a title=\'{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}\' href=\'javascript: SUGAR.util.closeStaticAdditionalDetails();\'><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('close.png')."\'></a>"; |
|
| 641 | + $extra .= "<a title=\'{$app_strings['LBL_ADDITIONAL_DETAILS_CLOSE_TITLE']}\' href=\'javascript: SUGAR.util.closeStaticAdditionalDetails();\'><img style=\'margin-left: 2px;\' border=\'0\' src=\'".SugarThemeRegistry::current()->getImageURL('close.png')."\'></a>"; |
|
| 642 | 642 | } else { |
| 643 | 643 | $closeVal = "false"; |
| 644 | 644 | } |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -84,8 +86,7 @@ discard block |
||
| 84 | 86 | } |
| 85 | 87 | $_SESSION[$this->var_order_by] = array('orderBy'=>$orderBy, 'direction'=> $direction); |
| 86 | 88 | $_SESSION['lvd']['last_ob'] = $orderBy; |
| 87 | - } |
|
| 88 | - else { |
|
| 89 | + } else { |
|
| 89 | 90 | $userPreferenceOrder = $GLOBALS['current_user']->getPreference('listviewOrder', $this->var_name); |
| 90 | 91 | if(!empty($_SESSION[$this->var_order_by])) { |
| 91 | 92 | $orderBy = $_SESSION[$this->var_order_by]['orderBy']; |
@@ -183,7 +184,7 @@ discard block |
||
| 183 | 184 | function getTotalCount($main_query){ |
| 184 | 185 | if(!empty($this->count_query)){ |
| 185 | 186 | $count_query = $this->count_query; |
| 186 | - }else{ |
|
| 187 | + } else{ |
|
| 187 | 188 | $count_query = $this->seed->create_list_count_query($main_query); |
| 188 | 189 | } |
| 189 | 190 | $result = $this->db->query($count_query); |
@@ -246,8 +247,7 @@ discard block |
||
| 246 | 247 | // if $params tell us to override all ordering |
| 247 | 248 | if(!empty($params['overrideOrder']) && !empty($params['orderBy'])) { |
| 248 | 249 | $order = $this->getOrderBy(strtolower($params['orderBy']), (empty($params['sortOrder']) ? '' : $params['sortOrder'])); // retreive from $_REQUEST |
| 249 | - } |
|
| 250 | - else { |
|
| 250 | + } else { |
|
| 251 | 251 | $order = $this->getOrderBy(); // retreive from $_REQUEST |
| 252 | 252 | } |
| 253 | 253 | |
@@ -274,8 +274,9 @@ discard block |
||
| 274 | 274 | } else { |
| 275 | 275 | $orderBy = $order['orderBy'] . ' ' . $order['sortOrder']; |
| 276 | 276 | //wdong, Bug 25476, fix the sorting problem of Oracle. |
| 277 | - if (isset($params['custom_order_by_override']['ori_code']) && $order['orderBy'] == $params['custom_order_by_override']['ori_code']) |
|
| 278 | - $orderBy = $params['custom_order_by_override']['custom_code'] . ' ' . $order['sortOrder']; |
|
| 277 | + if (isset($params['custom_order_by_override']['ori_code']) && $order['orderBy'] == $params['custom_order_by_override']['ori_code']) { |
|
| 278 | + $orderBy = $params['custom_order_by_override']['custom_code'] . ' ' . $order['sortOrder']; |
|
| 279 | + } |
|
| 279 | 280 | } |
| 280 | 281 | |
| 281 | 282 | if (empty($params['skipOrderSave'])) { // don't save preferences if told so |
@@ -293,11 +294,21 @@ discard block |
||
| 293 | 294 | $ret_array['inner_join'] = ' ' . implode(' ', $this->seed->listview_inner_join) . ' '; |
| 294 | 295 | } |
| 295 | 296 | |
| 296 | - if(!is_array($params)) $params = array(); |
|
| 297 | - if(!isset($params['custom_select'])) $params['custom_select'] = ''; |
|
| 298 | - if(!isset($params['custom_from'])) $params['custom_from'] = ''; |
|
| 299 | - if(!isset($params['custom_where'])) $params['custom_where'] = ''; |
|
| 300 | - if(!isset($params['custom_order_by'])) $params['custom_order_by'] = ''; |
|
| 297 | + if(!is_array($params)) { |
|
| 298 | + $params = array(); |
|
| 299 | + } |
|
| 300 | + if(!isset($params['custom_select'])) { |
|
| 301 | + $params['custom_select'] = ''; |
|
| 302 | + } |
|
| 303 | + if(!isset($params['custom_from'])) { |
|
| 304 | + $params['custom_from'] = ''; |
|
| 305 | + } |
|
| 306 | + if(!isset($params['custom_where'])) { |
|
| 307 | + $params['custom_where'] = ''; |
|
| 308 | + } |
|
| 309 | + if(!isset($params['custom_order_by'])) { |
|
| 310 | + $params['custom_order_by'] = ''; |
|
| 311 | + } |
|
| 301 | 312 | $main_query = $ret_array['select'] . $params['custom_select'] . $ret_array['from'] . $params['custom_from'] . $ret_array['inner_join']. $ret_array['where'] . $params['custom_where'] . $ret_array['order_by'] . $params['custom_order_by']; |
| 302 | 313 | //C.L. - Fix for 23461 |
| 303 | 314 | if(empty($_REQUEST['action']) || $_REQUEST['action'] != 'Popup') { |
@@ -305,13 +316,14 @@ discard block |
||
| 305 | 316 | } |
| 306 | 317 | if($limit < -1) { |
| 307 | 318 | $result = $this->db->query($main_query); |
| 308 | - } |
|
| 309 | - else { |
|
| 319 | + } else { |
|
| 310 | 320 | if($limit == -1) { |
| 311 | 321 | $limit = $this->getLimit(); |
| 312 | 322 | } |
| 313 | 323 | $dyn_offset = $this->getOffset(); |
| 314 | - if($dyn_offset > 0 || !is_int($dyn_offset))$offset = $dyn_offset; |
|
| 324 | + if($dyn_offset > 0 || !is_int($dyn_offset)) { |
|
| 325 | + $offset = $dyn_offset; |
|
| 326 | + } |
|
| 315 | 327 | |
| 316 | 328 | if(strcmp($offset, 'end') == 0){ |
| 317 | 329 | $totalCount = $this->getTotalCount($main_query); |
@@ -319,8 +331,7 @@ discard block |
||
| 319 | 331 | } |
| 320 | 332 | if($this->seed->ACLAccess('ListView')) { |
| 321 | 333 | $result = $this->db->limitQuery($main_query, $offset, $limit + 1); |
| 322 | - } |
|
| 323 | - else { |
|
| 334 | + } else { |
|
| 324 | 335 | $result = array(); |
| 325 | 336 | } |
| 326 | 337 | |
@@ -388,7 +399,9 @@ discard block |
||
| 388 | 399 | if(!isset($post_retrieve[$rows[$rowIndex[0]]['parent_type']])) { |
| 389 | 400 | $post_retrieve[$rows[$rowIndex[0]]['parent_type']] = array(); |
| 390 | 401 | } |
| 391 | - if(!empty($rows[$rowIndex[0]]['parent_id'])) $post_retrieve[$rows[$rowIndex[0]]['parent_type']][] = array('child_id' => $id , 'parent_id'=> $rows[$rowIndex[0]]['parent_id'], 'parent_type' => $rows[$rowIndex[0]]['parent_type'], 'type' => 'parent'); |
|
| 402 | + if(!empty($rows[$rowIndex[0]]['parent_id'])) { |
|
| 403 | + $post_retrieve[$rows[$rowIndex[0]]['parent_type']][] = array('child_id' => $id , 'parent_id'=> $rows[$rowIndex[0]]['parent_id'], 'parent_type' => $rows[$rowIndex[0]]['parent_type'], 'type' => 'parent'); |
|
| 404 | + } |
|
| 392 | 405 | } |
| 393 | 406 | if(isset($post_retrieve)) { |
| 394 | 407 | $parent_fields = $seed->retrieve_parent_fields($post_retrieve); |
@@ -416,7 +429,7 @@ discard block |
||
| 416 | 429 | } |
| 417 | 430 | if($idIndex[$row[$id_field]][0] == $dataIndex){ |
| 418 | 431 | $pageData['tag'][$dataIndex] = $temp->listviewACLHelper(); |
| 419 | - }else{ |
|
| 432 | + } else{ |
|
| 420 | 433 | $pageData['tag'][$dataIndex] = $pageData['tag'][$idIndex[$row[$id_field]][0]]; |
| 421 | 434 | } |
| 422 | 435 | $data[$dataIndex] = $temp->get_list_view_data($filter_fields); |
@@ -430,8 +443,7 @@ discard block |
||
| 430 | 443 | if($additionalDetailsAllow) { |
| 431 | 444 | if($this->additionalDetailsAjax) { |
| 432 | 445 | $ar = $this->getAdditionalDetailsAjax($data[$dataIndex]['ID']); |
| 433 | - } |
|
| 434 | - else { |
|
| 446 | + } else { |
|
| 435 | 447 | $additionalDetailsFile = 'modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
| 436 | 448 | if(file_exists('custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php')){ |
| 437 | 449 | $additionalDetailsFile = 'custom/modules/' . $this->seed->module_dir . '/metadata/additionalDetails.php'; |
@@ -456,7 +468,9 @@ discard block |
||
| 456 | 468 | |
| 457 | 469 | if($offset > 0) { |
| 458 | 470 | $prevOffset = $offset - $limit; |
| 459 | - if($prevOffset < 0)$prevOffset = 0; |
|
| 471 | + if($prevOffset < 0) { |
|
| 472 | + $prevOffset = 0; |
|
| 473 | + } |
|
| 460 | 474 | } |
| 461 | 475 | $totalCount = $count + $offset; |
| 462 | 476 | |
@@ -490,16 +504,19 @@ discard block |
||
| 490 | 504 | isset($_REQUEST["module"]) && $_REQUEST["module"] == "MergeRecords") |
| 491 | 505 | { |
| 492 | 506 | $queryString = "-advanced_search"; |
| 493 | - } |
|
| 494 | - else if (isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "basic_search") |
|
| 507 | + } else if (isset($_REQUEST["searchFormTab"]) && $_REQUEST["searchFormTab"] == "basic_search") |
|
| 495 | 508 | { |
| 496 | - if($seed->module_dir == "Reports") $searchMetaData = SearchFormReports::retrieveReportsSearchDefs(); |
|
| 497 | - else $searchMetaData = SearchForm::retrieveSearchDefs($seed->module_dir); |
|
| 509 | + if($seed->module_dir == "Reports") { |
|
| 510 | + $searchMetaData = SearchFormReports::retrieveReportsSearchDefs(); |
|
| 511 | + } else { |
|
| 512 | + $searchMetaData = SearchForm::retrieveSearchDefs($seed->module_dir); |
|
| 513 | + } |
|
| 498 | 514 | |
| 499 | 515 | $basicSearchFields = array(); |
| 500 | 516 | |
| 501 | - if( isset($searchMetaData['searchdefs']) && isset($searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search']) ) |
|
| 502 | - $basicSearchFields = $searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search']; |
|
| 517 | + if( isset($searchMetaData['searchdefs']) && isset($searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search']) ) { |
|
| 518 | + $basicSearchFields = $searchMetaData['searchdefs'][$seed->module_dir]['layout']['basic_search']; |
|
| 519 | + } |
|
| 503 | 520 | |
| 504 | 521 | foreach( $basicSearchFields as $basicSearchField) |
| 505 | 522 | { |
@@ -573,8 +590,7 @@ discard block |
||
| 573 | 590 | { |
| 574 | 591 | $queries['endPage'] = $queries['baseURL']; |
| 575 | 592 | $queries['endPage'][$this->var_offset] = $endOffset; |
| 576 | - } |
|
| 577 | - else |
|
| 593 | + } else |
|
| 578 | 594 | { |
| 579 | 595 | $queries['endPage'] = $queries['baseURL']; |
| 580 | 596 | $queries['endPage'][$this->var_offset] = 'end'; |
@@ -162,7 +162,8 @@ discard block |
||
| 162 | 162 | /** |
| 163 | 163 | * based off of a base name it sets base, offset, and order by variable names to retrieve them from requests and sessions |
| 164 | 164 | * |
| 165 | - * @param unknown_type $baseName |
|
| 165 | + * @param string $baseName |
|
| 166 | + * @param string $where |
|
| 166 | 167 | */ |
| 167 | 168 | function setVariableName($baseName, $where, $listviewName = null){ |
| 168 | 169 | global $timedate; |
@@ -180,6 +181,9 @@ discard block |
||
| 180 | 181 | $_SESSION[strtoupper($baseName) . "_DETAIL_NAV_HISTORY"] = false; |
| 181 | 182 | } |
| 182 | 183 | |
| 184 | + /** |
|
| 185 | + * @param string $main_query |
|
| 186 | + */ |
|
| 183 | 187 | function getTotalCount($main_query){ |
| 184 | 188 | if(!empty($this->count_query)){ |
| 185 | 189 | $count_query = $this->count_query; |
@@ -605,8 +609,8 @@ discard block |
||
| 605 | 609 | * generates the additional details values |
| 606 | 610 | * |
| 607 | 611 | * @param unknown_type $fields |
| 608 | - * @param unknown_type $adFunction |
|
| 609 | - * @param unknown_type $editAccess |
|
| 612 | + * @param string $adFunction |
|
| 613 | + * @param boolean $editAccess |
|
| 610 | 614 | * @return array string to attach to field |
| 611 | 615 | */ |
| 612 | 616 | function getAdditionalDetails($fields, $adFunction, $editAccess) |
@@ -54,44 +54,44 @@ discard block |
||
| 54 | 54 | * @return boolean - Returns true on success false on failure |
| 55 | 55 | */ |
| 56 | 56 | function sugar_mkdir($pathname, $mode=null, $recursive=false, $context='') { |
| 57 | - $mode = get_mode('dir_mode', $mode); |
|
| 58 | - |
|
| 59 | - if ( sugar_is_dir($pathname,$mode) ) |
|
| 60 | - return true; |
|
| 61 | - |
|
| 62 | - $result = false; |
|
| 63 | - if(empty($mode)) |
|
| 64 | - $mode = 0777; |
|
| 65 | - if(empty($context)) { |
|
| 66 | - $result = @mkdir($pathname, $mode, $recursive); |
|
| 67 | - } else { |
|
| 68 | - $result = @mkdir($pathname, $mode, $recursive, $context); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if($result){ |
|
| 72 | - if(!sugar_chmod($pathname, $mode)){ |
|
| 73 | - return false; |
|
| 74 | - } |
|
| 75 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 76 | - if(!sugar_chown($pathname)){ |
|
| 77 | - return false; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 81 | - if(!sugar_chgrp($pathname)) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - else { |
|
| 87 | - $errorMessage = "Cannot create directory $pathname cannot be touched"; |
|
| 88 | - if(is_null($GLOBALS['log'])) { |
|
| 89 | - throw new Exception("Error occurred but the system doesn't have logger. Error message: \"$errorMessage\""); |
|
| 90 | - } |
|
| 91 | - $GLOBALS['log']->error($errorMessage); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $result; |
|
| 57 | + $mode = get_mode('dir_mode', $mode); |
|
| 58 | + |
|
| 59 | + if ( sugar_is_dir($pathname,$mode) ) |
|
| 60 | + return true; |
|
| 61 | + |
|
| 62 | + $result = false; |
|
| 63 | + if(empty($mode)) |
|
| 64 | + $mode = 0777; |
|
| 65 | + if(empty($context)) { |
|
| 66 | + $result = @mkdir($pathname, $mode, $recursive); |
|
| 67 | + } else { |
|
| 68 | + $result = @mkdir($pathname, $mode, $recursive, $context); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if($result){ |
|
| 72 | + if(!sugar_chmod($pathname, $mode)){ |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 75 | + if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 76 | + if(!sugar_chown($pathname)){ |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 81 | + if(!sugar_chgrp($pathname)) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + else { |
|
| 87 | + $errorMessage = "Cannot create directory $pathname cannot be touched"; |
|
| 88 | + if(is_null($GLOBALS['log'])) { |
|
| 89 | + throw new Exception("Error occurred but the system doesn't have logger. Error message: \"$errorMessage\""); |
|
| 90 | + } |
|
| 91 | + $GLOBALS['log']->error($errorMessage); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $result; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -109,17 +109,17 @@ discard block |
||
| 109 | 109 | * @return boolean - Returns a file pointer on success, false otherwise |
| 110 | 110 | */ |
| 111 | 111 | function sugar_fopen($filename, $mode, $use_include_path=false, $context=null){ |
| 112 | - //check to see if the file exists, if not then use touch to create it. |
|
| 113 | - if(!file_exists($filename)){ |
|
| 114 | - sugar_touch($filename); |
|
| 115 | - } |
|
| 112 | + //check to see if the file exists, if not then use touch to create it. |
|
| 113 | + if(!file_exists($filename)){ |
|
| 114 | + sugar_touch($filename); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - if(empty($context)) { |
|
| 117 | + if(empty($context)) { |
|
| 118 | 118 | |
| 119 | - return fopen($filename, $mode, $use_include_path); |
|
| 120 | - } else { |
|
| 121 | - return fopen($filename, $mode, $use_include_path, $context); |
|
| 122 | - } |
|
| 119 | + return fopen($filename, $mode, $use_include_path); |
|
| 120 | + } else { |
|
| 121 | + return fopen($filename, $mode, $use_include_path, $context); |
|
| 122 | + } |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -137,23 +137,23 @@ discard block |
||
| 137 | 137 | * @return int - Returns the number of bytes written to the file, false otherwise. |
| 138 | 138 | */ |
| 139 | 139 | function sugar_file_put_contents($filename, $data, $flags=null, $context=null){ |
| 140 | - //check to see if the file exists, if not then use touch to create it. |
|
| 141 | - if(!file_exists($filename)){ |
|
| 142 | - sugar_touch($filename); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if ( !is_writable($filename) ) { |
|
| 146 | - $GLOBALS['log']->error("File $filename cannot be written to"); |
|
| 147 | - return false; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - if(empty($flags)) { |
|
| 151 | - return file_put_contents($filename, $data); |
|
| 152 | - } elseif(empty($context)) { |
|
| 153 | - return file_put_contents($filename, $data, $flags); |
|
| 154 | - } else{ |
|
| 155 | - return file_put_contents($filename, $data, $flags, $context); |
|
| 156 | - } |
|
| 140 | + //check to see if the file exists, if not then use touch to create it. |
|
| 141 | + if(!file_exists($filename)){ |
|
| 142 | + sugar_touch($filename); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if ( !is_writable($filename) ) { |
|
| 146 | + $GLOBALS['log']->error("File $filename cannot be written to"); |
|
| 147 | + return false; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + if(empty($flags)) { |
|
| 151 | + return file_put_contents($filename, $data); |
|
| 152 | + } elseif(empty($context)) { |
|
| 153 | + return file_put_contents($filename, $data, $flags); |
|
| 154 | + } else{ |
|
| 155 | + return file_put_contents($filename, $data, $flags, $context); |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | if(file_exists($filename)) |
| 200 | 200 | { |
| 201 | - return sugar_chmod($filename, 0755); |
|
| 201 | + return sugar_chmod($filename, 0755); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return false; |
@@ -215,21 +215,21 @@ discard block |
||
| 215 | 215 | * @return string|boolean - Returns a file data on success, false otherwise |
| 216 | 216 | */ |
| 217 | 217 | function sugar_file_get_contents($filename, $use_include_path=false, $context=null){ |
| 218 | - //check to see if the file exists, if not then use touch to create it. |
|
| 219 | - if(!file_exists($filename)){ |
|
| 220 | - sugar_touch($filename); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if ( !is_readable($filename) ) { |
|
| 224 | - $GLOBALS['log']->error("File $filename cannot be read"); |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - if(empty($context)) { |
|
| 229 | - return file_get_contents($filename, $use_include_path); |
|
| 230 | - } else { |
|
| 231 | - return file_get_contents($filename, $use_include_path, $context); |
|
| 232 | - } |
|
| 218 | + //check to see if the file exists, if not then use touch to create it. |
|
| 219 | + if(!file_exists($filename)){ |
|
| 220 | + sugar_touch($filename); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if ( !is_readable($filename) ) { |
|
| 224 | + $GLOBALS['log']->error("File $filename cannot be read"); |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + if(empty($context)) { |
|
| 229 | + return file_get_contents($filename, $use_include_path); |
|
| 230 | + } else { |
|
| 231 | + return file_get_contents($filename, $use_include_path, $context); |
|
| 232 | + } |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -248,31 +248,31 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | function sugar_touch($filename, $time=null, $atime=null) { |
| 250 | 250 | |
| 251 | - $result = false; |
|
| 252 | - |
|
| 253 | - if(!empty($atime) && !empty($time)) { |
|
| 254 | - $result = @touch($filename, $time, $atime); |
|
| 255 | - } else if(!empty($time)) { |
|
| 256 | - $result = @touch($filename, $time); |
|
| 257 | - } else { |
|
| 258 | - $result = @touch($filename); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if(!$result) { |
|
| 262 | - $GLOBALS['log']->error("File $filename cannot be touched"); |
|
| 263 | - return $result; |
|
| 264 | - } |
|
| 265 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])){ |
|
| 266 | - sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']); |
|
| 267 | - } |
|
| 268 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 269 | - sugar_chown($filename); |
|
| 270 | - } |
|
| 271 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 272 | - sugar_chgrp($filename); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return true; |
|
| 251 | + $result = false; |
|
| 252 | + |
|
| 253 | + if(!empty($atime) && !empty($time)) { |
|
| 254 | + $result = @touch($filename, $time, $atime); |
|
| 255 | + } else if(!empty($time)) { |
|
| 256 | + $result = @touch($filename, $time); |
|
| 257 | + } else { |
|
| 258 | + $result = @touch($filename); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if(!$result) { |
|
| 262 | + $GLOBALS['log']->error("File $filename cannot be touched"); |
|
| 263 | + return $result; |
|
| 264 | + } |
|
| 265 | + if(!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])){ |
|
| 266 | + sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']); |
|
| 267 | + } |
|
| 268 | + if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 269 | + sugar_chown($filename); |
|
| 270 | + } |
|
| 271 | + if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 272 | + sugar_chgrp($filename); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return true; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -287,17 +287,17 @@ discard block |
||
| 287 | 287 | function sugar_chmod($filename, $mode=null) { |
| 288 | 288 | if ( !is_int($mode) ) |
| 289 | 289 | $mode = (int) $mode; |
| 290 | - if(!is_windows()){ |
|
| 291 | - if(!isset($mode)){ |
|
| 292 | - $mode = get_mode('file_mode', $mode); |
|
| 293 | - } |
|
| 290 | + if(!is_windows()){ |
|
| 291 | + if(!isset($mode)){ |
|
| 292 | + $mode = get_mode('file_mode', $mode); |
|
| 293 | + } |
|
| 294 | 294 | if(isset($mode) && $mode > 0){ |
| 295 | - return @chmod($filename, $mode); |
|
| 296 | - }else{ |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - return true; |
|
| 295 | + return @chmod($filename, $mode); |
|
| 296 | + }else{ |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + return true; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -310,19 +310,19 @@ discard block |
||
| 310 | 310 | * @return boolean - Returns TRUE on success or FALSE on failure. |
| 311 | 311 | */ |
| 312 | 312 | function sugar_chown($filename, $user='') { |
| 313 | - if(!is_windows()){ |
|
| 314 | - if(strlen($user)){ |
|
| 315 | - return chown($filename, $user); |
|
| 316 | - }else{ |
|
| 317 | - if(strlen($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 318 | - $user = $GLOBALS['sugar_config']['default_permissions']['user']; |
|
| 319 | - return chown($filename, $user); |
|
| 320 | - }else{ |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - return true; |
|
| 313 | + if(!is_windows()){ |
|
| 314 | + if(strlen($user)){ |
|
| 315 | + return chown($filename, $user); |
|
| 316 | + }else{ |
|
| 317 | + if(strlen($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 318 | + $user = $GLOBALS['sugar_config']['default_permissions']['user']; |
|
| 319 | + return chown($filename, $user); |
|
| 320 | + }else{ |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + return true; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -335,19 +335,19 @@ discard block |
||
| 335 | 335 | * @return boolean - Returns TRUE on success or FALSE on failure. |
| 336 | 336 | */ |
| 337 | 337 | function sugar_chgrp($filename, $group='') { |
| 338 | - if(!is_windows()){ |
|
| 339 | - if(!empty($group)){ |
|
| 340 | - return chgrp($filename, $group); |
|
| 341 | - }else{ |
|
| 342 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 343 | - $group = $GLOBALS['sugar_config']['default_permissions']['group']; |
|
| 344 | - return chgrp($filename, $group); |
|
| 345 | - }else{ |
|
| 346 | - return false; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - return true; |
|
| 338 | + if(!is_windows()){ |
|
| 339 | + if(!empty($group)){ |
|
| 340 | + return chgrp($filename, $group); |
|
| 341 | + }else{ |
|
| 342 | + if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 343 | + $group = $GLOBALS['sugar_config']['default_permissions']['group']; |
|
| 344 | + return chgrp($filename, $group); |
|
| 345 | + }else{ |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + return true; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -361,26 +361,26 @@ discard block |
||
| 361 | 361 | * @return int - the mode either found in the config file or passed in via the input parameter |
| 362 | 362 | */ |
| 363 | 363 | function get_mode($key = 'dir_mode', $mode=null) { |
| 364 | - if ( !is_int($mode) ) |
|
| 364 | + if ( !is_int($mode) ) |
|
| 365 | 365 | $mode = (int) $mode; |
| 366 | 366 | if(!class_exists('SugarConfig', true)) { |
| 367 | - require 'include/SugarObjects/SugarConfig.php'; |
|
| 368 | - } |
|
| 369 | - if(!is_windows()){ |
|
| 370 | - $conf_inst=SugarConfig::getInstance(); |
|
| 371 | - $mode = $conf_inst->get('default_permissions.'.$key, $mode); |
|
| 372 | - } |
|
| 373 | - return $mode; |
|
| 367 | + require 'include/SugarObjects/SugarConfig.php'; |
|
| 368 | + } |
|
| 369 | + if(!is_windows()){ |
|
| 370 | + $conf_inst=SugarConfig::getInstance(); |
|
| 371 | + $mode = $conf_inst->get('default_permissions.'.$key, $mode); |
|
| 372 | + } |
|
| 373 | + return $mode; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | function sugar_is_dir($path, $mode='r'){ |
| 377 | - if(defined('TEMPLATE_URL'))return is_dir($path, $mode); |
|
| 378 | - return is_dir($path); |
|
| 377 | + if(defined('TEMPLATE_URL'))return is_dir($path, $mode); |
|
| 378 | + return is_dir($path); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | function sugar_is_file($path, $mode='r'){ |
| 382 | - if(defined('TEMPLATE_URL'))return is_file($path, $mode); |
|
| 383 | - return is_file($path); |
|
| 382 | + if(defined('TEMPLATE_URL'))return is_file($path, $mode); |
|
| 383 | + return is_file($path); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -53,39 +53,39 @@ discard block |
||
| 53 | 53 | * @param $context |
| 54 | 54 | * @return boolean - Returns true on success false on failure |
| 55 | 55 | */ |
| 56 | -function sugar_mkdir($pathname, $mode=null, $recursive=false, $context='') { |
|
| 56 | +function sugar_mkdir($pathname, $mode = null, $recursive = false, $context = '') { |
|
| 57 | 57 | $mode = get_mode('dir_mode', $mode); |
| 58 | 58 | |
| 59 | - if ( sugar_is_dir($pathname,$mode) ) |
|
| 59 | + if (sugar_is_dir($pathname, $mode)) |
|
| 60 | 60 | return true; |
| 61 | 61 | |
| 62 | 62 | $result = false; |
| 63 | - if(empty($mode)) |
|
| 63 | + if (empty($mode)) |
|
| 64 | 64 | $mode = 0777; |
| 65 | - if(empty($context)) { |
|
| 65 | + if (empty($context)) { |
|
| 66 | 66 | $result = @mkdir($pathname, $mode, $recursive); |
| 67 | 67 | } else { |
| 68 | 68 | $result = @mkdir($pathname, $mode, $recursive, $context); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if($result){ |
|
| 72 | - if(!sugar_chmod($pathname, $mode)){ |
|
| 71 | + if ($result) { |
|
| 72 | + if (!sugar_chmod($pathname, $mode)) { |
|
| 73 | 73 | return false; |
| 74 | 74 | } |
| 75 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 76 | - if(!sugar_chown($pathname)){ |
|
| 75 | + if (!empty($GLOBALS['sugar_config']['default_permissions']['user'])) { |
|
| 76 | + if (!sugar_chown($pathname)) { |
|
| 77 | 77 | return false; |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 81 | - if(!sugar_chgrp($pathname)) { |
|
| 80 | + if (!empty($GLOBALS['sugar_config']['default_permissions']['group'])) { |
|
| 81 | + if (!sugar_chgrp($pathname)) { |
|
| 82 | 82 | return false; |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | else { |
| 87 | 87 | $errorMessage = "Cannot create directory $pathname cannot be touched"; |
| 88 | - if(is_null($GLOBALS['log'])) { |
|
| 88 | + if (is_null($GLOBALS['log'])) { |
|
| 89 | 89 | throw new Exception("Error occurred but the system doesn't have logger. Error message: \"$errorMessage\""); |
| 90 | 90 | } |
| 91 | 91 | $GLOBALS['log']->error($errorMessage); |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | * @param $context |
| 109 | 109 | * @return boolean - Returns a file pointer on success, false otherwise |
| 110 | 110 | */ |
| 111 | -function sugar_fopen($filename, $mode, $use_include_path=false, $context=null){ |
|
| 111 | +function sugar_fopen($filename, $mode, $use_include_path = false, $context = null) { |
|
| 112 | 112 | //check to see if the file exists, if not then use touch to create it. |
| 113 | - if(!file_exists($filename)){ |
|
| 113 | + if (!file_exists($filename)) { |
|
| 114 | 114 | sugar_touch($filename); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if(empty($context)) { |
|
| 117 | + if (empty($context)) { |
|
| 118 | 118 | |
| 119 | 119 | return fopen($filename, $mode, $use_include_path); |
| 120 | 120 | } else { |
@@ -136,22 +136,22 @@ discard block |
||
| 136 | 136 | * @param $context |
| 137 | 137 | * @return int - Returns the number of bytes written to the file, false otherwise. |
| 138 | 138 | */ |
| 139 | -function sugar_file_put_contents($filename, $data, $flags=null, $context=null){ |
|
| 139 | +function sugar_file_put_contents($filename, $data, $flags = null, $context = null) { |
|
| 140 | 140 | //check to see if the file exists, if not then use touch to create it. |
| 141 | - if(!file_exists($filename)){ |
|
| 141 | + if (!file_exists($filename)) { |
|
| 142 | 142 | sugar_touch($filename); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - if ( !is_writable($filename) ) { |
|
| 145 | + if (!is_writable($filename)) { |
|
| 146 | 146 | $GLOBALS['log']->error("File $filename cannot be written to"); |
| 147 | 147 | return false; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if(empty($flags)) { |
|
| 150 | + if (empty($flags)) { |
|
| 151 | 151 | return file_put_contents($filename, $data); |
| 152 | - } elseif(empty($context)) { |
|
| 152 | + } elseif (empty($context)) { |
|
| 153 | 153 | return file_put_contents($filename, $data, $flags); |
| 154 | - } else{ |
|
| 154 | + } else { |
|
| 155 | 155 | return file_put_contents($filename, $data, $flags, $context); |
| 156 | 156 | } |
| 157 | 157 | } |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | * @param context $context Context to pass into fopen operation |
| 170 | 170 | * @return boolean - Returns true if $filename was created, false otherwise. |
| 171 | 171 | */ |
| 172 | -function sugar_file_put_contents_atomic($filename, $data, $mode='wb', $use_include_path=false, $context=null){ |
|
| 172 | +function sugar_file_put_contents_atomic($filename, $data, $mode = 'wb', $use_include_path = false, $context = null) { |
|
| 173 | 173 | |
| 174 | 174 | $dir = dirname($filename); |
| 175 | 175 | $temp = tempnam($dir, 'temp'); |
| 176 | 176 | |
| 177 | 177 | if (!($f = @fopen($temp, $mode))) { |
| 178 | - $temp = $dir . DIRECTORY_SEPARATOR . uniqid('temp'); |
|
| 178 | + $temp = $dir.DIRECTORY_SEPARATOR.uniqid('temp'); |
|
| 179 | 179 | if (!($f = @fopen($temp, $mode))) { |
| 180 | 180 | trigger_error("sugar_file_put_contents_atomic() : error writing temporary file '$temp'", E_USER_WARNING); |
| 181 | 181 | return false; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if(file_exists($filename)) |
|
| 199 | + if (file_exists($filename)) |
|
| 200 | 200 | { |
| 201 | 201 | return sugar_chmod($filename, 0755); |
| 202 | 202 | } |
@@ -214,18 +214,18 @@ discard block |
||
| 214 | 214 | * @param $context |
| 215 | 215 | * @return string|boolean - Returns a file data on success, false otherwise |
| 216 | 216 | */ |
| 217 | -function sugar_file_get_contents($filename, $use_include_path=false, $context=null){ |
|
| 217 | +function sugar_file_get_contents($filename, $use_include_path = false, $context = null) { |
|
| 218 | 218 | //check to see if the file exists, if not then use touch to create it. |
| 219 | - if(!file_exists($filename)){ |
|
| 219 | + if (!file_exists($filename)) { |
|
| 220 | 220 | sugar_touch($filename); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( !is_readable($filename) ) { |
|
| 223 | + if (!is_readable($filename)) { |
|
| 224 | 224 | $GLOBALS['log']->error("File $filename cannot be read"); |
| 225 | 225 | return false; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - if(empty($context)) { |
|
| 228 | + if (empty($context)) { |
|
| 229 | 229 | return file_get_contents($filename, $use_include_path); |
| 230 | 230 | } else { |
| 231 | 231 | return file_get_contents($filename, $use_include_path, $context); |
@@ -246,29 +246,29 @@ discard block |
||
| 246 | 246 | * @return boolean - Returns TRUE on success or FALSE on failure. |
| 247 | 247 | * |
| 248 | 248 | */ |
| 249 | -function sugar_touch($filename, $time=null, $atime=null) { |
|
| 249 | +function sugar_touch($filename, $time = null, $atime = null) { |
|
| 250 | 250 | |
| 251 | 251 | $result = false; |
| 252 | 252 | |
| 253 | - if(!empty($atime) && !empty($time)) { |
|
| 253 | + if (!empty($atime) && !empty($time)) { |
|
| 254 | 254 | $result = @touch($filename, $time, $atime); |
| 255 | - } else if(!empty($time)) { |
|
| 255 | + } else if (!empty($time)) { |
|
| 256 | 256 | $result = @touch($filename, $time); |
| 257 | 257 | } else { |
| 258 | 258 | $result = @touch($filename); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if(!$result) { |
|
| 261 | + if (!$result) { |
|
| 262 | 262 | $GLOBALS['log']->error("File $filename cannot be touched"); |
| 263 | 263 | return $result; |
| 264 | 264 | } |
| 265 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])){ |
|
| 265 | + if (!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])) { |
|
| 266 | 266 | sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']); |
| 267 | 267 | } |
| 268 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 268 | + if (!empty($GLOBALS['sugar_config']['default_permissions']['user'])) { |
|
| 269 | 269 | sugar_chown($filename); |
| 270 | 270 | } |
| 271 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 271 | + if (!empty($GLOBALS['sugar_config']['default_permissions']['group'])) { |
|
| 272 | 272 | sugar_chgrp($filename); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -284,16 +284,16 @@ discard block |
||
| 284 | 284 | * @param int $mode The integer value of the permissions mode to set the created directory to |
| 285 | 285 | * @return boolean Returns TRUE on success or FALSE on failure. |
| 286 | 286 | */ |
| 287 | -function sugar_chmod($filename, $mode=null) { |
|
| 288 | - if ( !is_int($mode) ) |
|
| 289 | - $mode = (int) $mode; |
|
| 290 | - if(!is_windows()){ |
|
| 291 | - if(!isset($mode)){ |
|
| 287 | +function sugar_chmod($filename, $mode = null) { |
|
| 288 | + if (!is_int($mode)) |
|
| 289 | + $mode = (int)$mode; |
|
| 290 | + if (!is_windows()) { |
|
| 291 | + if (!isset($mode)) { |
|
| 292 | 292 | $mode = get_mode('file_mode', $mode); |
| 293 | 293 | } |
| 294 | - if(isset($mode) && $mode > 0){ |
|
| 294 | + if (isset($mode) && $mode > 0) { |
|
| 295 | 295 | return @chmod($filename, $mode); |
| 296 | - }else{ |
|
| 296 | + } else { |
|
| 297 | 297 | return false; |
| 298 | 298 | } |
| 299 | 299 | } |
@@ -309,15 +309,15 @@ discard block |
||
| 309 | 309 | * @param user - A user name or number |
| 310 | 310 | * @return boolean - Returns TRUE on success or FALSE on failure. |
| 311 | 311 | */ |
| 312 | -function sugar_chown($filename, $user='') { |
|
| 313 | - if(!is_windows()){ |
|
| 314 | - if(strlen($user)){ |
|
| 312 | +function sugar_chown($filename, $user = '') { |
|
| 313 | + if (!is_windows()) { |
|
| 314 | + if (strlen($user)) { |
|
| 315 | 315 | return chown($filename, $user); |
| 316 | - }else{ |
|
| 317 | - if(strlen($GLOBALS['sugar_config']['default_permissions']['user'])){ |
|
| 316 | + } else { |
|
| 317 | + if (strlen($GLOBALS['sugar_config']['default_permissions']['user'])) { |
|
| 318 | 318 | $user = $GLOBALS['sugar_config']['default_permissions']['user']; |
| 319 | 319 | return chown($filename, $user); |
| 320 | - }else{ |
|
| 320 | + } else { |
|
| 321 | 321 | return false; |
| 322 | 322 | } |
| 323 | 323 | } |
@@ -334,15 +334,15 @@ discard block |
||
| 334 | 334 | * @param group - A group name or number |
| 335 | 335 | * @return boolean - Returns TRUE on success or FALSE on failure. |
| 336 | 336 | */ |
| 337 | -function sugar_chgrp($filename, $group='') { |
|
| 338 | - if(!is_windows()){ |
|
| 339 | - if(!empty($group)){ |
|
| 337 | +function sugar_chgrp($filename, $group = '') { |
|
| 338 | + if (!is_windows()) { |
|
| 339 | + if (!empty($group)) { |
|
| 340 | 340 | return chgrp($filename, $group); |
| 341 | - }else{ |
|
| 342 | - if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
|
| 341 | + } else { |
|
| 342 | + if (!empty($GLOBALS['sugar_config']['default_permissions']['group'])) { |
|
| 343 | 343 | $group = $GLOBALS['sugar_config']['default_permissions']['group']; |
| 344 | 344 | return chgrp($filename, $group); |
| 345 | - }else{ |
|
| 345 | + } else { |
|
| 346 | 346 | return false; |
| 347 | 347 | } |
| 348 | 348 | } |
@@ -360,26 +360,26 @@ discard block |
||
| 360 | 360 | * defined in the config file. |
| 361 | 361 | * @return int - the mode either found in the config file or passed in via the input parameter |
| 362 | 362 | */ |
| 363 | -function get_mode($key = 'dir_mode', $mode=null) { |
|
| 364 | - if ( !is_int($mode) ) |
|
| 365 | - $mode = (int) $mode; |
|
| 366 | - if(!class_exists('SugarConfig', true)) { |
|
| 363 | +function get_mode($key = 'dir_mode', $mode = null) { |
|
| 364 | + if (!is_int($mode)) |
|
| 365 | + $mode = (int)$mode; |
|
| 366 | + if (!class_exists('SugarConfig', true)) { |
|
| 367 | 367 | require 'include/SugarObjects/SugarConfig.php'; |
| 368 | 368 | } |
| 369 | - if(!is_windows()){ |
|
| 370 | - $conf_inst=SugarConfig::getInstance(); |
|
| 369 | + if (!is_windows()) { |
|
| 370 | + $conf_inst = SugarConfig::getInstance(); |
|
| 371 | 371 | $mode = $conf_inst->get('default_permissions.'.$key, $mode); |
| 372 | 372 | } |
| 373 | 373 | return $mode; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | -function sugar_is_dir($path, $mode='r'){ |
|
| 377 | - if(defined('TEMPLATE_URL'))return is_dir($path, $mode); |
|
| 376 | +function sugar_is_dir($path, $mode = 'r') { |
|
| 377 | + if (defined('TEMPLATE_URL'))return is_dir($path, $mode); |
|
| 378 | 378 | return is_dir($path); |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | -function sugar_is_file($path, $mode='r'){ |
|
| 382 | - if(defined('TEMPLATE_URL'))return is_file($path, $mode); |
|
| 381 | +function sugar_is_file($path, $mode = 'r') { |
|
| 382 | + if (defined('TEMPLATE_URL'))return is_file($path, $mode); |
|
| 383 | 383 | return is_file($path); |
| 384 | 384 | } |
| 385 | 385 | |
@@ -391,10 +391,10 @@ discard block |
||
| 391 | 391 | function sugar_cached($file) |
| 392 | 392 | { |
| 393 | 393 | static $cdir = null; |
| 394 | - if(empty($cdir) && !empty($GLOBALS['sugar_config']['cache_dir'])) { |
|
| 394 | + if (empty($cdir) && !empty($GLOBALS['sugar_config']['cache_dir'])) { |
|
| 395 | 395 | $cdir = rtrim($GLOBALS['sugar_config']['cache_dir'], '/\\'); |
| 396 | 396 | } |
| 397 | - if(empty($cdir)) { |
|
| 397 | + if (empty($cdir)) { |
|
| 398 | 398 | $cdir = "cache"; |
| 399 | 399 | } |
| 400 | 400 | return "$cdir/$file"; |
@@ -1,5 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -56,12 +58,14 @@ discard block |
||
| 56 | 58 | function sugar_mkdir($pathname, $mode=null, $recursive=false, $context='') { |
| 57 | 59 | $mode = get_mode('dir_mode', $mode); |
| 58 | 60 | |
| 59 | - if ( sugar_is_dir($pathname,$mode) ) |
|
| 60 | - return true; |
|
| 61 | + if ( sugar_is_dir($pathname,$mode) ) { |
|
| 62 | + return true; |
|
| 63 | + } |
|
| 61 | 64 | |
| 62 | 65 | $result = false; |
| 63 | - if(empty($mode)) |
|
| 64 | - $mode = 0777; |
|
| 66 | + if(empty($mode)) { |
|
| 67 | + $mode = 0777; |
|
| 68 | + } |
|
| 65 | 69 | if(empty($context)) { |
| 66 | 70 | $result = @mkdir($pathname, $mode, $recursive); |
| 67 | 71 | } else { |
@@ -82,8 +86,7 @@ discard block |
||
| 82 | 86 | return false; |
| 83 | 87 | } |
| 84 | 88 | } |
| 85 | - } |
|
| 86 | - else { |
|
| 89 | + } else { |
|
| 87 | 90 | $errorMessage = "Cannot create directory $pathname cannot be touched"; |
| 88 | 91 | if(is_null($GLOBALS['log'])) { |
| 89 | 92 | throw new Exception("Error occurred but the system doesn't have logger. Error message: \"$errorMessage\""); |
@@ -285,15 +288,16 @@ discard block |
||
| 285 | 288 | * @return boolean Returns TRUE on success or FALSE on failure. |
| 286 | 289 | */ |
| 287 | 290 | function sugar_chmod($filename, $mode=null) { |
| 288 | - if ( !is_int($mode) ) |
|
| 289 | - $mode = (int) $mode; |
|
| 291 | + if ( !is_int($mode) ) { |
|
| 292 | + $mode = (int) $mode; |
|
| 293 | + } |
|
| 290 | 294 | if(!is_windows()){ |
| 291 | 295 | if(!isset($mode)){ |
| 292 | 296 | $mode = get_mode('file_mode', $mode); |
| 293 | 297 | } |
| 294 | 298 | if(isset($mode) && $mode > 0){ |
| 295 | 299 | return @chmod($filename, $mode); |
| 296 | - }else{ |
|
| 300 | + } else{ |
|
| 297 | 301 | return false; |
| 298 | 302 | } |
| 299 | 303 | } |
@@ -313,11 +317,11 @@ discard block |
||
| 313 | 317 | if(!is_windows()){ |
| 314 | 318 | if(strlen($user)){ |
| 315 | 319 | return chown($filename, $user); |
| 316 | - }else{ |
|
| 320 | + } else{ |
|
| 317 | 321 | if(strlen($GLOBALS['sugar_config']['default_permissions']['user'])){ |
| 318 | 322 | $user = $GLOBALS['sugar_config']['default_permissions']['user']; |
| 319 | 323 | return chown($filename, $user); |
| 320 | - }else{ |
|
| 324 | + } else{ |
|
| 321 | 325 | return false; |
| 322 | 326 | } |
| 323 | 327 | } |
@@ -338,11 +342,11 @@ discard block |
||
| 338 | 342 | if(!is_windows()){ |
| 339 | 343 | if(!empty($group)){ |
| 340 | 344 | return chgrp($filename, $group); |
| 341 | - }else{ |
|
| 345 | + } else{ |
|
| 342 | 346 | if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){ |
| 343 | 347 | $group = $GLOBALS['sugar_config']['default_permissions']['group']; |
| 344 | 348 | return chgrp($filename, $group); |
| 345 | - }else{ |
|
| 349 | + } else{ |
|
| 346 | 350 | return false; |
| 347 | 351 | } |
| 348 | 352 | } |
@@ -361,8 +365,9 @@ discard block |
||
| 361 | 365 | * @return int - the mode either found in the config file or passed in via the input parameter |
| 362 | 366 | */ |
| 363 | 367 | function get_mode($key = 'dir_mode', $mode=null) { |
| 364 | - if ( !is_int($mode) ) |
|
| 365 | - $mode = (int) $mode; |
|
| 368 | + if ( !is_int($mode) ) { |
|
| 369 | + $mode = (int) $mode; |
|
| 370 | + } |
|
| 366 | 371 | if(!class_exists('SugarConfig', true)) { |
| 367 | 372 | require 'include/SugarObjects/SugarConfig.php'; |
| 368 | 373 | } |
@@ -374,12 +379,16 @@ discard block |
||
| 374 | 379 | } |
| 375 | 380 | |
| 376 | 381 | function sugar_is_dir($path, $mode='r'){ |
| 377 | - if(defined('TEMPLATE_URL'))return is_dir($path, $mode); |
|
| 382 | + if(defined('TEMPLATE_URL')) { |
|
| 383 | + return is_dir($path, $mode); |
|
| 384 | + } |
|
| 378 | 385 | return is_dir($path); |
| 379 | 386 | } |
| 380 | 387 | |
| 381 | 388 | function sugar_is_file($path, $mode='r'){ |
| 382 | - if(defined('TEMPLATE_URL'))return is_file($path, $mode); |
|
| 389 | + if(defined('TEMPLATE_URL')) { |
|
| 390 | + return is_file($path, $mode); |
|
| 391 | + } |
|
| 383 | 392 | return is_file($path); |
| 384 | 393 | } |
| 385 | 394 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * 0777 by default. |
| 49 | 49 | * |
| 50 | 50 | * @param $pathname - String value of the directory to create |
| 51 | - * @param $mode - The integer value of the permissions mode to set the created directory to |
|
| 51 | + * @param integer $mode - The integer value of the permissions mode to set the created directory to |
|
| 52 | 52 | * @param $recursive - boolean value indicating whether or not to create recursive directories if needed |
| 53 | 53 | * @param $context |
| 54 | 54 | * @return boolean - Returns true on success false on failure |
@@ -103,10 +103,10 @@ discard block |
||
| 103 | 103 | * 0777 by default. |
| 104 | 104 | * |
| 105 | 105 | * @param $filename - String value of the file to create |
| 106 | - * @param $mode - The integer value of the permissions mode to set the created file to |
|
| 106 | + * @param string $mode - The integer value of the permissions mode to set the created file to |
|
| 107 | 107 | * @param $$use_include_path - boolean value indicating whether or not to search the the included_path |
| 108 | 108 | * @param $context |
| 109 | - * @return boolean - Returns a file pointer on success, false otherwise |
|
| 109 | + * @return resource - Returns a file pointer on success, false otherwise |
|
| 110 | 110 | */ |
| 111 | 111 | function sugar_fopen($filename, $mode, $use_include_path=false, $context=null){ |
| 112 | 112 | //check to see if the file exists, if not then use touch to create it. |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @param $filename - String value of the file to create |
| 134 | 134 | * @param $data - The data to be written to the file |
| 135 | - * @param $flags - int as specifed by file_put_contents parameters |
|
| 135 | + * @param integer $flags - int as specifed by file_put_contents parameters |
|
| 136 | 136 | * @param $context |
| 137 | 137 | * @return int - Returns the number of bytes written to the file, false otherwise. |
| 138 | 138 | */ |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | * This is an atomic version of sugar_file_put_contents. It attempts to circumvent the shortcomings of file_put_contents |
| 163 | 163 | * by creating a temporary unique file and then doing an atomic rename operation. |
| 164 | 164 | * |
| 165 | - * @param $filename - String value of the file to create |
|
| 166 | - * @param $data - The data to be written to the file |
|
| 165 | + * @param string $filename - String value of the file to create |
|
| 166 | + * @param string $data - The data to be written to the file |
|
| 167 | 167 | * @param string $mode String value of the parameter to specify the type of access you require to the file stream |
| 168 | 168 | * @param boolean $use_include_path set to '1' or TRUE if you want to search for the file in the include_path too |
| 169 | 169 | * @param context $context Context to pass into fopen operation |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param $filename - String value of the file to create |
| 213 | 213 | * @param $use_include_path - boolean value indicating whether or not to search the the included_path |
| 214 | 214 | * @param $context |
| 215 | - * @return string|boolean - Returns a file data on success, false otherwise |
|
| 215 | + * @return false|string - Returns a file data on success, false otherwise |
|
| 216 | 216 | */ |
| 217 | 217 | function sugar_file_get_contents($filename, $use_include_path=false, $context=null){ |
| 218 | 218 | //check to see if the file exists, if not then use touch to create it. |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * may be set with the permissions specified in the configuration file (if set). |
| 242 | 242 | * |
| 243 | 243 | * @param $filename - The name of the file being touched. |
| 244 | - * @param $time - The touch time. If time is not supplied, the current system time is used. |
|
| 244 | + * @param integer $time - The touch time. If time is not supplied, the current system time is used. |
|
| 245 | 245 | * @param $atime - If present, the access time of the given filename is set to the value of atime |
| 246 | 246 | * @return boolean - Returns TRUE on success or FALSE on failure. |
| 247 | 247 | * |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | ); |
| 238 | 238 | $adminOnlyList = array( |
| 239 | 239 | //module => list of actions (all says all actions are admin only) |
| 240 | - //'Administration'=>array('all'=>1, 'SupportPortal'=>'allow'), |
|
| 240 | + //'Administration'=>array('all'=>1, 'SupportPortal'=>'allow'), |
|
| 241 | 241 | 'Dropdown'=>array('all'=>1), |
| 242 | 242 | 'Dynamic'=>array('all'=>1), |
| 243 | 243 | 'DynamicFields'=>array('all'=>1), |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | 'DocumentRevisions' => 'Documents', |
| 295 | 295 | 'EmailTemplates' => 'Emails', |
| 296 | 296 | 'EmailMarketing' => 'Campaigns', |
| 297 | - ); |
|
| 297 | + ); |
|
| 298 | 298 | $beanList['EAPM'] = 'EAPM'; |
| 299 | 299 | $beanFiles['EAPM'] = 'modules/EAPM/EAPM.php'; |
| 300 | 300 | $modules_exempt_from_availability_check['EAPM'] = 'EAPM'; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 3 | 3 | /********************************************************************************* |
| 4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -79,18 +79,18 @@ discard block |
||
| 79 | 79 | $beanList['Cases'] = 'aCase'; |
| 80 | 80 | $beanList['Bugs'] = 'Bug'; |
| 81 | 81 | $beanList['ProspectLists'] = 'ProspectList'; |
| 82 | -$beanList['Prospects'] = 'Prospect'; |
|
| 82 | +$beanList['Prospects'] = 'Prospect'; |
|
| 83 | 83 | $beanList['Project'] = 'Project'; |
| 84 | -$beanList['ProjectTask'] = 'ProjectTask'; |
|
| 84 | +$beanList['ProjectTask'] = 'ProjectTask'; |
|
| 85 | 85 | $beanList['Campaigns'] = 'Campaign'; |
| 86 | -$beanList['EmailMarketing'] = 'EmailMarketing'; |
|
| 86 | +$beanList['EmailMarketing'] = 'EmailMarketing'; |
|
| 87 | 87 | $beanList['CampaignLog'] = 'CampaignLog'; |
| 88 | 88 | $beanList['CampaignTrackers'] = 'CampaignTracker'; |
| 89 | -$beanList['Releases'] = 'Release'; |
|
| 89 | +$beanList['Releases'] = 'Release'; |
|
| 90 | 90 | $beanList['Groups'] = 'Group'; |
| 91 | 91 | $beanList['EmailMan'] = 'EmailMan'; |
| 92 | -$beanList['Schedulers'] = 'Scheduler'; |
|
| 93 | -$beanList['SchedulersJobs'] = 'SchedulersJob'; |
|
| 92 | +$beanList['Schedulers'] = 'Scheduler'; |
|
| 93 | +$beanList['SchedulersJobs'] = 'SchedulersJob'; |
|
| 94 | 94 | $beanList['Contacts'] = 'Contact'; |
| 95 | 95 | $beanList['Accounts'] = 'Account'; |
| 96 | 96 | $beanList['DynamicFields'] = 'DynamicField'; |
@@ -106,19 +106,19 @@ discard block |
||
| 106 | 106 | $beanList['Currencies'] = 'Currency'; |
| 107 | 107 | $beanList['Trackers'] = 'Tracker'; |
| 108 | 108 | $beanList['Connectors'] = 'Connectors'; |
| 109 | -$beanList['Import_1'] = 'ImportMap'; |
|
| 109 | +$beanList['Import_1'] = 'ImportMap'; |
|
| 110 | 110 | $beanList['Import_2'] = 'UsersLastImport'; |
| 111 | 111 | $beanList['Versions'] = 'Version'; |
| 112 | 112 | $beanList['Administration'] = 'Administration'; |
| 113 | 113 | $beanList['vCals'] = 'vCal'; |
| 114 | 114 | $beanList['CustomFields'] = 'CustomFields'; |
| 115 | -$beanList['Alerts'] = 'Alert'; |
|
| 115 | +$beanList['Alerts'] = 'Alert'; |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | |
| 119 | 119 | |
| 120 | -$beanList['Documents'] = 'Document'; |
|
| 121 | -$beanList['DocumentRevisions'] = 'DocumentRevision'; |
|
| 120 | +$beanList['Documents'] = 'Document'; |
|
| 121 | +$beanList['DocumentRevisions'] = 'DocumentRevision'; |
|
| 122 | 122 | $beanList['Roles'] = 'Role'; |
| 123 | 123 | |
| 124 | 124 | $beanList['Audit'] = 'Audit'; |
@@ -152,24 +152,24 @@ discard block |
||
| 152 | 152 | $beanFiles['aCase'] = 'modules/Cases/Case.php'; |
| 153 | 153 | $beanFiles['Bug'] = 'modules/Bugs/Bug.php'; |
| 154 | 154 | $beanFiles['Group'] = 'modules/Groups/Group.php'; |
| 155 | -$beanFiles['CampaignLog'] = 'modules/CampaignLog/CampaignLog.php'; |
|
| 155 | +$beanFiles['CampaignLog'] = 'modules/CampaignLog/CampaignLog.php'; |
|
| 156 | 156 | $beanFiles['Project'] = 'modules/Project/Project.php'; |
| 157 | -$beanFiles['ProjectTask'] = 'modules/ProjectTask/ProjectTask.php'; |
|
| 157 | +$beanFiles['ProjectTask'] = 'modules/ProjectTask/ProjectTask.php'; |
|
| 158 | 158 | $beanFiles['Campaign'] = 'modules/Campaigns/Campaign.php'; |
| 159 | 159 | $beanFiles['ProspectList'] = 'modules/ProspectLists/ProspectList.php'; |
| 160 | -$beanFiles['Prospect'] = 'modules/Prospects/Prospect.php'; |
|
| 160 | +$beanFiles['Prospect'] = 'modules/Prospects/Prospect.php'; |
|
| 161 | 161 | |
| 162 | -$beanFiles['EmailMarketing'] = 'modules/EmailMarketing/EmailMarketing.php'; |
|
| 163 | -$beanFiles['CampaignTracker'] = 'modules/CampaignTrackers/CampaignTracker.php'; |
|
| 162 | +$beanFiles['EmailMarketing'] = 'modules/EmailMarketing/EmailMarketing.php'; |
|
| 163 | +$beanFiles['CampaignTracker'] = 'modules/CampaignTrackers/CampaignTracker.php'; |
|
| 164 | 164 | $beanFiles['Release'] = 'modules/Releases/Release.php'; |
| 165 | 165 | $beanFiles['EmailMan'] = 'modules/EmailMan/EmailMan.php'; |
| 166 | 166 | |
| 167 | -$beanFiles['Scheduler'] = 'modules/Schedulers/Scheduler.php'; |
|
| 168 | -$beanFiles['SchedulersJob'] = 'modules/SchedulersJobs/SchedulersJob.php'; |
|
| 167 | +$beanFiles['Scheduler'] = 'modules/Schedulers/Scheduler.php'; |
|
| 168 | +$beanFiles['SchedulersJob'] = 'modules/SchedulersJobs/SchedulersJob.php'; |
|
| 169 | 169 | $beanFiles['Contact'] = 'modules/Contacts/Contact.php'; |
| 170 | 170 | $beanFiles['Account'] = 'modules/Accounts/Account.php'; |
| 171 | 171 | $beanFiles['Opportunity'] = 'modules/Opportunities/Opportunity.php'; |
| 172 | -$beanFiles['EmailTemplate'] = 'modules/EmailTemplates/EmailTemplate.php'; |
|
| 172 | +$beanFiles['EmailTemplate'] = 'modules/EmailTemplates/EmailTemplate.php'; |
|
| 173 | 173 | $beanFiles['Note'] = 'modules/Notes/Note.php'; |
| 174 | 174 | $beanFiles['Call'] = 'modules/Calls/Call.php'; |
| 175 | 175 | $beanFiles['Email'] = 'modules/Emails/Email.php'; |
@@ -177,21 +177,21 @@ discard block |
||
| 177 | 177 | $beanFiles['Task'] = 'modules/Tasks/Task.php'; |
| 178 | 178 | $beanFiles['User'] = 'modules/Users/User.php'; |
| 179 | 179 | $beanFiles['Employee'] = 'modules/Employees/Employee.php'; |
| 180 | -$beanFiles['Currency'] = 'modules/Currencies/Currency.php'; |
|
| 181 | -$beanFiles['Tracker'] = 'modules/Trackers/Tracker.php'; |
|
| 180 | +$beanFiles['Currency'] = 'modules/Currencies/Currency.php'; |
|
| 181 | +$beanFiles['Tracker'] = 'modules/Trackers/Tracker.php'; |
|
| 182 | 182 | $beanFiles['ImportMap'] = 'modules/Import/maps/ImportMap.php'; |
| 183 | -$beanFiles['UsersLastImport']= 'modules/Import/UsersLastImport.php'; |
|
| 184 | -$beanFiles['Administration']= 'modules/Administration/Administration.php'; |
|
| 185 | -$beanFiles['UpgradeHistory']= 'modules/Administration/UpgradeHistory.php'; |
|
| 183 | +$beanFiles['UsersLastImport'] = 'modules/Import/UsersLastImport.php'; |
|
| 184 | +$beanFiles['Administration'] = 'modules/Administration/Administration.php'; |
|
| 185 | +$beanFiles['UpgradeHistory'] = 'modules/Administration/UpgradeHistory.php'; |
|
| 186 | 186 | $beanFiles['vCal'] = 'modules/vCals/vCal.php'; |
| 187 | -$beanFiles['Alert'] = 'modules/Alerts/Alert.php'; |
|
| 188 | -$beanFiles['Version'] = 'modules/Versions/Version.php'; |
|
| 187 | +$beanFiles['Alert'] = 'modules/Alerts/Alert.php'; |
|
| 188 | +$beanFiles['Version'] = 'modules/Versions/Version.php'; |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | |
| 192 | -$beanFiles['Role'] = 'modules/Roles/Role.php'; |
|
| 192 | +$beanFiles['Role'] = 'modules/Roles/Role.php'; |
|
| 193 | 193 | |
| 194 | -$beanFiles['Document'] = 'modules/Documents/Document.php'; |
|
| 194 | +$beanFiles['Document'] = 'modules/Documents/Document.php'; |
|
| 195 | 195 | $beanFiles['DocumentRevision'] = 'modules/DocumentRevisions/DocumentRevision.php'; |
| 196 | 196 | $beanFiles['FieldsMetaData'] = 'modules/DynamicFields/FieldsMetaData.php'; |
| 197 | 197 | //$beanFiles['Audit'] = 'modules/Audit/Audit.php'; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | $beanFiles['SavedSearch'] = 'modules/SavedSearch/SavedSearch.php'; |
| 207 | -$beanFiles['UserPreference'] = 'modules/UserPreferences/UserPreference.php'; |
|
| 207 | +$beanFiles['UserPreference'] = 'modules/UserPreferences/UserPreference.php'; |
|
| 208 | 208 | $beanFiles['MergeRecord'] = 'modules/MergeRecords/MergeRecord.php'; |
| 209 | 209 | $beanFiles['EmailAddress'] = 'modules/EmailAddresses/EmailAddress.php'; |
| 210 | 210 | $beanFiles['EmailText'] = 'modules/EmailText/EmailText.php'; |
@@ -216,19 +216,19 @@ discard block |
||
| 216 | 216 | //$beanList['Library']= 'Library'; |
| 217 | 217 | //$beanFiles['Library'] = 'modules/Library/Library.php'; |
| 218 | 218 | |
| 219 | -$beanFiles['Configurator'] = 'modules/Configurator/Configurator.php'; |
|
| 219 | +$beanFiles['Configurator'] = 'modules/Configurator/Configurator.php'; |
|
| 220 | 220 | |
| 221 | 221 | // added these lists for security settings for tabs |
| 222 | 222 | $modInvisList = array('Administration', 'Currencies', 'CustomFields', 'Connectors', |
| 223 | 223 | 'Dropdown', 'Dynamic', 'DynamicFields', 'DynamicLayout', 'EditCustomFields', |
| 224 | - 'Help', 'Import', 'MySettings', 'EditCustomFields','FieldsMetaData', |
|
| 224 | + 'Help', 'Import', 'MySettings', 'EditCustomFields', 'FieldsMetaData', |
|
| 225 | 225 | 'UpgradeWizard', 'Trackers', 'Connectors', 'Employees', 'Calendar', |
| 226 | - 'Releases','Sync', |
|
| 227 | - 'Users', 'Versions', 'LabelEditor','Roles','EmailMarketing' |
|
| 228 | - ,'OptimisticLock', 'TeamMemberships', 'TeamSets', 'TeamSetModule', 'Audit', 'MailMerge', 'MergeRecords', 'EmailAddresses','EmailText', |
|
| 229 | - 'Schedulers','Schedulers_jobs', /*'Queues',*/ 'EmailTemplates', |
|
| 226 | + 'Releases', 'Sync', |
|
| 227 | + 'Users', 'Versions', 'LabelEditor', 'Roles', 'EmailMarketing' |
|
| 228 | + ,'OptimisticLock', 'TeamMemberships', 'TeamSets', 'TeamSetModule', 'Audit', 'MailMerge', 'MergeRecords', 'EmailAddresses', 'EmailText', |
|
| 229 | + 'Schedulers', 'Schedulers_jobs', /*'Queues',*/ 'EmailTemplates', |
|
| 230 | 230 | 'CampaignTrackers', 'CampaignLog', 'EmailMan', 'Prospects', 'ProspectLists', |
| 231 | - 'Groups','InboundEmail', |
|
| 231 | + 'Groups', 'InboundEmail', |
|
| 232 | 232 | 'ACLActions', 'ACLRoles', |
| 233 | 233 | 'DocumentRevisions', |
| 234 | 234 | 'ProjectTask', |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | $modInvisList[] = 'Connectors'; |
| 266 | 266 | |
| 267 | 267 | $report_include_modules = array(); |
| 268 | -$report_include_modules['Currencies']='Currency'; |
|
| 268 | +$report_include_modules['Currencies'] = 'Currency'; |
|
| 269 | 269 | //add prospects |
| 270 | -$report_include_modules['Prospects']='Prospect'; |
|
| 270 | +$report_include_modules['Prospects'] = 'Prospect'; |
|
| 271 | 271 | $report_include_modules['DocumentRevisions'] = 'DocumentRevision'; |
| 272 | 272 | $report_include_modules['ProductCategories'] = 'ProductCategory'; |
| 273 | 273 | $report_include_modules['ProductTypes'] = 'ProductType'; |
| 274 | 274 | //add Tracker modules |
| 275 | 275 | |
| 276 | -$report_include_modules['Trackers'] = 'Tracker'; |
|
| 276 | +$report_include_modules['Trackers'] = 'Tracker'; |
|
| 277 | 277 | |
| 278 | 278 | |
| 279 | 279 | |
@@ -323,9 +323,9 @@ discard block |
||
| 323 | 323 | //the bean class name == dictionary entry/object name convention |
| 324 | 324 | //No future module should need an entry here. |
| 325 | 325 | $objectList = array(); |
| 326 | -$objectList['Cases'] = 'Case'; |
|
| 327 | -$objectList['Groups'] = 'User'; |
|
| 328 | -$objectList['Users'] = 'User'; |
|
| 326 | +$objectList['Cases'] = 'Case'; |
|
| 327 | +$objectList['Groups'] = 'User'; |
|
| 328 | +$objectList['Users'] = 'User'; |
|
| 329 | 329 | |
| 330 | 330 | |
| 331 | 331 | // knowledge base |
@@ -1,5 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
| 2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
| 3 | + die('Not A Valid Entry Point'); |
|
| 4 | +} |
|
| 3 | 5 | /********************************************************************************* |
| 4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
| 5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | var $templateDir = 'modules/'; |
| 51 | 51 | var $ss; |
| 52 | 52 | function TemplateHandler() { |
| 53 | - $this->cacheDir = sugar_cached(''); |
|
| 53 | + $this->cacheDir = sugar_cached(''); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | function loadSmarty(){ |
@@ -66,10 +66,10 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | */ |
| 68 | 68 | static function clearAll() { |
| 69 | - global $beanList; |
|
| 70 | - foreach($beanList as $module_dir =>$object_name){ |
|
| 69 | + global $beanList; |
|
| 70 | + foreach($beanList as $module_dir =>$object_name){ |
|
| 71 | 71 | TemplateHandler::clearCache($module_dir); |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | foreach($panel as $row) { |
| 133 | 133 | foreach($row as $entry) { |
| 134 | 134 | if(empty($entry)) { |
| 135 | - continue; |
|
| 135 | + continue; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | if(is_array($entry) && |
@@ -140,35 +140,35 @@ discard block |
||
| 140 | 140 | isset($entry['displayParams']) && |
| 141 | 141 | isset($entry['displayParams']['required']) && |
| 142 | 142 | $entry['displayParams']['required']) { |
| 143 | - $panelFields[$entry['name']] = $entry; |
|
| 143 | + $panelFields[$entry['name']] = $entry; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if(is_array($entry)) { |
| 147 | - $defs2[$entry['name']] = $entry; |
|
| 147 | + $defs2[$entry['name']] = $entry; |
|
| 148 | 148 | } else { |
| 149 | - $defs2[$entry] = array('name' => $entry); |
|
| 149 | + $defs2[$entry] = array('name' => $entry); |
|
| 150 | 150 | } |
| 151 | 151 | } //foreach |
| 152 | 152 | } //foreach |
| 153 | 153 | } //foreach |
| 154 | 154 | |
| 155 | 155 | foreach($panelFields as $field=>$value) { |
| 156 | - $nameList = array(); |
|
| 157 | - if(!is_array($value['displayParams']['required'])) { |
|
| 158 | - $nameList[] = $field; |
|
| 159 | - } else { |
|
| 160 | - foreach($value['displayParams']['required'] as $groupedField) { |
|
| 161 | - $nameList[] = $groupedField; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - foreach($nameList as $x) { |
|
| 166 | - if(isset($defs[$x]) && |
|
| 156 | + $nameList = array(); |
|
| 157 | + if(!is_array($value['displayParams']['required'])) { |
|
| 158 | + $nameList[] = $field; |
|
| 159 | + } else { |
|
| 160 | + foreach($value['displayParams']['required'] as $groupedField) { |
|
| 161 | + $nameList[] = $groupedField; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + foreach($nameList as $x) { |
|
| 166 | + if(isset($defs[$x]) && |
|
| 167 | 167 | isset($defs[$x]['type']) && |
| 168 | 168 | !isset($defs[$x]['required'])) { |
| 169 | 169 | $defs[$x]['required'] = true; |
| 170 | - } |
|
| 171 | - } |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | 172 | } //foreach |
| 173 | 173 | |
| 174 | 174 | //Create a base class with field_name_map property |
@@ -195,23 +195,23 @@ discard block |
||
| 195 | 195 | //5) not already been added to Array |
| 196 | 196 | foreach($sugarbean->field_name_map as $name=>$def) { |
| 197 | 197 | |
| 198 | - if($def['type']=='relate' && |
|
| 198 | + if($def['type']=='relate' && |
|
| 199 | 199 | isset($defs2[$name]) && |
| 200 | 200 | (!isset($defs2[$name]['validateDependency']) || $defs2[$name]['validateDependency'] === true) && |
| 201 | 201 | isset($def['id_name']) && |
| 202 | 202 | !in_array($name, $validatedFields)) { |
| 203 | 203 | |
| 204 | - if(isset($mod_strings[$def['vname']]) |
|
| 204 | + if(isset($mod_strings[$def['vname']]) |
|
| 205 | 205 | || isset($app_strings[$def['vname']]) |
| 206 | 206 | || translate($def['vname'],$sugarbean->module_dir) != $def['vname']) { |
| 207 | - $vname = $def['vname']; |
|
| 208 | - } |
|
| 209 | - else{ |
|
| 210 | - $vname = "undefined"; |
|
| 211 | - } |
|
| 212 | - $javascript->addToValidateBinaryDependency($name, 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty($vname), (!empty($def['required']) ? 'true' : 'false'), '', $def['id_name']); |
|
| 213 | - $validatedFields[] = $name; |
|
| 214 | - } |
|
| 207 | + $vname = $def['vname']; |
|
| 208 | + } |
|
| 209 | + else{ |
|
| 210 | + $vname = "undefined"; |
|
| 211 | + } |
|
| 212 | + $javascript->addToValidateBinaryDependency($name, 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty($vname), (!empty($def['required']) ? 'true' : 'false'), '', $def['id_name']); |
|
| 213 | + $validatedFields[] = $name; |
|
| 214 | + } |
|
| 215 | 215 | } //foreach |
| 216 | 216 | |
| 217 | 217 | $contents .= "{literal}\n"; |
@@ -275,11 +275,11 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | $file = $this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl'; |
| 277 | 277 | if(file_exists($file)) { |
| 278 | - return $this->ss->fetch($file); |
|
| 278 | + return $this->ss->fetch($file); |
|
| 279 | 279 | } else { |
| 280 | - global $app_strings; |
|
| 281 | - $GLOBALS['log']->fatal($app_strings['ERR_NO_SUCH_FILE'] .": $file"); |
|
| 282 | - return $app_strings['ERR_NO_SUCH_FILE'] .": $file"; |
|
| 280 | + global $app_strings; |
|
| 281 | + $GLOBALS['log']->fatal($app_strings['ERR_NO_SUCH_FILE'] .": $file"); |
|
| 282 | + return $app_strings['ERR_NO_SUCH_FILE'] .": $file"; |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
@@ -329,13 +329,13 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | $qsd->setFormName($view); |
| 331 | 331 | if(preg_match('/^SearchForm_.+/', $view)){ |
| 332 | - if(strpos($view, 'popup_query_form')){ |
|
| 333 | - $qsd->setFormName('popup_query_form'); |
|
| 334 | - $parsedView = 'advanced'; |
|
| 335 | - }else{ |
|
| 336 | - $qsd->setFormName('search_form'); |
|
| 337 | - $parsedView = preg_replace("/^SearchForm_/", "", $view); |
|
| 338 | - } |
|
| 332 | + if(strpos($view, 'popup_query_form')){ |
|
| 333 | + $qsd->setFormName('popup_query_form'); |
|
| 334 | + $parsedView = 'advanced'; |
|
| 335 | + }else{ |
|
| 336 | + $qsd->setFormName('search_form'); |
|
| 337 | + $parsedView = preg_replace("/^SearchForm_/", "", $view); |
|
| 338 | + } |
|
| 339 | 339 | //Loop through the Meta-Data fields to see which ones need quick search support |
| 340 | 340 | foreach($defs as $f) { |
| 341 | 341 | $field = $f; |
@@ -373,14 +373,14 @@ discard block |
||
| 373 | 373 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSContact($field['name'], $field['id_name']); |
| 374 | 374 | } |
| 375 | 375 | } else { |
| 376 | - $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent($field['module']); |
|
| 377 | - if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
|
| 378 | - $sqs_objects[$name.'_'.$parsedView]['populate_list'] = array($field['name'], $field['id_name']); |
|
| 379 | - $sqs_objects[$name.'_'.$parsedView]['field_list'] = array('name', 'id'); |
|
| 380 | - } else { |
|
| 381 | - $sqs_objects[$name.'_'.$parsedView]['populate_list'] = $field['field_list']; |
|
| 382 | - $sqs_objects[$name.'_'.$parsedView]['field_list'] = $field['populate_list']; |
|
| 383 | - } |
|
| 376 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent($field['module']); |
|
| 377 | + if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
|
| 378 | + $sqs_objects[$name.'_'.$parsedView]['populate_list'] = array($field['name'], $field['id_name']); |
|
| 379 | + $sqs_objects[$name.'_'.$parsedView]['field_list'] = array('name', 'id'); |
|
| 380 | + } else { |
|
| 381 | + $sqs_objects[$name.'_'.$parsedView]['populate_list'] = $field['field_list']; |
|
| 382 | + $sqs_objects[$name.'_'.$parsedView]['field_list'] = $field['populate_list']; |
|
| 383 | + } |
|
| 384 | 384 | } |
| 385 | 385 | } else if($field['type'] == 'parent') { |
| 386 | 386 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent(); |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | } //foreach |
| 389 | 389 | |
| 390 | 390 | foreach ( $sqs_objects as $name => $field ) |
| 391 | - foreach ( $field['populate_list'] as $key => $fieldname ) |
|
| 391 | + foreach ( $field['populate_list'] as $key => $fieldname ) |
|
| 392 | 392 | $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key] . '_'.$parsedView; |
| 393 | 393 | }else{ |
| 394 | 394 | //Loop through the Meta-Data fields to see which ones need quick search support |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | $field['id_name'] = $module.$field['id_name']; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | - $name = $qsd->form_name . '_' . $field['name']; |
|
| 416 | + $name = $qsd->form_name . '_' . $field['name']; |
|
| 417 | 417 | |
| 418 | 418 | |
| 419 | 419 | if($field['type'] == 'relate' && isset($field['module']) && (preg_match('/_name$|_c$/si',$name) || !empty($field['quicksearch']))) { |
@@ -427,15 +427,15 @@ discard block |
||
| 427 | 427 | } else if($matches[0] == 'Users'){ |
| 428 | 428 | if($field['name'] == 'reports_to_name'){ |
| 429 | 429 | $sqs_objects[$name] = $qsd->getQSUser('reports_to_name','reports_to_id'); |
| 430 | - // Bug #52994 : QuickSearch for a 1-M User relationship changes assigned to user |
|
| 430 | + // Bug #52994 : QuickSearch for a 1-M User relationship changes assigned to user |
|
| 431 | 431 | }elseif($field['name'] == 'assigned_user_name'){ |
| 432 | - $sqs_objects[$name] = $qsd->getQSUser('assigned_user_name','assigned_user_id'); |
|
| 433 | - } |
|
| 434 | - else |
|
| 435 | - { |
|
| 436 | - $sqs_objects[$name] = $qsd->getQSUser($field['name'], $field['id_name']); |
|
| 432 | + $sqs_objects[$name] = $qsd->getQSUser('assigned_user_name','assigned_user_id'); |
|
| 433 | + } |
|
| 434 | + else |
|
| 435 | + { |
|
| 436 | + $sqs_objects[$name] = $qsd->getQSUser($field['name'], $field['id_name']); |
|
| 437 | 437 | |
| 438 | - } |
|
| 438 | + } |
|
| 439 | 439 | } else if($matches[0] == 'Campaigns') { |
| 440 | 440 | $sqs_objects[$name] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
| 441 | 441 | } else if($matches[0] == 'Accounts') { |
@@ -486,39 +486,39 @@ discard block |
||
| 486 | 486 | //merge populate_list && field_list with vardef |
| 487 | 487 | if (!empty($field['field_list']) && !empty($field['populate_list'])) { |
| 488 | 488 | for ($j=0; $j<count($field['field_list']); $j++) { |
| 489 | - //search for the same couple (field_list_item,populate_field_item) |
|
| 490 | - $field_list_item = $field['field_list'][$j]; |
|
| 491 | - $field_list_item_alternate = $qsd->form_name . '_' . $field['field_list'][$j]; |
|
| 492 | - $populate_list_item = $field['populate_list'][$j]; |
|
| 493 | - $found = false; |
|
| 494 | - for ($k=0; $k<count($sqs_objects[$name]['field_list']); $k++) { |
|
| 495 | - if (($field_list_item == $sqs_objects[$name]['populate_list'][$k] || $field_list_item_alternate == $sqs_objects[$name]['populate_list'][$k]) && //il faut inverser field_list et populate_list (cf lignes 465,466 ci-dessus) |
|
| 496 | - $populate_list_item == $sqs_objects[$name]['field_list'][$k]) { |
|
| 497 | - $found = true; |
|
| 498 | - break; |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - if (!$found) { |
|
| 502 | - $sqs_objects[$name]['field_list'][] = $field['populate_list'][$j]; // as in lines 462 and 463 |
|
| 503 | - $sqs_objects[$name]['populate_list'][] = $field['field_list'][$j]; |
|
| 504 | - } |
|
| 505 | - } |
|
| 489 | + //search for the same couple (field_list_item,populate_field_item) |
|
| 490 | + $field_list_item = $field['field_list'][$j]; |
|
| 491 | + $field_list_item_alternate = $qsd->form_name . '_' . $field['field_list'][$j]; |
|
| 492 | + $populate_list_item = $field['populate_list'][$j]; |
|
| 493 | + $found = false; |
|
| 494 | + for ($k=0; $k<count($sqs_objects[$name]['field_list']); $k++) { |
|
| 495 | + if (($field_list_item == $sqs_objects[$name]['populate_list'][$k] || $field_list_item_alternate == $sqs_objects[$name]['populate_list'][$k]) && //il faut inverser field_list et populate_list (cf lignes 465,466 ci-dessus) |
|
| 496 | + $populate_list_item == $sqs_objects[$name]['field_list'][$k]) { |
|
| 497 | + $found = true; |
|
| 498 | + break; |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + if (!$found) { |
|
| 502 | + $sqs_objects[$name]['field_list'][] = $field['populate_list'][$j]; // as in lines 462 and 463 |
|
| 503 | + $sqs_objects[$name]['populate_list'][] = $field['field_list'][$j]; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | } //foreach |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - //Implement QuickSearch for the field |
|
| 512 | - if(!empty($sqs_objects) && count($sqs_objects) > 0) { |
|
| 513 | - $quicksearch_js = '<script language="javascript">'; |
|
| 514 | - $quicksearch_js.= 'if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}'; |
|
| 515 | - $json = getJSONobj(); |
|
| 516 | - foreach($sqs_objects as $sqsfield=>$sqsfieldArray){ |
|
| 517 | - $quicksearch_js .= "sqs_objects['$sqsfield']={$json->encode($sqsfieldArray)};"; |
|
| 518 | - } |
|
| 519 | - return $quicksearch_js . '</script>'; |
|
| 520 | - } |
|
| 521 | - return ''; |
|
| 511 | + //Implement QuickSearch for the field |
|
| 512 | + if(!empty($sqs_objects) && count($sqs_objects) > 0) { |
|
| 513 | + $quicksearch_js = '<script language="javascript">'; |
|
| 514 | + $quicksearch_js.= 'if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}'; |
|
| 515 | + $json = getJSONobj(); |
|
| 516 | + foreach($sqs_objects as $sqsfield=>$sqsfieldArray){ |
|
| 517 | + $quicksearch_js .= "sqs_objects['$sqsfield']={$json->encode($sqsfieldArray)};"; |
|
| 518 | + } |
|
| 519 | + return $quicksearch_js . '</script>'; |
|
| 520 | + } |
|
| 521 | + return ''; |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | $this->cacheDir = sugar_cached(''); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - function loadSmarty(){ |
|
| 57 | - if(empty($this->ss)){ |
|
| 56 | + function loadSmarty() { |
|
| 57 | + if (empty($this->ss)) { |
|
| 58 | 58 | $this->ss = new Sugar_Smarty(); |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | static function clearAll() { |
| 69 | 69 | global $beanList; |
| 70 | - foreach($beanList as $module_dir =>$object_name){ |
|
| 70 | + foreach ($beanList as $module_dir =>$object_name) { |
|
| 71 | 71 | TemplateHandler::clearCache($module_dir); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | * @param String $module The module directory to clear |
| 81 | 81 | * @param String $view Optional view value (DetailView, EditView, etc.) |
| 82 | 82 | */ |
| 83 | - static function clearCache($module, $view=''){ |
|
| 84 | - $cacheDir = create_cache_directory('modules/'. $module . '/'); |
|
| 83 | + static function clearCache($module, $view = '') { |
|
| 84 | + $cacheDir = create_cache_directory('modules/'.$module.'/'); |
|
| 85 | 85 | $d = dir($cacheDir); |
| 86 | - while($e = $d->read()){ |
|
| 87 | - if(!empty($view) && $e != $view )continue; |
|
| 88 | - $end =strlen($e) - 4; |
|
| 89 | - if(is_file($cacheDir . $e) && $end > 1 && substr($e, $end) == '.tpl'){ |
|
| 90 | - unlink($cacheDir . $e); |
|
| 86 | + while ($e = $d->read()) { |
|
| 87 | + if (!empty($view) && $e != $view)continue; |
|
| 88 | + $end = strlen($e) - 4; |
|
| 89 | + if (is_file($cacheDir.$e) && $end > 1 && substr($e, $end) == '.tpl') { |
|
| 90 | + unlink($cacheDir.$e); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -105,21 +105,21 @@ discard block |
||
| 105 | 105 | function buildTemplate($module, $view, $tpl, $ajaxSave, $metaDataDefs) { |
| 106 | 106 | $this->loadSmarty(); |
| 107 | 107 | |
| 108 | - $cacheDir = create_cache_directory($this->templateDir. $module . '/'); |
|
| 109 | - $file = $cacheDir . $view . '.tpl'; |
|
| 110 | - $string = '{* Create Date: ' . date('Y-m-d H:i:s') . "*}\n"; |
|
| 108 | + $cacheDir = create_cache_directory($this->templateDir.$module.'/'); |
|
| 109 | + $file = $cacheDir.$view.'.tpl'; |
|
| 110 | + $string = '{* Create Date: '.date('Y-m-d H:i:s')."*}\n"; |
|
| 111 | 111 | $this->ss->left_delimiter = '{{'; |
| 112 | 112 | $this->ss->right_delimiter = '}}'; |
| 113 | 113 | $this->ss->assign('module', $module); |
| 114 | 114 | $this->ss->assign('built_in_buttons', array('CANCEL', 'DELETE', 'DUPLICATE', 'EDIT', 'FIND_DUPLICATES', 'SAVE', 'CONNECTOR')); |
| 115 | 115 | $contents = $this->ss->fetch($tpl); |
| 116 | 116 | //Insert validation and quicksearch stuff here |
| 117 | - if($view == 'EditView' || strpos($view,'QuickCreate') || $ajaxSave || $view == "ConvertLead") { |
|
| 117 | + if ($view == 'EditView' || strpos($view, 'QuickCreate') || $ajaxSave || $view == "ConvertLead") { |
|
| 118 | 118 | |
| 119 | 119 | global $dictionary, $beanList, $app_strings, $mod_strings; |
| 120 | 120 | $mod = $beanList[$module]; |
| 121 | 121 | |
| 122 | - if($mod == 'aCase') { |
|
| 122 | + if ($mod == 'aCase') { |
|
| 123 | 123 | $mod = 'Case'; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -128,14 +128,14 @@ discard block |
||
| 128 | 128 | //Retrieve all panel field definitions with displayParams Array field set |
| 129 | 129 | $panelFields = array(); |
| 130 | 130 | |
| 131 | - foreach($metaDataDefs['panels'] as $panel) { |
|
| 132 | - foreach($panel as $row) { |
|
| 133 | - foreach($row as $entry) { |
|
| 134 | - if(empty($entry)) { |
|
| 131 | + foreach ($metaDataDefs['panels'] as $panel) { |
|
| 132 | + foreach ($panel as $row) { |
|
| 133 | + foreach ($row as $entry) { |
|
| 134 | + if (empty($entry)) { |
|
| 135 | 135 | continue; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if(is_array($entry) && |
|
| 138 | + if (is_array($entry) && |
|
| 139 | 139 | isset($entry['name']) && |
| 140 | 140 | isset($entry['displayParams']) && |
| 141 | 141 | isset($entry['displayParams']['required']) && |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $panelFields[$entry['name']] = $entry; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if(is_array($entry)) { |
|
| 146 | + if (is_array($entry)) { |
|
| 147 | 147 | $defs2[$entry['name']] = $entry; |
| 148 | 148 | } else { |
| 149 | 149 | $defs2[$entry] = array('name' => $entry); |
@@ -152,18 +152,18 @@ discard block |
||
| 152 | 152 | } //foreach |
| 153 | 153 | } //foreach |
| 154 | 154 | |
| 155 | - foreach($panelFields as $field=>$value) { |
|
| 155 | + foreach ($panelFields as $field=>$value) { |
|
| 156 | 156 | $nameList = array(); |
| 157 | - if(!is_array($value['displayParams']['required'])) { |
|
| 157 | + if (!is_array($value['displayParams']['required'])) { |
|
| 158 | 158 | $nameList[] = $field; |
| 159 | 159 | } else { |
| 160 | - foreach($value['displayParams']['required'] as $groupedField) { |
|
| 160 | + foreach ($value['displayParams']['required'] as $groupedField) { |
|
| 161 | 161 | $nameList[] = $groupedField; |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - foreach($nameList as $x) { |
|
| 166 | - if(isset($defs[$x]) && |
|
| 165 | + foreach ($nameList as $x) { |
|
| 166 | + if (isset($defs[$x]) && |
|
| 167 | 167 | isset($defs[$x]['type']) && |
| 168 | 168 | !isset($defs[$x]['required'])) { |
| 169 | 169 | $defs[$x]['required'] = true; |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | $javascript->setSugarBean($sugarbean); |
| 184 | 184 | if ($view != "ConvertLead") |
| 185 | - $javascript->addAllFields('', null,true); |
|
| 185 | + $javascript->addAllFields('', null, true); |
|
| 186 | 186 | |
| 187 | 187 | $validatedFields = array(); |
| 188 | 188 | $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty('LBL_ASSIGNED_TO'), 'false', '', 'assigned_user_id'); |
@@ -193,20 +193,20 @@ discard block |
||
| 193 | 193 | //3) not have validateDepedency set to false in metadata |
| 194 | 194 | //4) have id_name in vardef entry |
| 195 | 195 | //5) not already been added to Array |
| 196 | - foreach($sugarbean->field_name_map as $name=>$def) { |
|
| 196 | + foreach ($sugarbean->field_name_map as $name=>$def) { |
|
| 197 | 197 | |
| 198 | - if($def['type']=='relate' && |
|
| 198 | + if ($def['type'] == 'relate' && |
|
| 199 | 199 | isset($defs2[$name]) && |
| 200 | 200 | (!isset($defs2[$name]['validateDependency']) || $defs2[$name]['validateDependency'] === true) && |
| 201 | 201 | isset($def['id_name']) && |
| 202 | 202 | !in_array($name, $validatedFields)) { |
| 203 | 203 | |
| 204 | - if(isset($mod_strings[$def['vname']]) |
|
| 204 | + if (isset($mod_strings[$def['vname']]) |
|
| 205 | 205 | || isset($app_strings[$def['vname']]) |
| 206 | - || translate($def['vname'],$sugarbean->module_dir) != $def['vname']) { |
|
| 206 | + || translate($def['vname'], $sugarbean->module_dir) != $def['vname']) { |
|
| 207 | 207 | $vname = $def['vname']; |
| 208 | 208 | } |
| 209 | - else{ |
|
| 209 | + else { |
|
| 210 | 210 | $vname = "undefined"; |
| 211 | 211 | } |
| 212 | 212 | $javascript->addToValidateBinaryDependency($name, 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty($vname), (!empty($def['required']) ? 'true' : 'false'), '', $def['id_name']); |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | $contents .= $javascript->getScript(); |
| 219 | 219 | $contents .= $this->createQuickSearchCode($defs, $defs2, $view, $module); |
| 220 | 220 | $contents .= "{/literal}\n"; |
| 221 | - }else if(preg_match('/^SearchForm_.+/', $view)){ |
|
| 221 | + } else if (preg_match('/^SearchForm_.+/', $view)) { |
|
| 222 | 222 | global $dictionary, $beanList, $app_strings, $mod_strings; |
| 223 | 223 | $mod = $beanList[$module]; |
| 224 | 224 | |
| 225 | - if($mod == 'aCase') { |
|
| 225 | + if ($mod == 'aCase') { |
|
| 226 | 226 | $mod = 'Case'; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | //Remove all the copyright comments |
| 236 | 236 | $contents = preg_replace('/\{\*[^\}]*?\*\}/', '', $contents); |
| 237 | 237 | |
| 238 | - if($fh = @sugar_fopen($file, 'w')) { |
|
| 238 | + if ($fh = @sugar_fopen($file, 'w')) { |
|
| 239 | 239 | fputs($fh, $contents); |
| 240 | 240 | fclose($fh); |
| 241 | 241 | } |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | * @param module string module name |
| 252 | 252 | * @param view string view need (eg DetailView, EditView, etc) |
| 253 | 253 | */ |
| 254 | - function checkTemplate($module, $view, $checkFormName = false, $formName='') { |
|
| 255 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
| 254 | + function checkTemplate($module, $view, $checkFormName = false, $formName = '') { |
|
| 255 | + if (inDeveloperMode() || !empty($_SESSION['developerMode'])) { |
|
| 256 | 256 | return false; |
| 257 | 257 | } |
| 258 | 258 | $view = $checkFormName ? $formName : $view; |
| 259 | - return file_exists($this->cacheDir . $this->templateDir . $module . '/' .$view . '.tpl'); |
|
| 259 | + return file_exists($this->cacheDir.$this->templateDir.$module.'/'.$view.'.tpl'); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -270,16 +270,16 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | function displayTemplate($module, $view, $tpl, $ajaxSave = false, $metaDataDefs = null) { |
| 272 | 272 | $this->loadSmarty(); |
| 273 | - if(!$this->checkTemplate($module, $view)) { |
|
| 273 | + if (!$this->checkTemplate($module, $view)) { |
|
| 274 | 274 | $this->buildTemplate($module, $view, $tpl, $ajaxSave, $metaDataDefs); |
| 275 | 275 | } |
| 276 | - $file = $this->cacheDir . $this->templateDir . $module . '/' . $view . '.tpl'; |
|
| 277 | - if(file_exists($file)) { |
|
| 276 | + $file = $this->cacheDir.$this->templateDir.$module.'/'.$view.'.tpl'; |
|
| 277 | + if (file_exists($file)) { |
|
| 278 | 278 | return $this->ss->fetch($file); |
| 279 | 279 | } else { |
| 280 | 280 | global $app_strings; |
| 281 | - $GLOBALS['log']->fatal($app_strings['ERR_NO_SUCH_FILE'] .": $file"); |
|
| 282 | - return $app_strings['ERR_NO_SUCH_FILE'] .": $file"; |
|
| 281 | + $GLOBALS['log']->fatal($app_strings['ERR_NO_SUCH_FILE'].": $file"); |
|
| 282 | + return $app_strings['ERR_NO_SUCH_FILE'].": $file"; |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
@@ -290,16 +290,16 @@ discard block |
||
| 290 | 290 | * @param view string view need (eg DetailView, EditView, etc) |
| 291 | 291 | */ |
| 292 | 292 | function deleteTemplate($module, $view) { |
| 293 | - if(is_file($this->cacheDir . $this->templateDir . $module . '/' .$view . '.tpl')) { |
|
| 293 | + if (is_file($this->cacheDir.$this->templateDir.$module.'/'.$view.'.tpl')) { |
|
| 294 | 294 | // Bug #54634 : RTC 18144 : Cannot add more than 1 user to role but popup is multi-selectable |
| 295 | - if ( !isset($this->ss) ) |
|
| 295 | + if (!isset($this->ss)) |
|
| 296 | 296 | { |
| 297 | 297 | $this->loadSmarty(); |
| 298 | 298 | } |
| 299 | - $cache_file_name = $this->ss->_get_compile_path($this->cacheDir . $this->templateDir . $module . '/' .$view . '.tpl'); |
|
| 299 | + $cache_file_name = $this->ss->_get_compile_path($this->cacheDir.$this->templateDir.$module.'/'.$view.'.tpl'); |
|
| 300 | 300 | SugarCache::cleanFile($cache_file_name); |
| 301 | 301 | |
| 302 | - return unlink($this->cacheDir . $this->templateDir . $module . '/' .$view . '.tpl'); |
|
| 302 | + return unlink($this->cacheDir.$this->templateDir.$module.'/'.$view.'.tpl'); |
|
| 303 | 303 | } |
| 304 | 304 | return false; |
| 305 | 305 | } |
@@ -316,47 +316,47 @@ discard block |
||
| 316 | 316 | * @param strign $module |
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | - public function createQuickSearchCode($defs, $defs2, $view = '', $module='') |
|
| 319 | + public function createQuickSearchCode($defs, $defs2, $view = '', $module = '') |
|
| 320 | 320 | { |
| 321 | 321 | $sqs_objects = array(); |
| 322 | 322 | require_once('include/QuickSearchDefaults.php'); |
| 323 | - if(isset($this) && $this instanceof TemplateHandler) //If someone calls createQuickSearchCode as a static method (@see ImportViewStep3) $this becomes anoter object, not TemplateHandler |
|
| 323 | + if (isset($this) && $this instanceof TemplateHandler) //If someone calls createQuickSearchCode as a static method (@see ImportViewStep3) $this becomes anoter object, not TemplateHandler |
|
| 324 | 324 | { |
| 325 | 325 | $qsd = QuickSearchDefaults::getQuickSearchDefaults($this->getQSDLookup()); |
| 326 | - }else |
|
| 326 | + } else |
|
| 327 | 327 | { |
| 328 | 328 | $qsd = QuickSearchDefaults::getQuickSearchDefaults(array()); |
| 329 | 329 | } |
| 330 | 330 | $qsd->setFormName($view); |
| 331 | - if(preg_match('/^SearchForm_.+/', $view)){ |
|
| 332 | - if(strpos($view, 'popup_query_form')){ |
|
| 331 | + if (preg_match('/^SearchForm_.+/', $view)) { |
|
| 332 | + if (strpos($view, 'popup_query_form')) { |
|
| 333 | 333 | $qsd->setFormName('popup_query_form'); |
| 334 | 334 | $parsedView = 'advanced'; |
| 335 | - }else{ |
|
| 335 | + } else { |
|
| 336 | 336 | $qsd->setFormName('search_form'); |
| 337 | 337 | $parsedView = preg_replace("/^SearchForm_/", "", $view); |
| 338 | 338 | } |
| 339 | 339 | //Loop through the Meta-Data fields to see which ones need quick search support |
| 340 | - foreach($defs as $f) { |
|
| 340 | + foreach ($defs as $f) { |
|
| 341 | 341 | $field = $f; |
| 342 | - $name = $qsd->form_name . '_' . $field['name']; |
|
| 342 | + $name = $qsd->form_name.'_'.$field['name']; |
|
| 343 | 343 | |
| 344 | - if($field['type'] == 'relate' && isset($field['module']) && preg_match('/_name$|_c$/si',$name) || !empty($field['quicksearch']) ) { |
|
| 345 | - if(preg_match('/^(Campaigns|Teams|Users|Contacts|Accounts)$/si', $field['module'], $matches)) { |
|
| 344 | + if ($field['type'] == 'relate' && isset($field['module']) && preg_match('/_name$|_c$/si', $name) || !empty($field['quicksearch'])) { |
|
| 345 | + if (preg_match('/^(Campaigns|Teams|Users|Contacts|Accounts)$/si', $field['module'], $matches)) { |
|
| 346 | 346 | |
| 347 | - if($matches[0] == 'Campaigns') { |
|
| 347 | + if ($matches[0] == 'Campaigns') { |
|
| 348 | 348 | $sqs_objects[$name.'_'.$parsedView] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
| 349 | - } else if($matches[0] == 'Users'){ |
|
| 349 | + } else if ($matches[0] == 'Users') { |
|
| 350 | 350 | |
| 351 | - if(!empty($f['name']) && !empty($f['id_name'])) { |
|
| 352 | - $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser($f['name'],$f['id_name']); |
|
| 351 | + if (!empty($f['name']) && !empty($f['id_name'])) { |
|
| 352 | + $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser($f['name'], $f['id_name']); |
|
| 353 | 353 | } |
| 354 | 354 | else { |
| 355 | 355 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser(); |
| 356 | 356 | } |
| 357 | - } else if($matches[0] == 'Campaigns') { |
|
| 357 | + } else if ($matches[0] == 'Campaigns') { |
|
| 358 | 358 | $sqs_objects[$name.'_'.$parsedView] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
| 359 | - } else if($matches[0] == 'Accounts') { |
|
| 359 | + } else if ($matches[0] == 'Accounts') { |
|
| 360 | 360 | $nameKey = $name; |
| 361 | 361 | $idKey = isset($field['id_name']) ? $field['id_name'] : 'account_id'; |
| 362 | 362 | |
@@ -369,12 +369,12 @@ discard block |
||
| 369 | 369 | $shippingKey = isset($f['displayParams']['shippingKey']) ? $f['displayParams']['shippingKey'] : null; |
| 370 | 370 | $additionalFields = isset($f['displayParams']['additionalFields']) ? $f['displayParams']['additionalFields'] : null; |
| 371 | 371 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSAccount($nameKey, $idKey, $billingKey, $shippingKey, $additionalFields); |
| 372 | - } else if($matches[0] == 'Contacts'){ |
|
| 372 | + } else if ($matches[0] == 'Contacts') { |
|
| 373 | 373 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSContact($field['name'], $field['id_name']); |
| 374 | 374 | } |
| 375 | 375 | } else { |
| 376 | 376 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent($field['module']); |
| 377 | - if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
|
| 377 | + if (!isset($field['field_list']) && !isset($field['populate_list'])) { |
|
| 378 | 378 | $sqs_objects[$name.'_'.$parsedView]['populate_list'] = array($field['name'], $field['id_name']); |
| 379 | 379 | $sqs_objects[$name.'_'.$parsedView]['field_list'] = array('name', 'id'); |
| 380 | 380 | } else { |
@@ -382,63 +382,63 @@ discard block |
||
| 382 | 382 | $sqs_objects[$name.'_'.$parsedView]['field_list'] = $field['populate_list']; |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | - } else if($field['type'] == 'parent') { |
|
| 385 | + } else if ($field['type'] == 'parent') { |
|
| 386 | 386 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent(); |
| 387 | 387 | } //if-else |
| 388 | 388 | } //foreach |
| 389 | 389 | |
| 390 | - foreach ( $sqs_objects as $name => $field ) |
|
| 391 | - foreach ( $field['populate_list'] as $key => $fieldname ) |
|
| 392 | - $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key] . '_'.$parsedView; |
|
| 393 | - }else{ |
|
| 390 | + foreach ($sqs_objects as $name => $field) |
|
| 391 | + foreach ($field['populate_list'] as $key => $fieldname) |
|
| 392 | + $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key].'_'.$parsedView; |
|
| 393 | + } else { |
|
| 394 | 394 | //Loop through the Meta-Data fields to see which ones need quick search support |
| 395 | - foreach($defs2 as $f) { |
|
| 396 | - if(!isset($defs[$f['name']])) continue; |
|
| 395 | + foreach ($defs2 as $f) { |
|
| 396 | + if (!isset($defs[$f['name']])) continue; |
|
| 397 | 397 | |
| 398 | 398 | $field = $defs[$f['name']]; |
| 399 | 399 | if ($view == "ConvertLead") |
| 400 | 400 | { |
| 401 | - $field['name'] = $module . $field['name']; |
|
| 401 | + $field['name'] = $module.$field['name']; |
|
| 402 | 402 | if (isset($field['module']) && isset($field['id_name']) && substr($field['id_name'], -4) == "_ida") { |
| 403 | 403 | $lc_module = strtolower($field['module']); |
| 404 | 404 | $ida_suffix = "_".$lc_module.$lc_module."_ida"; |
| 405 | 405 | if (preg_match('/'.$ida_suffix.'$/', $field['id_name']) > 0) { |
| 406 | - $field['id_name'] = $module . $field['id_name']; |
|
| 406 | + $field['id_name'] = $module.$field['id_name']; |
|
| 407 | 407 | } |
| 408 | 408 | else |
| 409 | - $field['id_name'] = $field['name'] . "_" . $field['id_name']; |
|
| 409 | + $field['id_name'] = $field['name']."_".$field['id_name']; |
|
| 410 | 410 | } |
| 411 | 411 | else { |
| 412 | 412 | if (!empty($field['id_name'])) |
| 413 | 413 | $field['id_name'] = $module.$field['id_name']; |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | - $name = $qsd->form_name . '_' . $field['name']; |
|
| 416 | + $name = $qsd->form_name.'_'.$field['name']; |
|
| 417 | 417 | |
| 418 | 418 | |
| 419 | - if($field['type'] == 'relate' && isset($field['module']) && (preg_match('/_name$|_c$/si',$name) || !empty($field['quicksearch']))) { |
|
| 420 | - if (!preg_match('/_c$/si',$name) |
|
| 421 | - && (!isset($field['id_name']) || !preg_match('/_c$/si',$field['id_name'])) |
|
| 419 | + if ($field['type'] == 'relate' && isset($field['module']) && (preg_match('/_name$|_c$/si', $name) || !empty($field['quicksearch']))) { |
|
| 420 | + if (!preg_match('/_c$/si', $name) |
|
| 421 | + && (!isset($field['id_name']) || !preg_match('/_c$/si', $field['id_name'])) |
|
| 422 | 422 | && preg_match('/^(Campaigns|Teams|Users|Contacts|Accounts)$/si', $field['module'], $matches) |
| 423 | 423 | ) { |
| 424 | 424 | |
| 425 | - if($matches[0] == 'Campaigns') { |
|
| 425 | + if ($matches[0] == 'Campaigns') { |
|
| 426 | 426 | $sqs_objects[$name] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
| 427 | - } else if($matches[0] == 'Users'){ |
|
| 428 | - if($field['name'] == 'reports_to_name'){ |
|
| 429 | - $sqs_objects[$name] = $qsd->getQSUser('reports_to_name','reports_to_id'); |
|
| 427 | + } else if ($matches[0] == 'Users') { |
|
| 428 | + if ($field['name'] == 'reports_to_name') { |
|
| 429 | + $sqs_objects[$name] = $qsd->getQSUser('reports_to_name', 'reports_to_id'); |
|
| 430 | 430 | // Bug #52994 : QuickSearch for a 1-M User relationship changes assigned to user |
| 431 | - }elseif($field['name'] == 'assigned_user_name'){ |
|
| 432 | - $sqs_objects[$name] = $qsd->getQSUser('assigned_user_name','assigned_user_id'); |
|
| 431 | + }elseif ($field['name'] == 'assigned_user_name') { |
|
| 432 | + $sqs_objects[$name] = $qsd->getQSUser('assigned_user_name', 'assigned_user_id'); |
|
| 433 | 433 | } |
| 434 | 434 | else |
| 435 | 435 | { |
| 436 | 436 | $sqs_objects[$name] = $qsd->getQSUser($field['name'], $field['id_name']); |
| 437 | 437 | |
| 438 | 438 | } |
| 439 | - } else if($matches[0] == 'Campaigns') { |
|
| 439 | + } else if ($matches[0] == 'Campaigns') { |
|
| 440 | 440 | $sqs_objects[$name] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
| 441 | - } else if($matches[0] == 'Accounts') { |
|
| 441 | + } else if ($matches[0] == 'Accounts') { |
|
| 442 | 442 | $nameKey = $name; |
| 443 | 443 | $idKey = isset($field['id_name']) ? $field['id_name'] : 'account_id'; |
| 444 | 444 | |
@@ -451,15 +451,15 @@ discard block |
||
| 451 | 451 | $shippingKey = SugarArray::staticGet($f, 'displayParams.shippingKey'); |
| 452 | 452 | $additionalFields = SugarArray::staticGet($f, 'displayParams.additionalFields'); |
| 453 | 453 | $sqs_objects[$name] = $qsd->getQSAccount($nameKey, $idKey, $billingKey, $shippingKey, $additionalFields); |
| 454 | - } else if($matches[0] == 'Contacts'){ |
|
| 454 | + } else if ($matches[0] == 'Contacts') { |
|
| 455 | 455 | $sqs_objects[$name] = $qsd->getQSContact($field['name'], $field['id_name']); |
| 456 | - if(preg_match('/_c$/si',$name) || !empty($field['quicksearch'])){ |
|
| 456 | + if (preg_match('/_c$/si', $name) || !empty($field['quicksearch'])) { |
|
| 457 | 457 | $sqs_objects[$name]['field_list'] = array('salutation', 'first_name', 'last_name', 'id'); |
| 458 | 458 | } |
| 459 | 459 | } |
| 460 | 460 | } else { |
| 461 | 461 | $sqs_objects[$name] = $qsd->getQSParent($field['module']); |
| 462 | - if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
|
| 462 | + if (!isset($field['field_list']) && !isset($field['populate_list'])) { |
|
| 463 | 463 | $sqs_objects[$name]['populate_list'] = array($field['name'], $field['id_name']); |
| 464 | 464 | // now handle quicksearches where the column to match is not 'name' but rather specified in 'rname' |
| 465 | 465 | if (!isset($field['rname'])) |
@@ -468,14 +468,14 @@ discard block |
||
| 468 | 468 | { |
| 469 | 469 | $sqs_objects[$name]['field_list'] = array($field['rname'], 'id'); |
| 470 | 470 | $sqs_objects[$name]['order'] = $field['rname']; |
| 471 | - $sqs_objects[$name]['conditions'] = array(array('name'=>$field['rname'],'op'=>'like_custom','end'=>'%','value'=>'')); |
|
| 471 | + $sqs_objects[$name]['conditions'] = array(array('name'=>$field['rname'], 'op'=>'like_custom', 'end'=>'%', 'value'=>'')); |
|
| 472 | 472 | } |
| 473 | 473 | } else { |
| 474 | 474 | $sqs_objects[$name]['populate_list'] = $field['field_list']; |
| 475 | 475 | $sqs_objects[$name]['field_list'] = $field['populate_list']; |
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | - } else if($field['type'] == 'parent') { |
|
| 478 | + } else if ($field['type'] == 'parent') { |
|
| 479 | 479 | $sqs_objects[$name] = $qsd->getQSParent(); |
| 480 | 480 | } //if-else |
| 481 | 481 | |
@@ -485,13 +485,13 @@ discard block |
||
| 485 | 485 | |
| 486 | 486 | //merge populate_list && field_list with vardef |
| 487 | 487 | if (!empty($field['field_list']) && !empty($field['populate_list'])) { |
| 488 | - for ($j=0; $j<count($field['field_list']); $j++) { |
|
| 488 | + for ($j = 0; $j < count($field['field_list']); $j++) { |
|
| 489 | 489 | //search for the same couple (field_list_item,populate_field_item) |
| 490 | 490 | $field_list_item = $field['field_list'][$j]; |
| 491 | - $field_list_item_alternate = $qsd->form_name . '_' . $field['field_list'][$j]; |
|
| 491 | + $field_list_item_alternate = $qsd->form_name.'_'.$field['field_list'][$j]; |
|
| 492 | 492 | $populate_list_item = $field['populate_list'][$j]; |
| 493 | 493 | $found = false; |
| 494 | - for ($k=0; $k<count($sqs_objects[$name]['field_list']); $k++) { |
|
| 494 | + for ($k = 0; $k < count($sqs_objects[$name]['field_list']); $k++) { |
|
| 495 | 495 | if (($field_list_item == $sqs_objects[$name]['populate_list'][$k] || $field_list_item_alternate == $sqs_objects[$name]['populate_list'][$k]) && //il faut inverser field_list et populate_list (cf lignes 465,466 ci-dessus) |
| 496 | 496 | $populate_list_item == $sqs_objects[$name]['field_list'][$k]) { |
| 497 | 497 | $found = true; |
@@ -509,14 +509,14 @@ discard block |
||
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | //Implement QuickSearch for the field |
| 512 | - if(!empty($sqs_objects) && count($sqs_objects) > 0) { |
|
| 512 | + if (!empty($sqs_objects) && count($sqs_objects) > 0) { |
|
| 513 | 513 | $quicksearch_js = '<script language="javascript">'; |
| 514 | - $quicksearch_js.= 'if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}'; |
|
| 514 | + $quicksearch_js .= 'if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}'; |
|
| 515 | 515 | $json = getJSONobj(); |
| 516 | - foreach($sqs_objects as $sqsfield=>$sqsfieldArray){ |
|
| 516 | + foreach ($sqs_objects as $sqsfield=>$sqsfieldArray) { |
|
| 517 | 517 | $quicksearch_js .= "sqs_objects['$sqsfield']={$json->encode($sqsfieldArray)};"; |
| 518 | 518 | } |
| 519 | - return $quicksearch_js . '</script>'; |
|
| 519 | + return $quicksearch_js.'</script>'; |
|
| 520 | 520 | } |
| 521 | 521 | return ''; |
| 522 | 522 | } |
@@ -84,7 +84,9 @@ discard block |
||
| 84 | 84 | $cacheDir = create_cache_directory('modules/'. $module . '/'); |
| 85 | 85 | $d = dir($cacheDir); |
| 86 | 86 | while($e = $d->read()){ |
| 87 | - if(!empty($view) && $e != $view )continue; |
|
| 87 | + if(!empty($view) && $e != $view ) { |
|
| 88 | + continue; |
|
| 89 | + } |
|
| 88 | 90 | $end =strlen($e) - 4; |
| 89 | 91 | if(is_file($cacheDir . $e) && $end > 1 && substr($e, $end) == '.tpl'){ |
| 90 | 92 | unlink($cacheDir . $e); |
@@ -181,8 +183,9 @@ discard block |
||
| 181 | 183 | $javascript->setFormName($view); |
| 182 | 184 | |
| 183 | 185 | $javascript->setSugarBean($sugarbean); |
| 184 | - if ($view != "ConvertLead") |
|
| 185 | - $javascript->addAllFields('', null,true); |
|
| 186 | + if ($view != "ConvertLead") { |
|
| 187 | + $javascript->addAllFields('', null,true); |
|
| 188 | + } |
|
| 186 | 189 | |
| 187 | 190 | $validatedFields = array(); |
| 188 | 191 | $javascript->addToValidateBinaryDependency('assigned_user_name', 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty('LBL_ASSIGNED_TO'), 'false', '', 'assigned_user_id'); |
@@ -205,8 +208,7 @@ discard block |
||
| 205 | 208 | || isset($app_strings[$def['vname']]) |
| 206 | 209 | || translate($def['vname'],$sugarbean->module_dir) != $def['vname']) { |
| 207 | 210 | $vname = $def['vname']; |
| 208 | - } |
|
| 209 | - else{ |
|
| 211 | + } else{ |
|
| 210 | 212 | $vname = "undefined"; |
| 211 | 213 | } |
| 212 | 214 | $javascript->addToValidateBinaryDependency($name, 'alpha', $javascript->buildStringToTranslateInSmarty('ERR_SQS_NO_MATCH_FIELD').': '.$javascript->buildStringToTranslateInSmarty($vname), (!empty($def['required']) ? 'true' : 'false'), '', $def['id_name']); |
@@ -218,7 +220,7 @@ discard block |
||
| 218 | 220 | $contents .= $javascript->getScript(); |
| 219 | 221 | $contents .= $this->createQuickSearchCode($defs, $defs2, $view, $module); |
| 220 | 222 | $contents .= "{/literal}\n"; |
| 221 | - }else if(preg_match('/^SearchForm_.+/', $view)){ |
|
| 223 | + } else if(preg_match('/^SearchForm_.+/', $view)){ |
|
| 222 | 224 | global $dictionary, $beanList, $app_strings, $mod_strings; |
| 223 | 225 | $mod = $beanList[$module]; |
| 224 | 226 | |
@@ -320,10 +322,12 @@ discard block |
||
| 320 | 322 | { |
| 321 | 323 | $sqs_objects = array(); |
| 322 | 324 | require_once('include/QuickSearchDefaults.php'); |
| 323 | - if(isset($this) && $this instanceof TemplateHandler) //If someone calls createQuickSearchCode as a static method (@see ImportViewStep3) $this becomes anoter object, not TemplateHandler |
|
| 325 | + if(isset($this) && $this instanceof TemplateHandler) { |
|
| 326 | + //If someone calls createQuickSearchCode as a static method (@see ImportViewStep3) $this becomes anoter object, not TemplateHandler |
|
| 324 | 327 | { |
| 325 | 328 | $qsd = QuickSearchDefaults::getQuickSearchDefaults($this->getQSDLookup()); |
| 326 | - }else |
|
| 329 | + } |
|
| 330 | + } else |
|
| 327 | 331 | { |
| 328 | 332 | $qsd = QuickSearchDefaults::getQuickSearchDefaults(array()); |
| 329 | 333 | } |
@@ -332,7 +336,7 @@ discard block |
||
| 332 | 336 | if(strpos($view, 'popup_query_form')){ |
| 333 | 337 | $qsd->setFormName('popup_query_form'); |
| 334 | 338 | $parsedView = 'advanced'; |
| 335 | - }else{ |
|
| 339 | + } else{ |
|
| 336 | 340 | $qsd->setFormName('search_form'); |
| 337 | 341 | $parsedView = preg_replace("/^SearchForm_/", "", $view); |
| 338 | 342 | } |
@@ -350,8 +354,7 @@ discard block |
||
| 350 | 354 | |
| 351 | 355 | if(!empty($f['name']) && !empty($f['id_name'])) { |
| 352 | 356 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser($f['name'],$f['id_name']); |
| 353 | - } |
|
| 354 | - else { |
|
| 357 | + } else { |
|
| 355 | 358 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser(); |
| 356 | 359 | } |
| 357 | 360 | } else if($matches[0] == 'Campaigns') { |
@@ -387,13 +390,16 @@ discard block |
||
| 387 | 390 | } //if-else |
| 388 | 391 | } //foreach |
| 389 | 392 | |
| 390 | - foreach ( $sqs_objects as $name => $field ) |
|
| 391 | - foreach ( $field['populate_list'] as $key => $fieldname ) |
|
| 393 | + foreach ( $sqs_objects as $name => $field ) { |
|
| 394 | + foreach ( $field['populate_list'] as $key => $fieldname ) |
|
| 392 | 395 | $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key] . '_'.$parsedView; |
| 393 | - }else{ |
|
| 396 | + } |
|
| 397 | + } else{ |
|
| 394 | 398 | //Loop through the Meta-Data fields to see which ones need quick search support |
| 395 | 399 | foreach($defs2 as $f) { |
| 396 | - if(!isset($defs[$f['name']])) continue; |
|
| 400 | + if(!isset($defs[$f['name']])) { |
|
| 401 | + continue; |
|
| 402 | + } |
|
| 397 | 403 | |
| 398 | 404 | $field = $defs[$f['name']]; |
| 399 | 405 | if ($view == "ConvertLead") |
@@ -404,13 +410,13 @@ discard block |
||
| 404 | 410 | $ida_suffix = "_".$lc_module.$lc_module."_ida"; |
| 405 | 411 | if (preg_match('/'.$ida_suffix.'$/', $field['id_name']) > 0) { |
| 406 | 412 | $field['id_name'] = $module . $field['id_name']; |
| 413 | + } else { |
|
| 414 | + $field['id_name'] = $field['name'] . "_" . $field['id_name']; |
|
| 415 | + } |
|
| 416 | + } else { |
|
| 417 | + if (!empty($field['id_name'])) { |
|
| 418 | + $field['id_name'] = $module.$field['id_name']; |
|
| 407 | 419 | } |
| 408 | - else |
|
| 409 | - $field['id_name'] = $field['name'] . "_" . $field['id_name']; |
|
| 410 | - } |
|
| 411 | - else { |
|
| 412 | - if (!empty($field['id_name'])) |
|
| 413 | - $field['id_name'] = $module.$field['id_name']; |
|
| 414 | 420 | } |
| 415 | 421 | } |
| 416 | 422 | $name = $qsd->form_name . '_' . $field['name']; |
@@ -428,10 +434,9 @@ discard block |
||
| 428 | 434 | if($field['name'] == 'reports_to_name'){ |
| 429 | 435 | $sqs_objects[$name] = $qsd->getQSUser('reports_to_name','reports_to_id'); |
| 430 | 436 | // Bug #52994 : QuickSearch for a 1-M User relationship changes assigned to user |
| 431 | - }elseif($field['name'] == 'assigned_user_name'){ |
|
| 437 | + } elseif($field['name'] == 'assigned_user_name'){ |
|
| 432 | 438 | $sqs_objects[$name] = $qsd->getQSUser('assigned_user_name','assigned_user_id'); |
| 433 | - } |
|
| 434 | - else |
|
| 439 | + } else |
|
| 435 | 440 | { |
| 436 | 441 | $sqs_objects[$name] = $qsd->getQSUser($field['name'], $field['id_name']); |
| 437 | 442 | |
@@ -462,9 +467,9 @@ discard block |
||
| 462 | 467 | if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
| 463 | 468 | $sqs_objects[$name]['populate_list'] = array($field['name'], $field['id_name']); |
| 464 | 469 | // now handle quicksearches where the column to match is not 'name' but rather specified in 'rname' |
| 465 | - if (!isset($field['rname'])) |
|
| 466 | - $sqs_objects[$name]['field_list'] = array('name', 'id'); |
|
| 467 | - else |
|
| 470 | + if (!isset($field['rname'])) { |
|
| 471 | + $sqs_objects[$name]['field_list'] = array('name', 'id'); |
|
| 472 | + } else |
|
| 468 | 473 | { |
| 469 | 474 | $sqs_objects[$name]['field_list'] = array($field['rname'], 'id'); |
| 470 | 475 | $sqs_objects[$name]['order'] = $field['rname']; |
@@ -310,7 +310,7 @@ |
||
| 310 | 310 | * This function creates the $sqs_objects array that will be used by the quicksearch Javascript |
| 311 | 311 | * code. The $sqs_objects array is wrapped in a $json->encode call. |
| 312 | 312 | * |
| 313 | - * @param array $def The vardefs.php definitions |
|
| 313 | + * @param array $defs The vardefs.php definitions |
|
| 314 | 314 | * @param array $defs2 The Meta-Data file definitions |
| 315 | 315 | * @param string $view |
| 316 | 316 | * @param strign $module |