From f93c2ba4794a3be86dafcf7d293bfd1947226398 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 4 Aug 2023 16:46:41 +0200 Subject: [PATCH 1/6] :arrow_up: Update to Laravel v9.52.7 --- composer.json | 36 ++++++++--------- src/Core/Blade.php | 74 ----------------------------------- src/Support/Facades/Blade.php | 16 -------- 3 files changed, 18 insertions(+), 108 deletions(-) delete mode 100644 src/Core/Blade.php delete mode 100644 src/Support/Facades/Blade.php diff --git a/composer.json b/composer.json index 0a38a97..99dc0ac 100755 --- a/composer.json +++ b/composer.json @@ -25,32 +25,32 @@ } ], "require": { - "php": "^7.4 || ^8.0", - "illuminate/config": "^7.0 || ^8.0 || ^9.0", - "illuminate/contracts": "^7.0 || ^8.0 || ^9.0", - "illuminate/support": "^7.0 || ^8.0 || ^9.0", - "illuminate/translation": "^7.0 || ^8.0 || ^9.0", - "illuminate/filesystem": "^7.0 || ^8.0 || ^9.0", - "illuminate/validation": "^7.0 || ^8.0 || ^9.0", - "illuminate/http": "^7.0 || ^8.0 || ^9.0", - "illuminate/database": "^7.0 || ^8.0 || ^9.0", - "illuminate/container": "^7.0 || ^8.0 || ^9.0", - "illuminate/view": "^7.0 || ^8.0 || ^9.0", - "illuminate/routing": "^7.0 || ^8.0 || ^9.0", - "illuminate/events": "^7.0 || ^8.0 || ^9.0", - "illuminate/pagination": "^7.0 || ^8.0 || ^9.0", + "php": "^8.0", + "illuminate/config": "^9.52", + "illuminate/contracts": "^9.52", + "illuminate/support": "^9.52", + "illuminate/translation": "^9.52", + "illuminate/filesystem": "^9.52", + "illuminate/validation": "^9.52", + "illuminate/http": "^9.52", + "illuminate/database": "^9.52", + "illuminate/container": "^9.52", + "illuminate/view": "^9.52", + "illuminate/routing": "^9.52", + "illuminate/events": "^9.52", + "illuminate/pagination": "^9.52", "as247/wp-eloquent": "dev-master", - "phpfastcache/phpfastcache": "^7.0", - "jenssegers/blade": "^1.4", + "phpfastcache/phpfastcache": "^9.0", "amphibee/wordpress-eloquent-models": "v1.2.x-dev", "amphibee/hookable": "^1.0", - "symfony/finder": " ^5.1 || ^6.0", + "symfony/error-handler": "^6.0", + "symfony/var-dumper": "^5.0|^6.0", "nesbot/carbon": "^2.45", "doctrine/inflector": " ^2.0", "thunderer/shortcode": " ^0.7.3", "laravel/helpers": " ^1.0", "guzzlehttp/guzzle": "^7.3", - "league/flysystem": "^1.1" + "league/flysystem": "^3.0" }, "require-dev": { "symfony/var-dumper": "^5.2" diff --git a/src/Core/Blade.php b/src/Core/Blade.php deleted file mode 100644 index 1ea6090..0000000 --- a/src/Core/Blade.php +++ /dev/null @@ -1,74 +0,0 @@ -filter()->unique()->toArray(); - $output = $output->filter()->unique()->first(); - - if (!is_dir($output)) { - mkdir($output, 0770, true); - } - - parent::__construct($inputs, $output); - } - - - /** - * Templates the requested file and returns the output. - * - * @return string - */ - public function template(string $view, array $data = [], array $mergeData = []): string - { - return $this->render($view, $data, $mergeData); - } - - - /** - * Templates the requested file and print the output. - * - * @return void - */ - public function print(string $view, array $data = [], array $mergeData = []): void - { - echo $this->render($view, $data, $mergeData); - } -} diff --git a/src/Support/Facades/Blade.php b/src/Support/Facades/Blade.php deleted file mode 100644 index 5166da3..0000000 --- a/src/Support/Facades/Blade.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Mon, 30 Oct 2023 09:45:08 +0100 Subject: [PATCH 2/6] :bug: Fixing the class attributions on Term/Taxonomy relationships --- src/Framework/Factories/ModelFactory.php | 32 ++++++++++-- src/Framework/Models/Taxonomy.php | 66 ++++++++++++++++++++++++ src/Framework/Models/Term.php | 32 ++++++++++++ src/Support/Facades/Cache.php | 2 +- src/Support/Facades/Config.php | 2 +- src/Support/Facades/Language.php | 2 +- src/Support/Facades/Locale.php | 2 +- src/Support/Facades/ObjectPress.php | 2 +- 8 files changed, 132 insertions(+), 8 deletions(-) diff --git a/src/Framework/Factories/ModelFactory.php b/src/Framework/Factories/ModelFactory.php index 183e2cb..9cc1ba9 100755 --- a/src/Framework/Factories/ModelFactory.php +++ b/src/Framework/Factories/ModelFactory.php @@ -3,9 +3,9 @@ namespace OP\Framework\Factories; use Illuminate\Support\Str; -use InvalidArgumentException; use OP\Framework\Models\Post; use OP\Framework\Models\Term; +use OP\Framework\Models\Taxonomy; use OP\Support\Facades\Config; use Illuminate\Support\Collection; use OP\Framework\Helpers\PostHelper; @@ -82,7 +82,33 @@ public static function resolvePostClass(string $post_type = ''): string * @version 2.1 * @since 2.1 */ - public static function resolveTaxonomyClass(string $taxonomy = ''): string + public static function resolveTaxonomyClass(): string + { + $psr = Config::getFirst('object-press.theme.psr-prefix') ?: 'App'; + + $guess = [ + sprintf('%s\Models\Taxonomy', $psr), + ]; + + foreach ($guess as $class) { + if (class_exists($class)) { + return $class; + } + } + + return Taxonomy::class; + } + + /** + * Resolve the class corresponding to the asked taxonomy. + * + * @param string $taxonomy + * + * @return string + * @version 2.1 + * @since 2.1 + */ + public static function resolveTermClass(string $taxonomy = ''): string { $psr = Config::getFirst('object-press.theme.psr-prefix') ?: 'App'; $taxonomy = $taxonomy ?: 'term'; @@ -138,7 +164,7 @@ public static function post($post) */ public static function term($term) { - $class = static::resolveTaxonomyClass($term->taxonomy); + $class = static::resolveTermClass($term->taxonomy); return $class::find($term->term_id); } diff --git a/src/Framework/Models/Taxonomy.php b/src/Framework/Models/Taxonomy.php index eb9ba39..85c0b25 100644 --- a/src/Framework/Models/Taxonomy.php +++ b/src/Framework/Models/Taxonomy.php @@ -4,6 +4,7 @@ use OP\Support\Facades\Config; use AmphiBee\Eloquent\Connection; +use OP\Framework\Factories\ModelFactory; use OP\Framework\Models\Builder\TaxonomyBuilder; use OP\Framework\Models\Scopes\CurrentLangScope; use AmphiBee\Eloquent\Model\Taxonomy as TaxonomyModel; @@ -30,6 +31,37 @@ protected static function booted() } } + /** + * @param array $attributes + * @param null $connection + * @return mixed + */ + public function newFromBuilder($attributes = [], $connection = null) + { + $model = $this->getTaxonomyInstance(); + + $model->exists = true; + + $model->setRawAttributes((array)$attributes, true); + + $model->setConnection( + $connection ?: $this->getConnectionName() + ); + + return $model; + } + + /** + * @param array $attributes + * @return object + */ + protected function getTaxonomyInstance() + { + $class = ModelFactory::resolveTaxonomyClass() ?: static::class; + + return new $class(); + } + /** * @param \Illuminate\Database\Query\Builder $query * @return TaxonomyBuilder @@ -51,4 +83,38 @@ public function posts() 'object_id' ); } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function term() + { + return $this->belongsTo(Term::class, 'term_id'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function parent() + { + return $this->belongsTo(Taxonomy::class, 'parent'); + } + + /** + * Because the column is called "parent" by WP, the relationship cannot be always loaded using this name. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function parentModel() + { + return $this->parent(); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function children() + { + return $this->hasMany(Taxonomy::class, 'parent'); + } } diff --git a/src/Framework/Models/Term.php b/src/Framework/Models/Term.php index 79f864e..12366cf 100644 --- a/src/Framework/Models/Term.php +++ b/src/Framework/Models/Term.php @@ -2,6 +2,7 @@ namespace OP\Framework\Models; +use OP\Framework\Factories\ModelFactory; use AmphiBee\Eloquent\Model\Term as TermModel; /** @@ -14,6 +15,37 @@ */ class Term extends TermModel { + /** + * @param array $attributes + * @param null $connection + * @return mixed + */ + public function newFromBuilder($attributes = [], $connection = null) + { + $model = $this->getTermInstance((array)$attributes); + + $model->exists = true; + + $model->setRawAttributes((array)$attributes, true); + + $model->setConnection( + $connection ?: $this->getConnectionName() + ); + + return $model; + } + + /** + * @param array $attributes + * @return object + */ + protected function getTermInstance(array $attributes) + { + $class = ModelFactory::resolveTermClass($attributes['taxonomy'] ?? '') ?: static::class; + + return new $class(); + } + /** * @return \Illuminate\Database\Eloquent\Relations\HasOne */ diff --git a/src/Support/Facades/Cache.php b/src/Support/Facades/Cache.php index 11333c5..66236a5 100644 --- a/src/Support/Facades/Cache.php +++ b/src/Support/Facades/Cache.php @@ -11,6 +11,6 @@ class Cache extends Facade */ protected static function getFacadeAccessor() { - return 'OP\Core\Cache'; + return \OP\Core\Cache::class; } } diff --git a/src/Support/Facades/Config.php b/src/Support/Facades/Config.php index ba5dd57..0db88ed 100644 --- a/src/Support/Facades/Config.php +++ b/src/Support/Facades/Config.php @@ -11,6 +11,6 @@ class Config extends Facade */ protected static function getFacadeAccessor() { - return 'OP\Core\Config'; + return \OP\Core\Config::class; } } diff --git a/src/Support/Facades/Language.php b/src/Support/Facades/Language.php index a768d1b..f718f55 100644 --- a/src/Support/Facades/Language.php +++ b/src/Support/Facades/Language.php @@ -11,6 +11,6 @@ class Language extends Facade */ protected static function getFacadeAccessor() { - return 'OP\Support\Language\Language'; + return \OP\Support\Language\Language::class; } } diff --git a/src/Support/Facades/Locale.php b/src/Support/Facades/Locale.php index 571b690..58e2d78 100644 --- a/src/Support/Facades/Locale.php +++ b/src/Support/Facades/Locale.php @@ -11,6 +11,6 @@ class Locale extends Facade */ protected static function getFacadeAccessor() { - return 'OP\Core\Locale'; + return \OP\Core\Locale::class; } } diff --git a/src/Support/Facades/ObjectPress.php b/src/Support/Facades/ObjectPress.php index 9aba92c..0816ad4 100644 --- a/src/Support/Facades/ObjectPress.php +++ b/src/Support/Facades/ObjectPress.php @@ -11,6 +11,6 @@ class ObjectPress extends Facade */ protected static function getFacadeAccessor() { - return 'OP\Core\ObjectPress'; + return \OP\Core\ObjectPress::class; } } From 69716c5640fd074f02d97d4774050d2168ddf7e6 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 24 Nov 2023 12:40:10 +0100 Subject: [PATCH 3/6] :sparkles: Add new orderByTermName() method on Taxonomy builder natural sort) --- .../Models/Builder/TaxonomyBuilder.php | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Framework/Models/Builder/TaxonomyBuilder.php b/src/Framework/Models/Builder/TaxonomyBuilder.php index f5bd4af..7592b4a 100644 --- a/src/Framework/Models/Builder/TaxonomyBuilder.php +++ b/src/Framework/Models/Builder/TaxonomyBuilder.php @@ -9,7 +9,7 @@ /** * The taxonomy model query builder. - * + * * @package ObjectPress * @author tgeorgel * @access public @@ -41,7 +41,7 @@ public function lang(string $lang = 'current') if ($lang == 'current') { $lang = $driver->getCurrentLang(); } - + # Get the default/primary lang slug if ($lang == 'default') { $lang = $driver->getPrimaryLang(); @@ -51,7 +51,7 @@ public function lang(string $lang = 'current') if (is_a($driver, WPMLDriver::class)) { return $this->whereExists(function ($query) use ($db, $prefix, $lang) { $table = $prefix . 'icl_translations'; - + $query->select($db->raw(1)) ->from($table) ->whereRaw("{$table}.element_id = {$prefix}term_taxonomy.term_id") @@ -59,8 +59,24 @@ public function lang(string $lang = 'current') ->whereRaw("{$table}.language_code = '{$lang}'"); }); } - + # Polylang Support // TODO } + + /** + * Natural sort by term name. + */ + public function orderByTermName() + { + $db = Connection::instance(); + $prefix = $db->getPdo()->prefix(); + + $termsTable = $prefix . 'terms'; + $termTaxonomyTable = $prefix . 'term_taxonomy'; + + return $this->join($termsTable, "$termsTable.term_id", "=", "$termTaxonomyTable.term_id") + ->orderByRaw("LENGTH($termsTable.name)") + ->orderBy("$termsTable.name"); + } } From 46b5cb6e776ed43d1c61d7d01fe6fa84ae486479 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 30 Nov 2023 10:33:12 +0100 Subject: [PATCH 4/6] :sparkles: Migrate Post relationships to ObjectPress's Post model --- src/Framework/Models/Post.php | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/Framework/Models/Post.php b/src/Framework/Models/Post.php index 22f6390..87182c2 100644 --- a/src/Framework/Models/Post.php +++ b/src/Framework/Models/Post.php @@ -62,4 +62,54 @@ public function newEloquentBuilder($query) { return new PostBuilder($query); } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function comments() + { + return $this->hasMany(Comment::class, 'comment_post_ID'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function author() + { + return $this->belongsTo(User::class, 'post_author'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function parent() + { + return $this->belongsTo(Post::class, 'post_parent'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function children() + { + return $this->hasMany(Post::class, 'post_parent'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function attachment() + { + return $this->hasMany(Post::class, 'post_parent') + ->where('post_type', 'attachment'); + } + + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function revision() + { + return $this->hasMany(Post::class, 'post_parent') + ->where('post_type', 'revision'); + } } From d12b43fecbc29ae6da7833c270a5ffefd217c05d Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Dec 2023 09:27:13 +0100 Subject: [PATCH 5/6] :pushpin: Pin amphibee/wordpress-eloquent-models to ^1.2 --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 99dc0ac..816c424 100755 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ } ], "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "files": [ "src/helpers.php" @@ -41,7 +42,7 @@ "illuminate/pagination": "^9.52", "as247/wp-eloquent": "dev-master", "phpfastcache/phpfastcache": "^9.0", - "amphibee/wordpress-eloquent-models": "v1.2.x-dev", + "amphibee/wordpress-eloquent-models": "^1.2", "amphibee/hookable": "^1.0", "symfony/error-handler": "^6.0", "symfony/var-dumper": "^5.0|^6.0", From c377c140ab3a97053275be910e573da7c8240e2e Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 19 Dec 2023 10:13:16 +0100 Subject: [PATCH 6/6] :arrow_up: Upgrade dependancies, support for illuminate 10.x --- composer.json | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 816c424..584c99b 100755 --- a/composer.json +++ b/composer.json @@ -27,35 +27,32 @@ ], "require": { "php": "^8.0", - "illuminate/config": "^9.52", - "illuminate/contracts": "^9.52", - "illuminate/support": "^9.52", - "illuminate/translation": "^9.52", - "illuminate/filesystem": "^9.52", - "illuminate/validation": "^9.52", - "illuminate/http": "^9.52", - "illuminate/database": "^9.52", - "illuminate/container": "^9.52", - "illuminate/view": "^9.52", - "illuminate/routing": "^9.52", - "illuminate/events": "^9.52", - "illuminate/pagination": "^9.52", - "as247/wp-eloquent": "dev-master", + "illuminate/config": "^9.52 || ^10.0", + "illuminate/contracts": "^9.52 || ^10.0", + "illuminate/support": "^9.52 || ^10.0", + "illuminate/translation": "^9.52 || ^10.0", + "illuminate/filesystem": "^9.52 || ^10.0", + "illuminate/validation": "^9.52 || ^10.0", + "illuminate/http": "^9.52 || ^10.0", + "illuminate/database": "^9.52 || ^10.0", + "illuminate/container": "^9.52 || ^10.0", + "illuminate/view": "^9.52 || ^10.0", + "illuminate/routing": "^9.52 || ^10.0", + "illuminate/events": "^9.52 || ^10.0", + "illuminate/pagination": "^9.52 || ^10.0", + "as247/wp-eloquent": "^2.1", "phpfastcache/phpfastcache": "^9.0", "amphibee/wordpress-eloquent-models": "^1.2", "amphibee/hookable": "^1.0", "symfony/error-handler": "^6.0", "symfony/var-dumper": "^5.0|^6.0", "nesbot/carbon": "^2.45", - "doctrine/inflector": " ^2.0", - "thunderer/shortcode": " ^0.7.3", + "doctrine/inflector": "^2.0", + "thunderer/shortcode": "^0.7.3", "laravel/helpers": " ^1.0", "guzzlehttp/guzzle": "^7.3", "league/flysystem": "^3.0" }, - "require-dev": { - "symfony/var-dumper": "^5.2" - }, "suggest": { "wp-grogu/acf-manager": "A powerful Object-Oriented library helping you create ACF field groups & gutemberg blocks while adding type-cast in returned values from database." }