12
12
use JTMcC \AtomicDeployments \Exceptions \ExecuteFailedException ;
13
13
use JTMcC \AtomicDeployments \Helpers \FileHelper ;
14
14
use JTMcC \AtomicDeployments \Interfaces \DeploymentInterface ;
15
- use JTMcC \AtomicDeployments \Models \AtomicDeployment as Model ;
15
+ use JTMcC \AtomicDeployments \Models \AtomicDeployment ;
16
16
use JTMcC \AtomicDeployments \Models \Enums \DeploymentStatus ;
17
17
18
18
class AtomicDeploymentService
@@ -47,7 +47,7 @@ public function __construct(DeploymentInterface $deployment, array $migrate = []
47
47
48
48
register_shutdown_function ([$ this , 'shutdown ' ]);
49
49
50
- $ this ->initialDeploymentPath = $ deployment ->getCurrentDeploymentPath ();
50
+ $ this ->initialDeploymentPath = $ deployment ->getCurrentPath ();
51
51
}
52
52
53
53
/**
@@ -69,10 +69,10 @@ public function getInitialDeploymentPath(): string
69
69
/**
70
70
* Run full deployment.
71
71
*
72
- * @param Closure|null $success
73
- * @param Closure|null $failed
72
+ * @param Closure|null $successCallback
73
+ * @param Closure|null $failedCallback
74
74
*/
75
- public function deploy (?Closure $ success = null , ?Closure $ failed = null ): void
75
+ public function deploy (?Closure $ successCallback = null , ?Closure $ failedCallback = null ): void
76
76
{
77
77
try {
78
78
if ($ this ->isDryRun ()) {
@@ -98,14 +98,14 @@ public function deploy(?Closure $success = null, ?Closure $failed = null): void
98
98
99
99
DeploymentSuccessful::dispatch ($ this , $ this ->deployment ->getModel ());
100
100
101
- if ($ success ) {
102
- $ success ($ this );
101
+ if ($ successCallback ) {
102
+ $ successCallback ($ this );
103
103
}
104
104
} catch (\Throwable $ e ) {
105
- $ this ->failed ();
105
+ $ this ->fail ();
106
106
Output::throwable ($ e );
107
- if ($ failed ) {
108
- $ failed ($ this );
107
+ if ($ failedCallback ) {
108
+ $ failedCallback ($ this );
109
109
}
110
110
}
111
111
}
@@ -120,18 +120,18 @@ public function updateDeploymentStatus(int $status): void
120
120
121
121
return ;
122
122
}
123
- $ this ->deployment ->updateDeploymentStatus ($ status );
123
+ $ this ->deployment ->updateStatus ($ status );
124
124
}
125
125
126
126
public function linkDeployment (): void
127
127
{
128
- Output::info ("Creating symbolic link: {$ this ->deployment ->getDeploymentLink ()} -> {$ this ->deployment ->getDeploymentPath ()}" );
128
+ Output::info ("Creating symbolic link: {$ this ->deployment ->getLink ()} -> {$ this ->deployment ->getPath ()}" );
129
129
if ($ this ->isDryRun ()) {
130
130
Output::warn ('Dry run - Skipping symbolic link deployment ' );
131
131
132
132
return ;
133
133
}
134
- $ this ->deployment ->linkDeployment ();
134
+ $ this ->deployment ->link ();
135
135
Output::info ('Link created ' );
136
136
}
137
137
@@ -153,8 +153,8 @@ public function confirmSymbolicLink(): bool
153
153
if (!$ this ->deployment ->isDeployed ()) {
154
154
throw new ExecuteFailedException (
155
155
'Expected deployment link to direct to ' .
156
- $ this ->deployment ->getDeploymentPath ().' but found ' .
157
- $ this ->deployment ->getCurrentDeploymentPath ()
156
+ $ this ->deployment ->getPath ().' but found ' .
157
+ $ this ->deployment ->getCurrentPath ()
158
158
);
159
159
}
160
160
@@ -165,7 +165,7 @@ public function confirmSymbolicLink(): bool
165
165
166
166
public function createDeploymentDirectory (): void
167
167
{
168
- Output::info ("Creating directory at {$ this ->deployment ->getDeploymentPath ()}" );
168
+ Output::info ("Creating directory at {$ this ->deployment ->getPath ()}" );
169
169
170
170
if ($ this ->isDryRun ()) {
171
171
Output::warn ('Dry run - Skipping creating deployment directory ' );
@@ -209,7 +209,7 @@ public function copyMigrationContents(): void
209
209
}
210
210
211
211
$ rootFrom = rtrim ($ this ->initialDeploymentPath , DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR ;
212
- $ rootTo = rtrim ($ this ->deployment ->getDeploymentPath (), DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR ;
212
+ $ rootTo = rtrim ($ this ->deployment ->getPath (), DIRECTORY_SEPARATOR ).DIRECTORY_SEPARATOR ;
213
213
214
214
foreach (File::glob ($ rootFrom .$ pattern ) as $ from ) {
215
215
$ dir = $ from ;
@@ -254,7 +254,7 @@ public function updateSymlinks()
254
254
255
255
FileHelper::recursivelyUpdateSymlinks (
256
256
$ this ->getDeployment ()->getBuildPath (),
257
- $ this ->getDeployment ()->getDeploymentPath ()
257
+ $ this ->getDeployment ()->getPath ()
258
258
);
259
259
260
260
Output::info ('Finished correcting symlinks ' );
@@ -265,7 +265,7 @@ public function rollback(): void
265
265
Output::warn ('Atomic deployment rollback has been requested ' );
266
266
267
267
if (!$ this ->isDryRun ()) {
268
- $ currentPath = $ this ->deployment ->getCurrentDeploymentPath ();
268
+ $ currentPath = $ this ->deployment ->getCurrentPath ();
269
269
270
270
if (
271
271
//confirm if we need to revert the link
@@ -276,8 +276,8 @@ public function rollback(): void
276
276
277
277
try {
278
278
//attempt to revert link to our original path
279
- Exec::ln ($ this ->deployment ->getDeploymentLink (), $ this ->initialDeploymentPath );
280
- if ($ this ->deployment ->getCurrentDeploymentPath () === $ this ->initialDeploymentPath ) {
279
+ Exec::ln ($ this ->deployment ->getLink (), $ this ->initialDeploymentPath );
280
+ if ($ this ->deployment ->getCurrentPath () === $ this ->initialDeploymentPath ) {
281
281
Output::info ('Successfully rolled back symbolic link ' );
282
282
283
283
return ;
@@ -300,7 +300,7 @@ public function isDryRun(): bool
300
300
return $ this ->dryRun ;
301
301
}
302
302
303
- public function failed (): void
303
+ public function fail (): void
304
304
{
305
305
$ this ->rollback ();
306
306
DeploymentFailed::dispatch ($ this , $ this ->deployment ->getModel ());
@@ -311,7 +311,7 @@ public function shutdown(): void
311
311
{
312
312
if ($ error = error_get_last ()) {
313
313
Output::error ('Error detected during shutdown, requesting rollback ' );
314
- $ this ->failed ();
314
+ $ this ->fail ();
315
315
}
316
316
}
317
317
@@ -320,16 +320,16 @@ public function cleanBuilds(int $limit): void
320
320
Output::alert ('Running Build Cleanup ' );
321
321
Output::info ("Max deployment directories allowed set to {$ limit }" );
322
322
323
- $ buildIDs = Model ::successful ()
323
+ $ buildIDs = AtomicDeployment ::successful ()
324
324
->orderBy ('id ' , 'desc ' )
325
325
->limit ($ limit )
326
326
->pluck ('id ' );
327
327
328
- $ buildsToRemove = Model ::whereNotIn ('id ' , $ buildIDs )->get ();
328
+ $ buildsToRemove = AtomicDeployment ::whereNotIn ('id ' , $ buildIDs )->get ();
329
329
330
- $ found = $ buildsToRemove ->count ();
330
+ $ countOfBuildsToRemove = $ buildsToRemove ->count ();
331
331
332
- Output::info ('Found ' .$ found .' ' .Pluralizer::plural ('folder ' , $ found ).' to be removed ' );
332
+ Output::info ('Found ' .$ countOfBuildsToRemove .' ' .Pluralizer::plural ('folder ' , $ countOfBuildsToRemove ).' to be removed ' );
333
333
334
334
foreach ($ buildsToRemove as $ deployment ) {
335
335
if ($ deployment ->isCurrentlyDeployed ) {
0 commit comments