From 7c7edcd191f99d7bfd323fae4ca0955c5b3f7b98 Mon Sep 17 00:00:00 2001 From: Vincent Sposato Date: Fri, 31 Jul 2015 20:24:34 -0400 Subject: [PATCH] Created a threading command that will allow all of the asset logs to be threaded into groups --- app/commands/ThreadAssetLogsCommand.php | 214 ++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100755 app/commands/ThreadAssetLogsCommand.php diff --git a/app/commands/ThreadAssetLogsCommand.php b/app/commands/ThreadAssetLogsCommand.php new file mode 100755 index 0000000000..7dd3eb21c2 --- /dev/null +++ b/app/commands/ThreadAssetLogsCommand.php @@ -0,0 +1,214 @@ +actionlog = new Actionlog(); + $this->assetLogs = $this->actionlog->getListingOfActionLogsChronologicalOrder(); + } + + /** + * Execute the console command. + * + * @return void + */ + public function fire() + { + + if (!$this->confirm( "Do you want to update your asset logs to be properly threaded? [yes|no]" )) { + return; + } + + foreach ($this->assetLogs as $assetLog) { + + if ($this->hasAssetChanged( $assetLog )) { + $this->resetCurrentAssetInformation( $assetLog ); + } + + if ($this->hasBegunNewChain( $assetLog )) { + $this->startOfCurrentThread = false; + continue; + } + + $this->updateAssetLogWithThreadInformation( $assetLog ); + + if ($this->hasReachedEndOfChain( $assetLog ) + ) { + $this->clearCurrentAssetInformation(); + } + + } + } + + /** + * hasAssetChanged + * + * @param $assetLog + * + * @return bool + * @author Vincent Sposato + * @version v1.0 + */ + protected function hasAssetChanged( $assetLog ) + { + + return $assetLog->asset_id !== $this->currentAssetId; + } + + /** + * resetCurrentAssetInformation + * + * @param $assetLog + * + * @author Vincent Sposato + * @version v1.0 + */ + protected function resetCurrentAssetInformation( $assetLog ) + { + + $this->currentAssetId = $assetLog->asset_id; + $this->currentAssetLogId = $assetLog->id; + $this->startOfCurrentThread = true; + } + + /** + * hasReachedEndOfChain + * + * @param $assetLog + * + * @return bool + * @author Vincent Sposato + * @version v1.0 + */ + protected function hasReachedEndOfChain( $assetLog ) + { + + return in_array( $assetLog->action_type, $this->threadFinalActionTypes ) + && $this->startOfCurrentThread == false; + } + + /** + * clearCurrentAssetInformation + * @author Vincent Sposato + * @version v1.0 + */ + protected function clearCurrentAssetInformation() + { + + $this->startOfCurrentThread = true; + $this->currentAssetLogId = null; + $this->currentAssetId = null; + } + + /** + * updateAssetLogWithThreadInformation + * + * @param $assetLog + * + * @author Vincent Sposato + * @version v1.0 + */ + protected function updateAssetLogWithThreadInformation( $assetLog ) + { + + $loadedAssetLog = Actionlog::find( $assetLog->id ); + + $loadedAssetLog->thread_id = $this->currentAssetLogId; + + $loadedAssetLog->update(); + + unset( $loadedAssetLog ); + } + + /** + * hasBegunNewChain + * + * @param $assetLog + * + * @return bool + * @author Vincent Sposato + * @version v1.0 + */ + protected function hasBegunNewChain( $assetLog ) + { + + return in_array( $assetLog->action_type, $this->threadStartingActionTypes ) + && $this->startOfCurrentThread == true; + } + + }