@@ -27,6 +27,11 @@ class Migration
2727 * @var CommandInterface
2828 */
2929 protected $ _dbCommand ;
30+
31+ /**
32+ * @var Callable
33+ */
34+ protected $ _callableProgress ;
3035
3136 /**
3237 * Migration constructor.
@@ -39,8 +44,8 @@ public function __construct(ConnectionManagement $_connection, $_folder)
3944 $ this ->_connection = $ _connection ;
4045 $ this ->_folder = $ _folder ;
4146
42- if (!file_exists ($ this ->_folder ) || ! is_dir ( $ this -> _folder )) {
43- throw new \InvalidArgumentException ("Base migrations directory ' {$ this ->_folder }' not found " );
47+ if (!file_exists ($ this ->_folder . ' /base.sql ' )) {
48+ throw new \InvalidArgumentException ("Migration script ' {$ this ->_folder }/base.sql ' not found " );
4449 }
4550 }
4651
@@ -114,6 +119,9 @@ public function prepareEnvironment()
114119 */
115120 public function reset ($ upVersion = null )
116121 {
122+ if ($ this ->_callableProgress ) {
123+ call_user_func_array ($ this ->_callableProgress , ['reset ' , 0 ]);
124+ }
117125 $ this ->getDbCommand ()->dropDatabase ();
118126 $ this ->getDbCommand ()->createDatabase ();
119127 $ this ->getDbCommand ()->executeSql (file_get_contents ($ this ->getBaseSql ()));
@@ -161,8 +169,13 @@ protected function migrate($upVersion, $increment)
161169 while ($ this ->canContinue ($ currentVersion , $ upVersion , $ increment )
162170 && file_exists ($ file = $ this ->getMigrationSql ($ currentVersion , $ increment ))
163171 ) {
172+ if ($ this ->_callableProgress ) {
173+ call_user_func_array ($ this ->_callableProgress , ['migrate ' , $ currentVersion ]);
174+ }
175+
164176 $ this ->getDbCommand ()->executeSql (file_get_contents ($ file ));
165- $ this ->getDbCommand ()->setVersion ($ currentVersion ++);
177+ $ this ->getDbCommand ()->setVersion ($ currentVersion );
178+ $ currentVersion = $ currentVersion + $ increment ;
166179 }
167180 }
168181
@@ -185,4 +198,9 @@ public function down($upVersion)
185198 {
186199 $ this ->migrate ($ upVersion , -1 );
187200 }
201+
202+ public function addCallbackProgress (Callable $ callable )
203+ {
204+ $ this ->_callableProgress = $ callable ;
205+ }
188206}
0 commit comments