@@ -20,14 +20,14 @@ |
||
| 20 | 20 | $this->db->disableForeignKeyChecks(); |
| 21 | 21 | |
| 22 | 22 | $this->forge->addField([ |
| 23 | - {attributes} |
|
| 24 | - ]); |
|
| 23 | + {attributes} |
|
| 24 | + ]); |
|
| 25 | 25 | {keys} |
| 26 | 26 | $this->forge->createTable('{table}'); |
| 27 | 27 | |
| 28 | 28 | //enable Foreign Key Check |
| 29 | 29 | $this->db->enableForeignKeyChecks(); |
| 30 | - } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | //-------------------------------------------------------------------- |
| 33 | 33 | |
@@ -94,8 +94,9 @@ |
||
| 94 | 94 | //do we have to add table info |
| 95 | 95 | if (!empty($table)) { |
| 96 | 96 | $db = new DBHandler(); |
| 97 | - if ($db->checkTableExist($table)) |
|
| 98 | - $properties = $db->generateRowArray($table); |
|
| 97 | + if ($db->checkTableExist($table)) { |
|
| 98 | + $properties = $db->generateRowArray($table); |
|
| 99 | + } |
|
| 99 | 100 | } |
| 100 | 101 | |
| 101 | 102 | $data = ['{namespace}' => $ns, '{name}' => $name, '{created_at}' => date("d F, Y h:i:s A"), |
@@ -75,8 +75,9 @@ |
||
| 75 | 75 | //if namespace is given |
| 76 | 76 | $ns = $params['-n'] ?? CLI::getOption('n'); |
| 77 | 77 | |
| 78 | - if (empty($name)) |
|
| 79 | - $name = CLI::prompt(lang('Recharge.configName'), null, 'required|string'); |
|
| 78 | + if (empty($name)) { |
|
| 79 | + $name = CLI::prompt(lang('Recharge.configName'), null, 'required|string'); |
|
| 80 | + } |
|
| 80 | 81 | |
| 81 | 82 | if (empty($name)) { |
| 82 | 83 | CLI::error(lang('Recharge.badName')); |
@@ -75,8 +75,9 @@ |
||
| 75 | 75 | //if namespace is given |
| 76 | 76 | $ns = $params['-n'] ?? CLI::getOption('n'); |
| 77 | 77 | |
| 78 | - if (empty($name)) |
|
| 79 | - $name = CLI::prompt(lang('Recharge.filterName'), null, 'required|string'); |
|
| 78 | + if (empty($name)) { |
|
| 79 | + $name = CLI::prompt(lang('Recharge.filterName'), null, 'required|string'); |
|
| 80 | + } |
|
| 80 | 81 | |
| 81 | 82 | if (empty($name)) { |
| 82 | 83 | CLI::error(lang('Recharge.badName')); |
@@ -79,8 +79,9 @@ discard block |
||
| 79 | 79 | $table = $params['-t'] ?? CLI::getOption('t'); |
| 80 | 80 | $alltables = $params['-all'] ?? CLI::getOption('all'); |
| 81 | 81 | |
| 82 | - if (empty($name) && is_null($alltables)) |
|
| 83 | - $name = CLI::prompt(lang('Recharge.migrateName'), null, 'string'); |
|
| 82 | + if (empty($name) && is_null($alltables)) { |
|
| 83 | + $name = CLI::prompt(lang('Recharge.migrateName'), null, 'string'); |
|
| 84 | + } |
|
| 84 | 85 | |
| 85 | 86 | if (empty($name) && is_null($alltables)) { |
| 86 | 87 | CLI::error(lang('Recharge.badName')); |
@@ -102,12 +103,15 @@ discard block |
||
| 102 | 103 | |
| 103 | 104 | foreach ($tableNames as $tableName) { |
| 104 | 105 | //disable framework generation tables |
| 105 | - if ($tableName == 'migrations' || $tableName == 'ci_sessions') continue; |
|
| 106 | + if ($tableName == 'migrations' || $tableName == 'ci_sessions') { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 106 | 109 | |
| 107 | 110 | $this->generateMigration($timestamp, $ns, $targetDir, NULL, $tableName); |
| 108 | 111 | } |
| 109 | - } else |
|
| 110 | - $this->generateMigration($timestamp, $ns, $targetDir, $name, $table); |
|
| 112 | + } else { |
|
| 113 | + $this->generateMigration($timestamp, $ns, $targetDir, $name, $table); |
|
| 114 | + } |
|
| 111 | 115 | } |
| 112 | 116 | |
| 113 | 117 | /** |
@@ -85,8 +85,9 @@ |
||
| 85 | 85 | $permission = null; |
| 86 | 86 | |
| 87 | 87 | //if folder already exists |
| 88 | - if ($this->checkFolderExist($path) == true) |
|
| 89 | - return true; |
|
| 88 | + if ($this->checkFolderExist($path) == true) { |
|
| 89 | + return true; |
|
| 90 | + } |
|
| 90 | 91 | |
| 91 | 92 | //create a folder |
| 92 | 93 | if (!mkdir($targetDir, 0755, true) == true) { |
@@ -107,44 +107,50 @@ discard block |
||
| 107 | 107 | foreach ($query as $field) { |
| 108 | 108 | $singleField = "\n\t\t'$field->Field' => ["; |
| 109 | 109 | //Type |
| 110 | - if (preg_match('/^([a-z]+)/', $field->Type, $matches) > 0) |
|
| 111 | - $singleField .= "\n\t\t\t'type' => '" . strtoupper($matches[1]) . "',"; |
|
| 110 | + if (preg_match('/^([a-z]+)/', $field->Type, $matches) > 0) { |
|
| 111 | + $singleField .= "\n\t\t\t'type' => '" . strtoupper($matches[1]) . "',"; |
|
| 112 | + } |
|
| 112 | 113 | |
| 113 | 114 | //Constraint |
| 114 | 115 | if (preg_match('/\((.+)\)/', $field->Type, $matches) > 0) { |
| 115 | 116 | //integer , varchar |
| 116 | - if (is_numeric($matches[1])) |
|
| 117 | - $singleField .= "\n\t\t\t'constraint' => " . $matches[1] . ","; |
|
| 117 | + if (is_numeric($matches[1])) { |
|
| 118 | + $singleField .= "\n\t\t\t'constraint' => " . $matches[1] . ","; |
|
| 119 | + } |
|
| 118 | 120 | |
| 119 | 121 | //float , double |
| 120 | - elseif (preg_match('/[\d]+\s?,[\d]+\s?/', $matches[1]) > 0) |
|
| 121 | - $singleField .= "\n\t\t\t'constraint' => '" . $matches[1] . "',"; |
|
| 122 | + elseif (preg_match('/[\d]+\s?,[\d]+\s?/', $matches[1]) > 0) { |
|
| 123 | + $singleField .= "\n\t\t\t'constraint' => '" . $matches[1] . "',"; |
|
| 124 | + } |
|
| 122 | 125 | |
| 123 | 126 | //Enum Fields |
| 124 | 127 | else { |
| 125 | 128 | $values = explode(',', str_replace("'", "", $matches[1])); |
| 126 | 129 | |
| 127 | - if (count($values) == 1) |
|
| 128 | - $singleField .= "\n\t\t\t'constraint' => [" . $this->getGluedString($values) . "],"; |
|
| 129 | - |
|
| 130 | - else |
|
| 131 | - $singleField .= "\n\t\t\t'constraint' => " . $this->getGluedString($values) . ","; |
|
| 130 | + if (count($values) == 1) { |
|
| 131 | + $singleField .= "\n\t\t\t'constraint' => [" . $this->getGluedString($values) . "],"; |
|
| 132 | + } else { |
|
| 133 | + $singleField .= "\n\t\t\t'constraint' => " . $this->getGluedString($values) . ","; |
|
| 134 | + } |
|
| 132 | 135 | } |
| 133 | 136 | } |
| 134 | 137 | |
| 135 | 138 | //if field need null |
| 136 | 139 | $singleField .= "\n\t\t\t'null' => " . (($field->Null == 'YES') ? 'true,' : 'false,'); |
| 137 | 140 | |
| 138 | - if (!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) |
|
| 139 | - $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
|
| 141 | + if (!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) { |
|
| 142 | + $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
|
| 143 | + } |
|
| 140 | 144 | |
| 141 | 145 | //unsigned |
| 142 | - if (strpos($field->Type, 'unsigned') !== false) |
|
| 143 | - $singleField .= "\n\t\t\t'unsigned' => true,"; |
|
| 146 | + if (strpos($field->Type, 'unsigned') !== false) { |
|
| 147 | + $singleField .= "\n\t\t\t'unsigned' => true,"; |
|
| 148 | + } |
|
| 144 | 149 | |
| 145 | 150 | //autoincrement |
| 146 | - if (strpos($field->Extra, 'auto_increment') !== false) |
|
| 147 | - $singleField .= "\n\t\t\t'auto_increment' => true,"; |
|
| 151 | + if (strpos($field->Extra, 'auto_increment') !== false) { |
|
| 152 | + $singleField .= "\n\t\t\t'auto_increment' => true,"; |
|
| 153 | + } |
|
| 148 | 154 | |
| 149 | 155 | $singleField .= "\n\t\t],"; |
| 150 | 156 | $fieldString .= $singleField; |
@@ -168,22 +174,23 @@ discard block |
||
| 168 | 174 | { |
| 169 | 175 | |
| 170 | 176 | //array consist of one element |
| 171 | - if (count($arr) == 1) |
|
| 172 | - return "'" . strval(array_shift($arr)) . "'"; |
|
| 173 | - |
|
| 174 | - else { |
|
| 177 | + if (count($arr) == 1) { |
|
| 178 | + return "'" . strval(array_shift($arr)) . "'"; |
|
| 179 | + } else { |
|
| 175 | 180 | |
| 176 | 181 | $str = ''; |
| 177 | 182 | if (!$is_assoc) { |
| 178 | 183 | foreach ($arr as $item) { |
| 179 | - if (strlen($item) > 0) |
|
| 180 | - $str .= "'$item', "; |
|
| 184 | + if (strlen($item) > 0) { |
|
| 185 | + $str .= "'$item', "; |
|
| 186 | + } |
|
| 181 | 187 | } |
| 182 | 188 | |
| 183 | 189 | } else { |
| 184 | 190 | foreach ($arr as $index => $item) { |
| 185 | - if (strlen($item) > 0) |
|
| 186 | - $str .= "'$index' => '$item',"; |
|
| 191 | + if (strlen($item) > 0) { |
|
| 192 | + $str .= "'$index' => '$item',"; |
|
| 193 | + } |
|
| 187 | 194 | } |
| 188 | 195 | } |
| 189 | 196 | |
@@ -238,8 +245,9 @@ discard block |
||
| 238 | 245 | { |
| 239 | 246 | $keys = $this->db->getForeignKeyData($table); |
| 240 | 247 | $keyArray = []; |
| 241 | - foreach ($keys as $key) |
|
| 242 | - array_push($keyArray, "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->foreign_column_name','CASCADE','CASCADE');"); |
|
| 248 | + foreach ($keys as $key) { |
|
| 249 | + array_push($keyArray, "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->foreign_column_name','CASCADE','CASCADE');"); |
|
| 250 | + } |
|
| 243 | 251 | |
| 244 | 252 | return implode('', array_unique($keyArray)); |
| 245 | 253 | } |
@@ -300,8 +308,9 @@ discard block |
||
| 300 | 308 | } |
| 301 | 309 | |
| 302 | 310 | //property cast |
| 303 | - if ($field->type == 'tinyint') |
|
| 304 | - $casts[$field->name] = (($field->nullable) ? "?" : '') . "boolean"; |
|
| 311 | + if ($field->type == 'tinyint') { |
|
| 312 | + $casts[$field->name] = (($field->nullable) ? "?" : '') . "boolean"; |
|
| 313 | + } |
|
| 305 | 314 | |
| 306 | 315 | } |
| 307 | 316 | |
@@ -324,14 +333,13 @@ discard block |
||
| 324 | 333 | $fields = $this->db->getFieldData($table); |
| 325 | 334 | |
| 326 | 335 | foreach ($fields as $field) { |
| 327 | - if ($field->primary_key === 1) |
|
| 328 | - $primary_ids[] = $field->name; |
|
| 329 | - |
|
| 330 | - elseif ($field->name == 'created_at' || $field->name == 'updated_at') |
|
| 331 | - continue; |
|
| 332 | - |
|
| 333 | - else |
|
| 334 | - $attributes[] = $field->name; |
|
| 336 | + if ($field->primary_key === 1) { |
|
| 337 | + $primary_ids[] = $field->name; |
|
| 338 | + } elseif ($field->name == 'created_at' || $field->name == 'updated_at') { |
|
| 339 | + continue; |
|
| 340 | + } else { |
|
| 341 | + $attributes[] = $field->name; |
|
| 342 | + } |
|
| 335 | 343 | } |
| 336 | 344 | |
| 337 | 345 | //Model only support single column in primary key getting the first one |
@@ -357,13 +365,16 @@ discard block |
||
| 357 | 365 | */ |
| 358 | 366 | public function validationRules(array $fields) |
| 359 | 367 | { |
| 360 | - if (empty($fields)) return '[]'; |
|
| 368 | + if (empty($fields)) { |
|
| 369 | + return '[]'; |
|
| 370 | + } |
|
| 361 | 371 | |
| 362 | 372 | $rules = []; |
| 363 | 373 | |
| 364 | 374 | foreach ($fields as $field) { |
| 365 | - if (in_array($field->name, ['created_at', 'updated_at'])) |
|
| 366 | - continue; |
|
| 375 | + if (in_array($field->name, ['created_at', 'updated_at'])) { |
|
| 376 | + continue; |
|
| 377 | + } |
|
| 367 | 378 | |
| 368 | 379 | $rule = []; |
| 369 | 380 | |