diff --git a/README.md b/README.md index f857895..de6ea63 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ composer require offline-agency/laravel-mongo-auto-sync ``` ### Prerequisites -Make sure you have the MongoDB PHP driver installed. You can find installation instructions at [http://php.net/manual/en/mongodb.installation.php](http://php.net/manual/en/mongodb.installation.php) +Make sure you have the MongoDB PHP driver installed. You can find installation instructions in the [manual](http://php.net/manual/en/mongodb.installation.php) ### Package version Compatibility @@ -36,85 +36,6 @@ Make sure you have the MongoDB PHP driver installed. You can find installation i | 3.x | 8.x | 3.8.x | | 3.x | 9.x | 3.9.x | -### PHP Version Compatibility -- Version 1: PHP 7.1, 7.2, 7.3 -- Version 2: PHP 7.4+ -- Version 3: PHP 7.4+ - -## Features -- Sync changes between collection with relationships after CRUD operations - - EmbedsOne & EmbedsMany - -#### Example without our package - - ``` php - //create a new Article with title "Game of Thrones" with Category "TV Series" - //assign data to $article - $article->save(); - /* - Article::class { - 'title' => 'Game of Thrones', - 'category' => Category::class { - 'name' => 'TV Series' - } - } - */ - - //Retrieve 'TV Series' category - $category = Category::where('name', 'TV Series')->first(); - /* - Category::class { - 'name' => 'Game of Thrones', - 'articles' => null - } - */ - ``` - -The sub document article has not been updated with the new article. So you will need some extra code to write in order to see the new article it in the category page. The number of sync depends on the number of the relationships and on the number of the entry in every single EmbedsMany relationships. - -Total updates = ∑ (entry in all EmbedsMany relationships) + ∑ (EmbedsOne relationships) - -As you can see the lines of extra code can rapidly increase, and you will write many redundant code. - -#### Example with our package - - ``` php - //create a new Article with title "Game of Thrones" with Category "TV Series" - $article->storeWithSync($request); - /* - Article::class { - 'title' => 'Game of Thrones', - 'category' => Category::class { - 'name' => 'TV Series' - } - } - */ - //Retrieve 'TV Series' category - $category = Category::where('name', 'TV Series')->first(); - /* - Category::class { - 'name' => 'Game of Thrones', - 'articles' => Article::class { - 'title' => 'Game of Thrones' - } - } - */ - ``` -The sub document article has been updated with the new article, with no need of extra code :tada: - -You can see the new article on the category page because the package synchronizes the information for you by reading the Model Setup. - -**These example can be applied for all write operations on the database.** -- Referenced sub documents [TO DO] -- Handle sub document as Model in order to exploit Laravel ORM support during write operation (without sync feature) [TO BE TEST] -- Handle referenced sub document as Model in order to exploit Laravel ORM support during write operation (without sync feature) [TO DO] -- Advance cast field support - -## Use cases -- Blog: see demo [here](https://github.com/offline-agency/laravel-mongodb-blog) -- Ecommerce -- API System for mobile application o for generated static site -- Any projects that require fast read operations and (slow) write operations that can be run on background ## Documentation You can find the documentation [here](https://docs.offlineagency.com/laravel-mongo-auto-sync/) @@ -131,19 +52,6 @@ Now run the tests with: composer test ``` -## Roadmap :rocket: -- Refactor target synchronization to Observer pattern, so all this operation can be run on background using [Laravel Queue System](https://laravel.com/docs/5.8/queues). This will also speed up all the operations in the collection that is primary involved in write operations. -- Command Analyse Database: This command will analyse the database in order to find some relationship error. -Ex: An article with a category associated that is not present on the Category's sub document. -- Refactor **save()** method in order to handle CRUD operation on relationship also without sync. -- Support for [referenced relationships](https://docs.mongodb.com/manual/tutorial/model-referenced-one-to-many-relationships-between-documents/). -- Better support for all field types. -- DestroyWithSync() without delete sub documents on other collections. -- Add more tests. -- Nested relationships. -- Benchmark MongoDB vs Mysql (write and read operation). -- Fix typo errors. - ## Contributing Please see [CONTRIBUTING](CONTRIBUTING.md) for details. diff --git a/src/Console/DropCollection.php b/src/Console/DropCollection.php index cedc767..e2860cb 100644 --- a/src/Console/DropCollection.php +++ b/src/Console/DropCollection.php @@ -67,7 +67,7 @@ public function handle() } /** - * @param $collection_name + * @param $collection_name * @return string * * @throws Exception @@ -80,8 +80,8 @@ public function getModelPathByName($collection_name) } /** - * @param $path - * @param $collection_name + * @param $path + * @param $collection_name * @return string * * @throws Exception diff --git a/src/Console/GenerateModelDocumentation.php b/src/Console/GenerateModelDocumentation.php index 934294d..2afb648 100644 --- a/src/Console/GenerateModelDocumentation.php +++ b/src/Console/GenerateModelDocumentation.php @@ -76,7 +76,7 @@ public function handle() } /** - * @param $collection_name + * @param $collection_name * @return string * * @throws Exception @@ -89,8 +89,8 @@ public function getModelPathByName($collection_name) } /** - * @param $path - * @param $collection_name + * @param $path + * @param $collection_name * @return string * * @throws Exception diff --git a/src/Extensions/MongoCollection.php b/src/Extensions/MongoCollection.php index df22978..8d58255 100644 --- a/src/Extensions/MongoCollection.php +++ b/src/Extensions/MongoCollection.php @@ -99,7 +99,7 @@ public function getPublic() //Check if the collection has an item with ref_id equal to id of the obj pass in to the parameter, useful to mark a category already selected in edit /** - * @param $obj + * @param $obj * @return bool */ public function hasItem($obj) @@ -130,7 +130,7 @@ public function hasItem($obj) //Move the item with ref_id equal to the parameter, useful for edit primary category /** - * @param $id + * @param $id * @return $this */ public function moveFirst($id) @@ -176,7 +176,7 @@ public function findByAID(string $aid) } /** - * @param $id + * @param $id * @return bool */ public function hasPermission($id) @@ -199,7 +199,7 @@ public function hasPermission($id) } /** - * @param $name + * @param $name * @return bool */ public function hasRole($name) @@ -222,7 +222,7 @@ public function hasRole($name) } /** - * @param $name + * @param $name * @return bool */ public function checkPermission($name) diff --git a/src/MongoAutoSyncServiceProvider.php b/src/MongoAutoSyncServiceProvider.php index 00fd29e..579a07b 100644 --- a/src/MongoAutoSyncServiceProvider.php +++ b/src/MongoAutoSyncServiceProvider.php @@ -44,7 +44,7 @@ public function register() } /** - * @param $path + * @param $path * @return string */ private function packagePath($path) diff --git a/src/Traits/Helper.php b/src/Traits/Helper.php index 611cfa0..6ef0179 100644 --- a/src/Traits/Helper.php +++ b/src/Traits/Helper.php @@ -8,7 +8,7 @@ trait Helper { /** - * @param $options + * @param $options * @return bool|mixed * * @throws Exception @@ -21,7 +21,7 @@ public function isArray($options) } /** - * @param $options + * @param $options * @return bool|mixed * * @throws Exception @@ -34,7 +34,7 @@ public function isCarbonDate($options) } /** - * @param $options + * @param $options * * @throws Exception */ @@ -46,7 +46,7 @@ private function validateOptions($options) } /** - * @param $value + * @param $value * @param string $expected * * @throws Exception diff --git a/src/Traits/MainMongoTrait.php b/src/Traits/MainMongoTrait.php index 7fc8a18..c8d1682 100644 --- a/src/Traits/MainMongoTrait.php +++ b/src/Traits/MainMongoTrait.php @@ -110,7 +110,7 @@ private function getOptionValue(array $options, string $key) } /** - * @param $obj + * @param $obj * @param string $EOkey * @param string $method * @param string $model @@ -126,7 +126,7 @@ public function checkPropertyExistence($obj, string $EOkey, $method = '', $model } /** - * @param $arr + * @param $arr * @param string $key * * @throws Exception @@ -174,9 +174,9 @@ public function getHasPartialRequest() public function setHasPartialRequest(): void { $this->has_partial_request = $this->getOptionValue( - $this->getOptions(), - 'request_type' - ) == 'partial'; + $this->getOptions(), + 'request_type' + ) == 'partial'; } /** diff --git a/src/Traits/ModelAdditionalMethod.php b/src/Traits/ModelAdditionalMethod.php index 980a5cc..2cd7a56 100644 --- a/src/Traits/ModelAdditionalMethod.php +++ b/src/Traits/ModelAdditionalMethod.php @@ -122,7 +122,7 @@ public function getFreshMiniModel(string $mini_model_path) /** * @param string $key - * @param $item + * @param $item * @param string $mini_model_path * @return array|mixed|UTCDateTime|null * diff --git a/src/Traits/RelationshipMongoTrait.php b/src/Traits/RelationshipMongoTrait.php index 5f5c6be..d25bfbd 100644 --- a/src/Traits/RelationshipMongoTrait.php +++ b/src/Traits/RelationshipMongoTrait.php @@ -73,7 +73,6 @@ public function processAllRelationships(Request $request, string $event, string if ($is_EO || $is_EM) {//EmbedsOne Create - EmbedsMany Create if ($event == 'update' && $is_embeds_has_to_be_updated) { - //Delete EmbedsMany or EmbedsOne on Target - TODO: check if it is necessary to run deleteTargetObj method if ($hasTarget) { $this->deleteTargetObj($method, $modelTarget, $methodOnTarget, $is_EO, $is_EM, $is_EO_target, $is_EM_target); @@ -124,7 +123,7 @@ public function processAllRelationships(Request $request, string $event, string } /** - * @param $mini_model + * @param $mini_model * @param string $method_on_target * @param bool $is_EO_target * @param bool $is_EM_target @@ -188,22 +187,22 @@ public function updateRelationWithSync($mini_model, string $method_on_target, $i /** * @param Request $request - * @param $obj - * @param $type - * @param $model - * @param $method - * @param $modelTarget - * @param $methodOnTarget - * @param $modelOnTarget - * @param $event - * @param $hasTarget + * @param $obj + * @param $type + * @param $model + * @param $method + * @param $modelTarget + * @param $methodOnTarget + * @param $modelOnTarget + * @param $event + * @param $hasTarget * @param bool $is_EO * @param bool $is_EM * @param bool $is_EO_target * @param bool $is_EM_target - * @param $i + * @param $i * @param bool $is_embeds_has_to_be_updated - * @param $options + * @param $options * * @throws Exception */ @@ -271,15 +270,15 @@ public function handleSubTarget(?string $target_id, string $modelTarget, string /** * @param Request $request - * @param $obj - * @param $type - * @param $model - * @param $method - * @param $event - * @param $is_EO - * @param $is_EM - * @param $i - * @param $options + * @param $obj + * @param $type + * @param $model + * @param $method + * @param $event + * @param $is_EO + * @param $is_EM + * @param $i + * @param $options * * @throws Exception */ @@ -329,10 +328,10 @@ private function processEmbedOnCurrentCollection(Request $request, $obj, $type, } /** - * @param $modelTarget - * @param $obj - * @param $methodOnTarget - * @param $modelOnTarget + * @param $modelTarget + * @param $obj + * @param $methodOnTarget + * @param $modelOnTarget * @param bool $is_EO_target * @param bool $is_EM_target * diff --git a/src/syncUtils.php b/src/syncUtils.php index da8f10f..b123014 100644 --- a/src/syncUtils.php +++ b/src/syncUtils.php @@ -5,7 +5,6 @@ use Jenssegers\Mongodb\Eloquent\Model; if (! function_exists('getTranslatedContent')) { - /** * @param array $mlCollection * @return string @@ -24,7 +23,6 @@ function getTranslatedContent($mlCollection) } if (! function_exists('cl')) { - /** * @return string current Lang */ @@ -166,9 +164,8 @@ function getAID(Model $model) } if (! function_exists('getArrayWithEmptyObj')) { - /** - * @param $model + * @param $model * @return array */ function getArrayWithEmptyObj($model, $is_EO, $is_EM) @@ -192,12 +189,11 @@ function getArrayWithEmptyObj($model, $is_EO, $is_EM) } if (! function_exists('getCounterForRelationships')) { - /** - * @param $method - * @param $is_EO - * @param $is_EM - * @param $i + * @param $method + * @param $is_EO + * @param $is_EM + * @param $i * @return string */ function getCounterForRelationships($method, $is_EO, $is_EM, $i) diff --git a/tests/SyncTestCase.php b/tests/SyncTestCase.php index 2ed3af9..ea2ca60 100644 --- a/tests/SyncTestCase.php +++ b/tests/SyncTestCase.php @@ -416,7 +416,7 @@ public function getMiniRoles($role_id = '') } /** - * @param $category_id + * @param $category_id * @return object * * @throws Exception @@ -441,7 +441,7 @@ public function prepareSingleMiniCategory($category_id) } /** - * @param $permission_id + * @param $permission_id * @return object * * @throws Exception @@ -465,7 +465,7 @@ public function prepareSingleMiniPermission($permission_id) } /** - * @param $role_id + * @param $role_id * @return object * * @throws Exception @@ -560,7 +560,7 @@ public function getMiniNavigation(string $navigation_id = '') } /** - * @param $navigation + * @param $navigation * @return bool */ public function isNavigationCreated($navigation) @@ -569,7 +569,7 @@ public function isNavigationCreated($navigation) } /** - * @param $item + * @param $item * @return bool */ public function isItemCreated($item) @@ -590,7 +590,7 @@ public function cleanUp(Navigation $navigation, SubItem $sub_item) } /** - * @param $item + * @param $item * @return bool */ public function isItemUpdatedCorrectly($item) @@ -599,7 +599,7 @@ public function isItemUpdatedCorrectly($item) } /** - * @param $navigation + * @param $navigation * @return bool */ public function isNavigationUpdatedCorrectly($navigation) @@ -608,7 +608,7 @@ public function isNavigationUpdatedCorrectly($navigation) } /** - * @param $navigation + * @param $navigation * @return bool */ public function isUpdated($navigation) @@ -617,8 +617,8 @@ public function isUpdated($navigation) } /** - * @param $navigation_id - * @param $item_id + * @param $navigation_id + * @param $item_id * @return bool */ public function isItemAddedInNavigationCollection($navigation_id, $item_id) @@ -635,7 +635,7 @@ public function isItemAddedInNavigationCollection($navigation_id, $item_id) } /** - * @param $navigation_code + * @param $navigation_code * @return false|string */ public function getNavigation($navigation_code) diff --git a/tests/SyncUtilsTest.php b/tests/SyncUtilsTest.php index 1fb7b96..6150568 100644 --- a/tests/SyncUtilsTest.php +++ b/tests/SyncUtilsTest.php @@ -41,7 +41,6 @@ public function test_cl() public function test_ml() { - // Input expected to be [ "en" => "1" ] from $out $destination = null;