| Conditions | 11 |
| Paths | 176 |
| Total Lines | 105 |
| Code Lines | 89 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 108 | public static function activate(): int |
||
| 109 | { |
||
| 110 | $fields = self::getFieldsStructure(); |
||
| 111 | $i = 0; |
||
| 112 | foreach (self::FIELDS as $moduleName => $value) { |
||
| 113 | $fieldsExists = (new \App\Db\Query())->select(['fieldname'])->from('vtiger_field') |
||
| 114 | ->where(['tabid' => \App\Module::getModuleId($moduleName), 'fieldname' => array_keys($fields)])->column(); |
||
| 115 | if ($fieldsToAdd = array_diff_key(array_intersect_key($fields, array_flip($value['fields'])), array_flip($fieldsExists))) { |
||
| 116 | $blockModel = vtlib\Block::getInstance($value['block']['name'], $moduleName); |
||
| 117 | if (!$blockModel) { |
||
| 118 | if ($value['block']['create']) { |
||
| 119 | $blockModel = new vtlib\Block(); |
||
| 120 | $blockModel->label = $value['block']['name']; |
||
| 121 | vtlib\Module::getInstance($moduleName)->addBlock($blockModel); |
||
| 122 | } else { |
||
| 123 | $blocks = vtlib\Block::getAllForModule(vtlib\Module::getInstance($moduleName)); |
||
| 124 | $blockModel = current($blocks); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | foreach ($fieldsToAdd as $fieldName => &$fieldData) { |
||
| 128 | if (isset($value['fieldsData'][$fieldName])) { |
||
| 129 | $fieldData = array_merge($fieldData, $value['fieldsData'][$fieldName]); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | self::addFields($fieldsToAdd, $blockModel); |
||
| 133 | $i += \count($fieldsToAdd); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | $importer = new \App\Db\Importers\Base(); |
||
| 137 | $dbLog = \App\Db::getInstance('log'); |
||
| 138 | if (!$dbLog->isTableExists(Comarch::LOG_TABLE_NAME)) { |
||
| 139 | $dbLog->createTable(Comarch::LOG_TABLE_NAME, [ |
||
| 140 | 'id' => $importer->primaryKeyUnsigned(), |
||
| 141 | 'server_id' => $importer->integer(10)->unsigned()->notNull(), |
||
| 142 | 'time' => $importer->dateTime()->notNull(), |
||
| 143 | 'error' => $importer->tinyInteger(1)->unsigned()->defaultValue(0), |
||
| 144 | 'message' => $importer->stringType(255), |
||
| 145 | 'params' => $importer->text(), |
||
| 146 | 'trace' => $importer->text(), |
||
| 147 | ]); |
||
| 148 | ++$i; |
||
| 149 | } |
||
| 150 | $db = \App\Db::getInstance('admin'); |
||
| 151 | $tableServer = $db->convertTablePrefix(Comarch::TABLE_NAME); |
||
| 152 | if (!$db->isTableExists(Comarch::MAP_TABLE_NAME)) { |
||
| 153 | $table = $db->convertTablePrefix(Comarch::MAP_TABLE_NAME); |
||
| 154 | $db->createTable(Comarch::MAP_TABLE_NAME, [ |
||
| 155 | 'server_id' => $importer->integer(10)->unsigned()->notNull(), |
||
| 156 | 'map' => $importer->stringType(50)->notNull(), |
||
| 157 | 'class' => $importer->stringType(100)->notNull(), |
||
| 158 | ]); |
||
| 159 | $db->createCommand() |
||
| 160 | ->createIndex($table . '_server_id_idx', Comarch::MAP_TABLE_NAME, 'server_id') |
||
| 161 | ->execute(); |
||
| 162 | $db->createCommand()->addForeignKey( |
||
| 163 | $table . '_ibfk_1', |
||
| 164 | Comarch::MAP_TABLE_NAME, 'server_id', |
||
| 165 | $tableServer, 'id', |
||
| 166 | 'CASCADE', null |
||
| 167 | )->execute(); |
||
| 168 | ++$i; |
||
| 169 | } |
||
| 170 | if (!$db->isTableExists(Comarch::CONFIG_TABLE_NAME)) { |
||
| 171 | $table = $db->convertTablePrefix(Comarch::CONFIG_TABLE_NAME); |
||
| 172 | $db->createTable(Comarch::CONFIG_TABLE_NAME, [ |
||
| 173 | 'server_id' => $importer->integer(10)->unsigned()->notNull(), |
||
| 174 | 'name' => $importer->stringType(50)->notNull(), |
||
| 175 | 'value' => $importer->stringType(50)->null(), |
||
| 176 | ]); |
||
| 177 | $db->createCommand() |
||
| 178 | ->createIndex($table . '_server_id_idx', Comarch::CONFIG_TABLE_NAME, 'server_id') |
||
| 179 | ->execute(); |
||
| 180 | $db->createCommand()->addForeignKey( |
||
| 181 | $table . '_id_ibfk_1', |
||
| 182 | Comarch::CONFIG_TABLE_NAME, 'server_id', |
||
| 183 | $tableServer, 'id', |
||
| 184 | 'CASCADE', null |
||
| 185 | )->execute(); |
||
| 186 | ++$i; |
||
| 187 | } |
||
| 188 | if (!$db->isTableExists(Comarch::QUEUE_TABLE_NAME)) { |
||
| 189 | $table = $db->convertTablePrefix(Comarch::QUEUE_TABLE_NAME); |
||
| 190 | $db->createTable(Comarch::QUEUE_TABLE_NAME, [ |
||
| 191 | 'id' => $importer->primaryKeyUnsigned(), |
||
| 192 | 'server_id' => $importer->integer(10)->unsigned()->notNull(), |
||
| 193 | 'name' => $importer->stringType(50)->notNull(), |
||
| 194 | 'value' => $importer->stringType(50)->null(), |
||
| 195 | 'type' => $importer->stringType(50)->notNull(), |
||
| 196 | 'counter' => $importer->smallInteger(1)->notNull()->defaultValue(1), |
||
| 197 | ]); |
||
| 198 | $db->createCommand() |
||
| 199 | ->createIndex($table . '_server_type_idx', Comarch::QUEUE_TABLE_NAME, ['server_id', 'name', 'type']) |
||
| 200 | ->execute(); |
||
| 201 | $db->createCommand()->addForeignKey( |
||
| 202 | $table . '_ibfk_1', |
||
| 203 | Comarch::QUEUE_TABLE_NAME, 'server_id', |
||
| 204 | $tableServer, 'id', |
||
| 205 | 'CASCADE', null |
||
| 206 | )->execute(); |
||
| 207 | ++$i; |
||
| 208 | } |
||
| 209 | \App\EventHandler::setActive('Products_DuplicateEan_Handler', 'EditViewPreSave'); |
||
| 210 | \App\EventHandler::setActive('Accounts_DuplicateShortName_Handler', 'EditViewPreSave'); |
||
| 211 | \App\Cron::updateStatus(\App\Cron::STATUS_ENABLED, 'LBL_COMARCH'); |
||
| 212 | return $i; |
||
|
|
|||
| 213 | } |
||
| 253 |