@@ -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) { |
@@ -118,7 +118,7 @@ |
||
| 118 | 118 | //if field need null |
| 119 | 119 | $singleField .= "\n\t\t\t'null' => " . (($field->Null == 'YES') ? 'true,' : 'false,'); |
| 120 | 120 | |
| 121 | - if(!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) |
|
| 121 | + if (!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) |
|
| 122 | 122 | $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
| 123 | 123 | |
| 124 | 124 | //unsigned |
@@ -90,48 +90,54 @@ discard block |
||
| 90 | 90 | foreach ($query as $field) { |
| 91 | 91 | $singleField = "\n\t\t'$field->Field' => ["; |
| 92 | 92 | //Type |
| 93 | - if (preg_match('/^([a-z]+)/', $field->Type, $matches) > 0) |
|
| 94 | - $singleField .= "\n\t\t\t'type' => '" . strtoupper($matches[1]) . "',"; |
|
| 93 | + if (preg_match('/^([a-z]+)/', $field->Type, $matches) > 0) { |
|
| 94 | + $singleField .= "\n\t\t\t'type' => '" . strtoupper($matches[1]) . "',"; |
|
| 95 | + } |
|
| 95 | 96 | |
| 96 | 97 | //Constraint |
| 97 | 98 | if (preg_match('/\((.+)\)/', $field->Type, $matches) > 0) { |
| 98 | 99 | //integer , varchar |
| 99 | - if (is_numeric($matches[1])) |
|
| 100 | - $singleField .= "\n\t\t\t'constraint' => " . $matches[1] . ","; |
|
| 100 | + if (is_numeric($matches[1])) { |
|
| 101 | + $singleField .= "\n\t\t\t'constraint' => " . $matches[1] . ","; |
|
| 102 | + } |
|
| 101 | 103 | |
| 102 | 104 | //float , double |
| 103 | - elseif (preg_match('/[\d]+\s?,[\d]+\s?/', $matches[1]) > 0) |
|
| 104 | - $singleField .= "\n\t\t\t'constraint' => '" . $matches[1] . "',"; |
|
| 105 | + elseif (preg_match('/[\d]+\s?,[\d]+\s?/', $matches[1]) > 0) { |
|
| 106 | + $singleField .= "\n\t\t\t'constraint' => '" . $matches[1] . "',"; |
|
| 107 | + } |
|
| 105 | 108 | |
| 106 | 109 | //Enum Fields |
| 107 | 110 | else { |
| 108 | 111 | $values = explode(',', str_replace("'", "", $matches[1])); |
| 109 | 112 | |
| 110 | - if (count($values) == 1) |
|
| 111 | - $singleField .= "\n\t\t\t'constraint' => [" . $this->getGluedString($values) . "],"; |
|
| 112 | - |
|
| 113 | - else |
|
| 114 | - $singleField .= "\n\t\t\t'constraint' => " . $this->getGluedString($values) . ","; |
|
| 113 | + if (count($values) == 1) { |
|
| 114 | + $singleField .= "\n\t\t\t'constraint' => [" . $this->getGluedString($values) . "],"; |
|
| 115 | + } else { |
|
| 116 | + $singleField .= "\n\t\t\t'constraint' => " . $this->getGluedString($values) . ","; |
|
| 117 | + } |
|
| 115 | 118 | } |
| 116 | 119 | } |
| 117 | 120 | |
| 118 | 121 | //if field need null |
| 119 | 122 | $singleField .= "\n\t\t\t'null' => " . (($field->Null == 'YES') ? 'true,' : 'false,'); |
| 120 | 123 | |
| 121 | - if(!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) |
|
| 122 | - $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
|
| 124 | + if(!is_null($field->Default) && (strpos($field->Default, 'current_timestamp()') === FALSE)) { |
|
| 125 | + $singleField .= "\n\t\t\t'default' => '$field->Default',"; |
|
| 126 | + } |
|
| 123 | 127 | |
| 124 | 128 | //unsigned |
| 125 | - if (strpos($field->Type, 'unsigned') !== false) |
|
| 126 | - $singleField .= "\n\t\t\t'unsigned' => true,"; |
|
| 129 | + if (strpos($field->Type, 'unsigned') !== false) { |
|
| 130 | + $singleField .= "\n\t\t\t'unsigned' => true,"; |
|
| 131 | + } |
|
| 127 | 132 | |
| 128 | 133 | /* //Unique Key |
| 129 | 134 | if ($field->Key == 'UNI') |
| 130 | 135 | $singleField .= "\n\t\t\t'unique' => true,";*/ |
| 131 | 136 | |
| 132 | 137 | //autoincrement |
| 133 | - if (strpos($field->Extra, 'auto_increment') !== false) |
|
| 134 | - $singleField .= "\n\t\t\t'auto_increment' => true,"; |
|
| 138 | + if (strpos($field->Extra, 'auto_increment') !== false) { |
|
| 139 | + $singleField .= "\n\t\t\t'auto_increment' => true,"; |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | 142 | $singleField .= "\n\t\t],"; |
| 137 | 143 | $fieldString .= $singleField; |
@@ -149,22 +155,23 @@ discard block |
||
| 149 | 155 | { |
| 150 | 156 | |
| 151 | 157 | //array consist of one element |
| 152 | - if (count($arr) == 1) |
|
| 153 | - return "'" . strval(array_shift($arr)) . "'"; |
|
| 154 | - |
|
| 155 | - else { |
|
| 158 | + if (count($arr) == 1) { |
|
| 159 | + return "'" . strval(array_shift($arr)) . "'"; |
|
| 160 | + } else { |
|
| 156 | 161 | |
| 157 | 162 | $str = ''; |
| 158 | 163 | if (!$is_assoc) { |
| 159 | 164 | foreach ($arr as $item) { |
| 160 | - if (strlen($item) > 0) |
|
| 161 | - $str .= "'$item', "; |
|
| 165 | + if (strlen($item) > 0) { |
|
| 166 | + $str .= "'$item', "; |
|
| 167 | + } |
|
| 162 | 168 | } |
| 163 | 169 | |
| 164 | 170 | } else { |
| 165 | 171 | foreach ($arr as $index => $item) { |
| 166 | - if (strlen($item) > 0) |
|
| 167 | - $str .= "'$index' => '$item',"; |
|
| 172 | + if (strlen($item) > 0) { |
|
| 173 | + $str .= "'$index' => '$item',"; |
|
| 174 | + } |
|
| 168 | 175 | } |
| 169 | 176 | } |
| 170 | 177 | |
@@ -217,8 +224,9 @@ discard block |
||
| 217 | 224 | { |
| 218 | 225 | $keys = $this->db->getForeignKeyData($table); |
| 219 | 226 | $keyArray = []; |
| 220 | - foreach ($keys as $key) |
|
| 221 | - array_push($keyArray, "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->foreign_column_name','CASCADE','CASCADE');"); |
|
| 227 | + foreach ($keys as $key) { |
|
| 228 | + array_push($keyArray, "\n\t\t\$this->forge->addForeignKey('$key->column_name','$key->foreign_table_name','$key->foreign_column_name','CASCADE','CASCADE');"); |
|
| 229 | + } |
|
| 222 | 230 | |
| 223 | 231 | return implode('', array_unique($keyArray)); |
| 224 | 232 | } |
@@ -279,8 +287,9 @@ discard block |
||
| 279 | 287 | } |
| 280 | 288 | |
| 281 | 289 | //property cast |
| 282 | - if ($field->type == 'tinyint') |
|
| 283 | - $casts[$field->name] = (($field->nullable) ? "?" : '') . "boolean"; |
|
| 290 | + if ($field->type == 'tinyint') { |
|
| 291 | + $casts[$field->name] = (($field->nullable) ? "?" : '') . "boolean"; |
|
| 292 | + } |
|
| 284 | 293 | |
| 285 | 294 | } |
| 286 | 295 | |
@@ -303,14 +312,13 @@ discard block |
||
| 303 | 312 | $fields = $this->db->getFieldData($table); |
| 304 | 313 | |
| 305 | 314 | foreach ($fields as $field) { |
| 306 | - if ($field->primary_key === 1) |
|
| 307 | - $primary_ids[] = $field->name; |
|
| 308 | - |
|
| 309 | - elseif ($field->name == 'created_at' || $field->name == 'updated_at') |
|
| 310 | - continue; |
|
| 311 | - |
|
| 312 | - else |
|
| 313 | - $attributes[] = $field->name; |
|
| 315 | + if ($field->primary_key === 1) { |
|
| 316 | + $primary_ids[] = $field->name; |
|
| 317 | + } elseif ($field->name == 'created_at' || $field->name == 'updated_at') { |
|
| 318 | + continue; |
|
| 319 | + } else { |
|
| 320 | + $attributes[] = $field->name; |
|
| 321 | + } |
|
| 314 | 322 | } |
| 315 | 323 | |
| 316 | 324 | //Model only support single column in primary key getting the first one |
@@ -336,13 +344,16 @@ discard block |
||
| 336 | 344 | */ |
| 337 | 345 | public function validationRules(array $fields) |
| 338 | 346 | { |
| 339 | - if (empty($fields)) return '[]'; |
|
| 347 | + if (empty($fields)) { |
|
| 348 | + return '[]'; |
|
| 349 | + } |
|
| 340 | 350 | |
| 341 | 351 | $rules = []; |
| 342 | 352 | |
| 343 | 353 | foreach ($fields as $field) { |
| 344 | - if (in_array($field->name, ['created_at', 'updated_at'])) |
|
| 345 | - continue; |
|
| 354 | + if (in_array($field->name, ['created_at', 'updated_at'])) { |
|
| 355 | + continue; |
|
| 356 | + } |
|
| 346 | 357 | |
| 347 | 358 | $rule = []; |
| 348 | 359 | |