@@ 104-132 (lines=29) @@ | ||
101 | return $this->knownVersions; |
|
102 | } |
|
103 | ||
104 | private function up($data, $sourceVersion, $targetVersion) |
|
105 | { |
|
106 | while (version_compare($sourceVersion, $targetVersion, '<')) { |
|
107 | if (!isset($this->migrationsBySourceVersion[$sourceVersion])) { |
|
108 | throw new MigrationFailedException(sprintf( |
|
109 | 'No migration found to upgrade from version %s to %s.', |
|
110 | $sourceVersion, |
|
111 | $targetVersion |
|
112 | )); |
|
113 | } |
|
114 | ||
115 | $migration = $this->migrationsBySourceVersion[$sourceVersion]; |
|
116 | ||
117 | // Final version too high |
|
118 | if (version_compare($migration->getTargetVersion(), $targetVersion, '>')) { |
|
119 | throw new MigrationFailedException(sprintf( |
|
120 | 'No migration found to upgrade from version %s to %s.', |
|
121 | $sourceVersion, |
|
122 | $targetVersion |
|
123 | )); |
|
124 | } |
|
125 | ||
126 | $migration->up($data); |
|
127 | ||
128 | $this->versioner->updateVersion($data, $migration->getTargetVersion()); |
|
129 | ||
130 | $sourceVersion = $migration->getTargetVersion(); |
|
131 | } |
|
132 | } |
|
133 | ||
134 | private function down($data, $sourceVersion, $targetVersion) |
|
135 | { |
|
@@ 134-162 (lines=29) @@ | ||
131 | } |
|
132 | } |
|
133 | ||
134 | private function down($data, $sourceVersion, $targetVersion) |
|
135 | { |
|
136 | while (version_compare($sourceVersion, $targetVersion, '>')) { |
|
137 | if (!isset($this->migrationsByTargetVersion[$sourceVersion])) { |
|
138 | throw new MigrationFailedException(sprintf( |
|
139 | 'No migration found to downgrade from version %s to %s.', |
|
140 | $sourceVersion, |
|
141 | $targetVersion |
|
142 | )); |
|
143 | } |
|
144 | ||
145 | $migration = $this->migrationsByTargetVersion[$sourceVersion]; |
|
146 | ||
147 | // Final version too low |
|
148 | if (version_compare($migration->getSourceVersion(), $targetVersion, '<')) { |
|
149 | throw new MigrationFailedException(sprintf( |
|
150 | 'No migration found to downgrade from version %s to %s.', |
|
151 | $sourceVersion, |
|
152 | $targetVersion |
|
153 | )); |
|
154 | } |
|
155 | ||
156 | $migration->down($data); |
|
157 | ||
158 | $this->versioner->updateVersion($data, $migration->getSourceVersion()); |
|
159 | ||
160 | $sourceVersion = $migration->getSourceVersion(); |
|
161 | } |
|
162 | } |
|
163 | } |
|
164 |