@@ -27,12 +27,10 @@ public function runPending(array $migrations, array $options = []): void
2727
2828        $ batch$ this repository ->getNextBatchNumber ();
2929
30-         $ pretend$ options'pretend ' ] ?? false ;
31- 
3230        $ step$ options'step ' ] ?? false ;
3331
3432        foreach  ($ migrationsas  $ file
35-             $ this patch ($ file$ batch,  $ pretend 
33+             $ this patch ($ file$ batch
3634
3735            if  ($ step
3836                $ batch
@@ -45,40 +43,60 @@ public function runPending(array $migrations, array $options = []): void
4543     * 
4644     * @param string $file 
4745     * @param int $batch 
48-      * @param bool $pretend 
49-      * 
5046     * @return void 
5147     * @throws \Throwable 
5248     */ 
53-     protected  function  patch (string  $ fileint  $ batch,  bool   $ pretend void 
49+     protected  function  patch (string  $ fileint  $ batchvoid 
5450    {
55-         $ migration $ this resolvePath ($ file
51+         $ patch $ this resolvePath ($ file
5652
5753        $ name$ this getMigrationName ($ file
5854
59-         $ migrationsetContainer (app ())->setCommand (app ('command.patcher ' ));
60- 
61-         $ this note ("<comment>Patching:</comment>  {$ name );
55+         $ this note ("<comment>Patching:</comment>  $ name );
6256
6357        $ startTimemicrotime (true );
6458
65-         $ this runPatch ($ migration
59+         if  ($ patchinstanceof  Patch && $ this isEligible ($ patch
60+             $ patch
61+                 ->setContainer (app ())
62+                 ->setCommand (app ('command.patcher ' ))
63+                 ->setLogger (app ('log ' )->driver (PatcherServiceProvider::$ LOG_CHANNEL 
64+ 
65+             $ this runPatch ($ patch
6666
67-         $ runTimeround (microtime (true ) - $ startTime2 );
67+             $ runTimeround (microtime (true ) - $ startTime2 );
68+ 
69+             $ this repository ->log ($ name$ batch
70+ 
71+             $ this note ("<info>Patched:</info>   $ name ( $ runTime seconds). " );
72+         } else  {
73+             $ this note ("<comment>Skipped:</comment>  $ name is not eligible to run in current condition. " );
74+         }
75+     }
6876
69-         $ this repository ->log ($ name$ batch
77+     /** 
78+      * Determine if patcher should run. 
79+      * 
80+      * @param \Dentro\Patcher\Patch $patch 
81+      * @return bool 
82+      */ 
83+     public  function  isEligible (Patch $ patchbool 
84+     {
85+         if  (method_exists ($ patch'eligible ' )) {
86+             return  $ patcheligible ();
87+         }
7088
71-         $ this -> note ( " <info>Patched:</info>   { $ name }  ( { $ runTime }  seconds) " ) ;
89+         return   true ;
7290    }
7391
7492    /** 
7593     * Run a migration inside a transaction if the database supports it. 
7694     * 
77-      * @param object  $patch 
95+      * @param \Dentro\Patcher\Patch  $patch 
7896     * @return void 
7997     * @throws \Throwable 
8098     */ 
81-     protected  function  runPatch (object $ patchvoid 
99+     protected  function  runPatch (Patch $ patchvoid 
82100    {
83101        $ connection$ this resolveConnection (
84102            $ patchgetConnection ()
@@ -102,9 +120,11 @@ protected function runPatch(object $patch): void
102120            }
103121        };
104122
105-         $ this getSchemaGrammar ($ connectionsupportsSchemaTransactions ()
106-         && $ patchwithinTransaction 
107-             ? $ connectiontransaction ($ callback
108-             : $ callback
123+         if  ($ patchwithinTransaction  && $ this getSchemaGrammar ($ connectionsupportsSchemaTransactions ()) {
124+             $ connectiontransaction ($ callback
125+             return ;
126+         }
127+ 
128+         $ callback
109129    }
110130}
0 commit comments