From 555891051e935aad73983997168d7b772ad28913 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 12 Apr 2018 00:44:30 +0800 Subject: [PATCH 01/15] add getAll method to fetch all records --- src/Query.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/Query.php b/src/Query.php index d6cfd1c..3600397 100755 --- a/src/Query.php +++ b/src/Query.php @@ -375,6 +375,39 @@ public function get($selectKeys = null) return $this->createModels($this->parseQuery->find($this->useMasterKey)); } + /** + * Get all records. + * + * + * + * @return Collection + */ + public function getAll() + { + $results = []; + + $query = $this->parseQuery + ->ascending('objectId') + ->limit(1000) + ->find($this->useMasterKey); + + $results = array_merge($results, $query); + + while (!empty($query)) { + $lastObjectId = end($query)->getObjectId(); + + $query = $this->parseQuery + ->greaterThan('objectId', $lastObjectId) + ->ascending('objectId') + ->limit(1000) + ->find($this->useMasterKey); + + $results = array_merge($results, $query); + } + + return $this->createModels($results); + } + /** * Allow to pass instances of either Query or ParseQuery. * From f63fa6c72fd87735d054d189437cf7ddb7ed071f Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 12 Apr 2018 00:47:03 +0800 Subject: [PATCH 02/15] update static method all should be call getAll method from Query class --- src/ObjectModel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ObjectModel.php b/src/ObjectModel.php index 2c3dd22..5cdb02a 100755 --- a/src/ObjectModel.php +++ b/src/ObjectModel.php @@ -103,9 +103,9 @@ public static function all($useMasterKey = null) $useMasterKey = static::$defaultUseMasterKey; } - return static::query($useMasterKey)->get(); + return static::query($useMasterKey)->getAll(); } - + /** * Set the default value for defaultUseMasterKey. This is intended to be used * as a global configuration, hence the value is set to "self" and not to "static". From 50f365cb211df24c63dc6ed014036a006666c0a0 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 19 Apr 2018 11:43:09 +0800 Subject: [PATCH 03/15] Merge branch 'master' of git://github.com/parziphal/parse --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 543b02e..51b03fa 100755 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ $post->useMasterKey(function($post) { // When creating queries, pass as parameter: $query = Post::query(true); // or use the setter method: -$query->userMasterKey(true); +$query->useMasterKey(true); // Other object methods that accept a $useMasterKey value are: $post = Post::create($data, true); @@ -247,9 +247,11 @@ There are 3 provider drivers available: * `parse-facebook` which requires users to identify using their Facebook account * `parse-any` which lets users authenticate with either username/password or Facebook +### Log in with Facebook + You can use the `Parziphal\Parse\Auth\AuthenticatesWithFacebook` trait in your auth controller along with (not instead of) Laravel's `Illuminate\Foundation\Auth\AuthenticatesUsers` trait. The `AuthenticatesWithFacebook` trait has methods to handle Facebook authentication/registration. Just bind the method (or methods) you need to a route and you're ready to go. -Below is the interface of the authentication/registration trait. Note that it can respond in two ways: with a redirection (the \*Redirect methods), or with JSON (the \*Api methods), which will respond with the `$apiResponse` array. +Below is the interface of the authentication/registration trait. Note that it can respond in two ways: with a redirection (the \*Redirect methods), or with JSON (the \*Api methods), which will respond with the `$apiResponse` array, which is there so you can customize it. ```php trait AuthenticatesWithFacebook @@ -272,15 +274,15 @@ trait AuthenticatesWithFacebook } ``` -For Facebook login, the trait expects to find the user's Facebook ID as the `id` parameter, and their access token as the `access_token` parameter. +The trait expects to find the user's Facebook ID as the `id` parameter, and their access token as the `access_token` parameter. -### Username/password registration +### Log in with username/password There are things to take into consideration regarding this: -* The validator returned by the `validator` method of the registration controller has a `unique` constraint on the `email`, which will trigger database searches, leading to an error; make sure to remove that `unique` constraint. +* The validator returned by the `validator` method of Laravel's default registration controller has a `unique` constraint on the `email` parameter, which will trigger database searches, leading to an error; make sure to remove that `unique` constraint. -* You'll also have to change the `create` method according to your needs. It could look like this (specially if you're using the auth scaffold): +* You'll also have to change the `create` method according to your needs. It could look like this: ```php protected function create(array $data) @@ -295,7 +297,7 @@ protected function create(array $data) } ``` -Remember that on Parse, the `username` field is the login name of the user, so you'll have to store their email under the `username` key if you require users to login using their email. +Notice that the email is stored as the username, this is because on Parse, the `username` field is the login name of the user, so if you require users to login using their email, you'll have to store their email under the `username` key. ## Inspiration from From 4a943ad86b53f9b30d56254b51df727475b00ae4 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 19 Apr 2018 11:56:53 +0800 Subject: [PATCH 04/15] add startsWith, endsWith, and matches operators --- src/Query.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Query.php b/src/Query.php index 3600397..d1a2136 100755 --- a/src/Query.php +++ b/src/Query.php @@ -19,6 +19,9 @@ class Query '<' => 'lessThan', '<=' => 'lessThanOrEqualTo', 'in' => 'containedIn', + '%%' => 'matches', + '.%' => 'startsWith', + '%.' => 'endsWith' ]; /** From ee117a7f4f7936ce88752763d2c93cf0c719b877 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 19 Apr 2018 11:59:46 +0800 Subject: [PATCH 05/15] make array of conditions work --- src/Query.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Query.php b/src/Query.php index d1a2136..7a67349 100755 --- a/src/Query.php +++ b/src/Query.php @@ -173,11 +173,26 @@ public function orQuery() * @return $this */ public function where($key, $operator = null, $value = null) - { + { if (is_array($key)) { $where = $key; - + foreach ($where as $key => $value) { + if (is_array($value)) { + + if (count($value) !== 3) { + continue; + } + + if (!array_key_exists($value[1], self::OPERATORS)) { + throw new Exception("Invalid operator: " . $value[1]); + } + + call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2]); + + continue; + } + if ($value instanceof ObjectModel) { $value = $value->getParseObject(); } From 0a4025bc9d79b1d13b829a9ffec31f28e0b6078c Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 19 Apr 2018 12:02:46 +0800 Subject: [PATCH 06/15] queries::where now accept array of conditions --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 51b03fa..722100a 100755 --- a/README.md +++ b/README.md @@ -155,6 +155,12 @@ $user->posts()->create($arrayWithPostData); // and not like ParseQuery's `get` which finds an object by id. $posts = Post::where('createdAt', '<=', $date)->descending('score')->get(); +$posts = Post::where([ + ['status', '=', '1'], + ['subscribed', '<>', '1'] + ]) + ->get(); + $posts = Post::where([ 'creator' => $user, 'title' => $title From 374a6f3e38937c4801194773691def4d9fcf2d38 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 19 Apr 2018 12:05:51 +0800 Subject: [PATCH 07/15] matches operator now case insensitive --- src/Query.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Query.php b/src/Query.php index 7a67349..5306605 100755 --- a/src/Query.php +++ b/src/Query.php @@ -188,7 +188,11 @@ public function where($key, $operator = null, $value = null) throw new Exception("Invalid operator: " . $value[1]); } - call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2]); + if (self::OPERATORS[$value[1]] === 'matches') { + call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2], 'i'); + } else { + call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2]); + } continue; } From a68e643b7ffd965815afdad22c393973edbc8027 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 19 Apr 2018 12:09:03 +0800 Subject: [PATCH 08/15] update readme.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 722100a..b664020 100755 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ $user->posts()->create($arrayWithPostData); // and not like ParseQuery's `get` which finds an object by id. $posts = Post::where('createdAt', '<=', $date)->descending('score')->get(); +// passing an array of conditions $posts = Post::where([ ['status', '=', '1'], ['subscribed', '<>', '1'] From 2fd7b5c99147fdd1e028fc2501322aff581cd4d6 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 3 May 2018 13:54:54 +0800 Subject: [PATCH 09/15] fix auto convert parse object issue --- src/Query.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Query.php b/src/Query.php index 5306605..2b01453 100755 --- a/src/Query.php +++ b/src/Query.php @@ -188,6 +188,10 @@ public function where($key, $operator = null, $value = null) throw new Exception("Invalid operator: " . $value[1]); } + if ($value[2] instanceof ObjectModel) { + $value[2] = $value[2]->getParseObject(); + } + if (self::OPERATORS[$value[1]] === 'matches') { call_user_func([$this, self::OPERATORS[$value[1]]], $value[0], $value[2], 'i'); } else { From 83ca71b41008ee5d3d7c27fb91dd89152426af49 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 3 May 2018 13:56:50 +0800 Subject: [PATCH 10/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b664020..e05c84b 100755 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ $posts = Post::where('createdAt', '<=', $date)->descending('score')->get(); // passing an array of conditions $posts = Post::where([ ['status', '=', '1'], - ['subscribed', '<>', '1'] + ['subscribed', '!=', '1'] ]) ->get(); From 363f82314b11363d7664aa76fcfb86bf5ee50477 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Wed, 25 Jul 2018 11:32:47 +0800 Subject: [PATCH 11/15] update parse-sdk version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5da3af6..e09b431 100755 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "require": { "php": ">=5.6", "laravel/framework": "^5.2", - "parse/php-sdk": "~1.2.0" + "parse/php-sdk": "~1.4.0" }, "autoload": { "psr-4": { From 4167361249e6423eb3baed0b5effbe758621d0ae Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Tue, 31 Jul 2018 15:35:57 +0800 Subject: [PATCH 12/15] allow useMasterKey to fetch relation --- src/ObjectModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ObjectModel.php b/src/ObjectModel.php index 5cdb02a..3b1aca5 100755 --- a/src/ObjectModel.php +++ b/src/ObjectModel.php @@ -389,7 +389,7 @@ public function addUnique($key, $value) public function fetch($force = false) { if (!$this->hasBeenFetched() || $force) { - $this->parseObject->fetch(); + $this->parseObject->fetch($this->useMasterKey); } return $this; From dfd6760aeba0a7dc1cc8a7d34788b38074d2b6e0 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Mon, 6 Aug 2018 18:42:37 +0800 Subject: [PATCH 13/15] allow incase sensitive search --- src/Query.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Query.php b/src/Query.php index 2b01453..b1a0607 100755 --- a/src/Query.php +++ b/src/Query.php @@ -218,7 +218,11 @@ public function where($key, $operator = null, $value = null) throw new Exception("Invalid operator: " . $operator); } - call_user_func([$this, self::OPERATORS[$operator]], $key, $value); + if (self::OPERATORS[$operator] === 'matches') { + call_user_func([$this, self::OPERATORS[$operator]], $key, $value, 'i'); + } else { + call_user_func([$this, self::OPERATORS[$operator]], $key, $value); + } } return $this; From 6bf14686f46909310a8ef11b18dc70707f671fe0 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Mon, 1 Apr 2019 17:48:20 +0700 Subject: [PATCH 14/15] Update BelongsToMany.php --- src/Relations/BelongsToMany.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Relations/BelongsToMany.php b/src/Relations/BelongsToMany.php index 3a5e1fd..a7b8d4e 100755 --- a/src/Relations/BelongsToMany.php +++ b/src/Relations/BelongsToMany.php @@ -82,7 +82,7 @@ protected function createItems() $class = $this->embeddedClass; foreach ($items as $item) { - $this->collection[] = new $class($item); + $this->collection[] = new $class($item->fetch()); } } } From 5e4eac271a71fe5640d72dddced3e0f198c9d795 Mon Sep 17 00:00:00 2001 From: Abdul Manaaf Date: Thu, 2 May 2019 12:59:32 +0700 Subject: [PATCH 15/15] fix relation column type --- src/Relations/BelongsToMany.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Relations/BelongsToMany.php b/src/Relations/BelongsToMany.php index a7b8d4e..5bf5f4a 100755 --- a/src/Relations/BelongsToMany.php +++ b/src/Relations/BelongsToMany.php @@ -76,8 +76,13 @@ public function save($others, $unique = true) protected function createItems() { - $items = $this->parentObject->getParseObject()->get($this->keyName); - + $query = $this->parentObject + ->getParseObject() + ->get($this->keyName) + ->getQuery(); + + $items = $query->find(); + if ($items) { $class = $this->embeddedClass;