Conditions | 1 |
Paths | 1 |
Total Lines | 84 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
20 | public function up(Schema $schema) : void |
||
21 | { |
||
22 | // this up() migration is auto-generated, please modify it to your needs |
||
23 | $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
||
24 | |||
25 | $this->addSql('ALTER TABLE users ADD id_preview_attachement INT DEFAULT NULL, ADD pw_reset_token VARCHAR(255) DEFAULT NULL, ADD pw_reset_expires DATETIME DEFAULT NULL, ADD disabled TINYINT(1) NOT NULL, DROP config_image_path'); |
||
26 | $this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E96DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
27 | $this->addSql('CREATE INDEX IDX_1483A5E96DEDCEC2 ON users (id_preview_attachement)'); |
||
28 | $this->addSql('ALTER TABLE attachment_types ADD id_preview_attachement INT DEFAULT NULL'); |
||
29 | $this->addSql('ALTER TABLE attachment_types ADD CONSTRAINT FK_EFAED7196DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
30 | $this->addSql('CREATE INDEX IDX_EFAED7196DEDCEC2 ON attachment_types (id_preview_attachement)'); |
||
31 | $this->addSql('ALTER TABLE categories ADD id_preview_attachement INT DEFAULT NULL'); |
||
32 | $this->addSql('ALTER TABLE categories ADD CONSTRAINT FK_3AF346686DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
33 | $this->addSql('CREATE INDEX IDX_3AF346686DEDCEC2 ON categories (id_preview_attachement)'); |
||
34 | $this->addSql('ALTER TABLE currencies ADD id_preview_attachement INT DEFAULT NULL'); |
||
35 | $this->addSql('ALTER TABLE currencies ADD CONSTRAINT FK_37C446936DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
36 | $this->addSql('CREATE INDEX IDX_37C446936DEDCEC2 ON currencies (id_preview_attachement)'); |
||
37 | $this->addSql('ALTER TABLE devices ADD id_preview_attachement INT DEFAULT NULL'); |
||
38 | $this->addSql('ALTER TABLE devices ADD CONSTRAINT FK_11074E9A6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
39 | $this->addSql('CREATE INDEX IDX_11074E9A6DEDCEC2 ON devices (id_preview_attachement)'); |
||
40 | |||
41 | $this->addSql('ALTER TABLE attachments DROP FOREIGN KEY FK_47C4FAD61F1F2A24'); |
||
42 | $this->addSql('ALTER TABLE attachments ADD original_filename VARCHAR(255) DEFAULT NULL, CHANGE filename path VARCHAR(255) NOT NULL'); |
||
43 | |||
44 | //Before we drop the filename and filename_3d properties we have to migrate the data to attachments |
||
45 | $this->addSql("INSERT INTO `attachment_types` (`id`, `name`, `parent_id`, `comment`, `datetime_added`, `last_modified`, `filetype_filter`) |
||
46 | VALUES |
||
47 | (1000, 'Footprints', NULL, 'Created during automatic migration of the footprint files.', current_timestamp(), current_timestamp(), 'apng, bmp, gif, ico, cur, jpg, jpeg, jfif, pjpeg, pjp, png, svg, webp'), |
||
48 | (1001, 'Footprints (3D)', NULL, 'Created during automatic migration of the footprint files.', current_timestamp(), current_timestamp(), 'x3d') |
||
49 | "); |
||
50 | |||
51 | //Add a attachment for each footprint attachment |
||
52 | $this->addSql( |
||
53 | 'INSERT INTO attachments (element_id, type_id, name, class_name, path, last_modified, datetime_added) ' . |
||
54 | "SELECT footprints.id, 1000, 'Footprint', 'Footprint', footprints.filename, NOW(), NOW() FROM footprints " . |
||
55 | "WHERE footprints.filename <> ''" |
||
56 | ); |
||
57 | |||
58 | //Do the same for 3D Footprints |
||
59 | $this->addSql( |
||
60 | 'INSERT INTO attachments (element_id, type_id, name, class_name, path, last_modified, datetime_added) ' . |
||
61 | "SELECT footprints.id, 1001, 'Footprint 3D', 'Footprint', footprints.filename_3d, NOW(), NOW() FROM footprints " . |
||
62 | "WHERE footprints.filename_3d <> ''" |
||
63 | ); |
||
64 | |||
65 | $this->addSql('ALTER TABLE footprints ADD id_footprint_3d INT DEFAULT NULL, ADD id_preview_attachement INT DEFAULT NULL, DROP filename, DROP filename_3d'); |
||
66 | $this->addSql('ALTER TABLE footprints ADD CONSTRAINT FK_A34D68A232A38C34 FOREIGN KEY (id_footprint_3d) REFERENCES `attachments` (id)'); |
||
67 | $this->addSql('ALTER TABLE footprints ADD CONSTRAINT FK_A34D68A26DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
68 | $this->addSql('CREATE INDEX IDX_A34D68A232A38C34 ON footprints (id_footprint_3d)'); |
||
69 | $this->addSql('CREATE INDEX IDX_A34D68A26DEDCEC2 ON footprints (id_preview_attachement)'); |
||
70 | |||
71 | //Set the created footprint attachments as preview image / 3D footprint image |
||
72 | $this->addSql('UPDATE footprints, attachments |
||
73 | SET footprints.id_preview_attachement = attachments.id |
||
74 | WHERE attachments.class_name = "Footprint" AND attachments.element_id = footprints.id |
||
75 | AND attachments.type_id = 1000; |
||
76 | '); |
||
77 | |||
78 | $this->addSql('UPDATE footprints, attachments |
||
79 | SET footprints.id_footprint_3d = attachments.id |
||
80 | WHERE attachments.class_name = "Footprint" AND attachments.element_id = footprints.id |
||
81 | AND attachments.type_id = 1001; |
||
82 | '); |
||
83 | |||
84 | $this->addSql('ALTER TABLE manufacturers ADD id_preview_attachement INT DEFAULT NULL'); |
||
85 | $this->addSql('ALTER TABLE manufacturers ADD CONSTRAINT FK_94565B126DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
86 | $this->addSql('CREATE INDEX IDX_94565B126DEDCEC2 ON manufacturers (id_preview_attachement)'); |
||
87 | $this->addSql('ALTER TABLE measurement_units ADD id_preview_attachement INT DEFAULT NULL'); |
||
88 | $this->addSql('ALTER TABLE measurement_units ADD CONSTRAINT FK_F5AF83CF6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
89 | $this->addSql('CREATE INDEX IDX_F5AF83CF6DEDCEC2 ON measurement_units (id_preview_attachement)'); |
||
90 | $this->addSql('ALTER TABLE storelocations ADD id_preview_attachement INT DEFAULT NULL'); |
||
91 | $this->addSql('ALTER TABLE storelocations ADD CONSTRAINT FK_75170206DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
92 | $this->addSql('CREATE INDEX IDX_75170206DEDCEC2 ON storelocations (id_preview_attachement)'); |
||
93 | $this->addSql('ALTER TABLE suppliers ADD id_preview_attachement INT DEFAULT NULL'); |
||
94 | $this->addSql('ALTER TABLE suppliers ADD CONSTRAINT FK_AC28B95C6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
95 | $this->addSql('CREATE INDEX IDX_AC28B95C6DEDCEC2 ON suppliers (id_preview_attachement)'); |
||
96 | $this->addSql('ALTER TABLE `groups` ADD id_preview_attachement INT DEFAULT NULL'); |
||
97 | $this->addSql('ALTER TABLE `groups` ADD CONSTRAINT FK_F06D39706DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
98 | $this->addSql('CREATE INDEX IDX_F06D39706DEDCEC2 ON `groups` (id_preview_attachement)'); |
||
99 | $this->addSql('ALTER TABLE parts DROP FOREIGN KEY FK_6940A7FEEBBCC786'); |
||
100 | $this->addSql('DROP INDEX IDX_6940A7FEEBBCC786 ON parts'); |
||
101 | $this->addSql('ALTER TABLE parts CHANGE id_master_picture_attachement id_preview_attachement INT DEFAULT NULL'); |
||
102 | $this->addSql('ALTER TABLE parts ADD CONSTRAINT FK_6940A7FE6DEDCEC2 FOREIGN KEY (id_preview_attachement) REFERENCES `attachments` (id)'); |
||
103 | $this->addSql('CREATE INDEX IDX_6940A7FE6DEDCEC2 ON parts (id_preview_attachement)'); |
||
104 | } |
||
155 |