1010use JTMcC \AtomicDeployments \Events \DeploymentFailed ;
1111use JTMcC \AtomicDeployments \Events \DeploymentSuccessful ;
1212use JTMcC \AtomicDeployments \Exceptions \ExecuteFailedException ;
13+ use JTMcC \AtomicDeployments \Helpers \FileHelper ;
1314use JTMcC \AtomicDeployments \Interfaces \DeploymentInterface ;
1415use JTMcC \AtomicDeployments \Models \AtomicDeployment as Model ;
1516use JTMcC \AtomicDeployments \Models \Enums \DeploymentStatus ;
@@ -89,6 +90,7 @@ public function deploy(?Closure $success = null, ?Closure $failed = null): void
8990 $ this ->createDeploymentDirectory ();
9091 $ this ->copyDeploymentContents ();
9192 $ this ->copyMigrationContents ();
93+ $ this ->updateSymlinks ();
9294 $ this ->linkDeployment ();
9395 $ this ->confirmSymbolicLink ();
9496
@@ -123,7 +125,7 @@ public function updateDeploymentStatus(int $status): void
123125
124126 public function linkDeployment (): void
125127 {
126- Output::info ("Creating web root symbolic link: {$ this ->deployment ->getDeploymentLink ()} -> {$ this ->deployment ->getDeploymentPath ()}" );
128+ Output::info ("Creating symbolic link: {$ this ->deployment ->getDeploymentLink ()} -> {$ this ->deployment ->getDeploymentPath ()}" );
127129 if ($ this ->isDryRun ()) {
128130 Output::warn ('Dry run - Skipping symbolic link deployment ' );
129131
@@ -237,6 +239,27 @@ public function copyMigrationContents(): void
237239 }
238240 }
239241
242+ /**
243+ * @throws ExecuteFailedException
244+ */
245+ public function updateSymlinks ()
246+ {
247+ Output::info ('Correcting old symlinks that still reference the build directory ' );
248+
249+ if ($ this ->isDryRun ()) {
250+ Output::warn ('Dry run - skipping symlink corrections ' );
251+
252+ return ;
253+ }
254+
255+ FileHelper::recursivelyUpdateSymlinks (
256+ $ this ->getDeployment ()->getBuildPath (),
257+ $ this ->getDeployment ()->getDeploymentPath ()
258+ );
259+
260+ Output::info ('Finished correcting symlinks ' );
261+ }
262+
240263 public function rollback (): void
241264 {
242265 Output::warn ('Atomic deployment rollback has been requested ' );
@@ -249,22 +272,21 @@ public function rollback(): void
249272 $ this ->initialDeploymentPath &&
250273 $ this ->initialDeploymentPath !== $ currentPath
251274 ) {
252- Output::emergency ('Atomic deployment rollback has been requested ' );
253- Output::emergency ("Attempting to link web root to {$ this ->initialDeploymentPath }" );
275+ Output::emergency ("Attempting to link deployment at {$ this ->initialDeploymentPath }" );
254276
255277 try {
256278 //attempt to revert link to our original path
257279 Exec::ln ($ this ->deployment ->getDeploymentLink (), $ this ->initialDeploymentPath );
258280 if ($ this ->deployment ->getCurrentDeploymentPath () === $ this ->initialDeploymentPath ) {
259- Output::info ('Successfully rolled back symbolic web root ' );
281+ Output::info ('Successfully rolled back symbolic link ' );
260282
261283 return ;
262284 }
263285 } catch (ExecuteFailedException $ e ) {
264286 Output::throwable ($ e );
265287 }
266288
267- Output::emergency ('Failed to roll back symbolic web root ' );
289+ Output::emergency ('Failed to roll back symbolic link ' );
268290
269291 return ;
270292 }
0 commit comments