From 2bd278137cadda421f1c26cba356128c8668ee37 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Tue, 25 Oct 2016 17:54:53 +0100 Subject: [PATCH] Include Rememberable --- composer.json | 3 ++- composer.lock | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ config/wordpress.php | 1 + src/Models/Comment.php | 17 +++++++++++++++++ src/Models/Meta.php | 17 +++++++++++++++++ src/Models/Option.php | 17 +++++++++++++++++ src/Models/Post.php | 14 ++++++++++++++ src/Models/Term.php | 17 +++++++++++++++++ src/Models/TermTaxonomy.php | 17 +++++++++++++++++ src/Models/User.php | 18 ++++++++++++++++++ src/Models/UserMeta.php | 28 ++++++++++++++++++++++++++++ 11 files changed, 197 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 75adac0..ffed439 100644 --- a/composer.json +++ a/composer.json @@ -11,7 +11,8 @@ "require": { "illuminate/support": "5.3.*", "illuminate/database": "^5.3", - "illuminate/routing": "^5.3" + "illuminate/routing": "^5.3", + "watson/rememberable": "^2.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index b172d58..aff464b 100644 --- a/composer.lock +++ a/composer.lock @@ -1,11 +1,11 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "6c58ad1439bbf1caa3093d16a54c1ed4", - "content-hash": "422f593da2fdd296c003567b90182d68", + "hash": "e07950081a6df76470a24f8aa9be508e", + "content-hash": "68f5b8ac3064bd34ac440dec5170d899", "packages": [ { "name": "doctrine/inflector", @@ -1112,6 +1112,54 @@ "description": "Symfony Translation Component", "homepage": "https://symfony.com", "time": "2016-08-05 08:37:39" + }, + { + "name": "watson/rememberable", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/dwightwatson/rememberable.git", + "reference": "7ab6978f8dfaea8864028128faea854440c7af81" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dwightwatson/rememberable/zipball/7ab6978f8dfaea8864028128faea854440c7af81", + "reference": "7ab6978f8dfaea8864028128faea854440c7af81", + "shasum": "" + }, + "require": { + "illuminate/database": "~5.0", + "illuminate/support": "~5.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "0.9.*", + "phpunit/phpunit": "4.2.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Watson\\Rememberable\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dwight Watson", + "email": "dwight@studiousapp.com" + } + ], + "description": "Query caching for Laravel 5", + "keywords": [ + "caching", + "eloquent", + "laravel", + "remember" + ], + "time": "2016-08-23 11:22:20" } ], "packages-dev": [], diff --git a/config/wordpress.php b/config/wordpress.php index e88ee69..2b5835c 100644 --- a/config/wordpress.php +++ a/config/wordpress.php @@ -16,4 +16,5 @@ 'path_current_site' => env('PATH_CURRENT_SITE'), 'site_id_current_site' => env('SITE_ID_CURRENT_SITE'), 'blog_id_current_site' => env('BLOG_ID_CURRENT_SITE'), + 'caching' => env('DB_CACHE'), ]; diff --git a/src/Models/Comment.php b/src/Models/Comment.php index dde3450..9aa0037 100644 --- a/src/Models/Comment.php +++ a/src/Models/Comment.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Koselig\Support\Action; use Koselig\Support\Wordpress; +use Watson\Rememberable\Rememberable; /** * Table containing all the comments belonging to posts. @@ -33,10 +34,19 @@ */ class Comment extends Model { + use Rememberable; + public $timestamps = false; protected $table = DB_PREFIX . 'comments'; protected $primaryKey = 'comment_ID'; protected $dates = ['comment_date', 'comment_date_gmt']; + + /** + * Length of time to cache this model for. + * + * @var integer + */ + protected $rememberFor; /** * Create a new Eloquent model instance. @@ -52,6 +62,13 @@ // Set the current table to the site's own table if we're in a multisite if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) { $this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_comments'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } diff --git a/src/Models/Meta.php b/src/Models/Meta.php index 36dce4e..4c7644b 100644 --- a/src/Models/Meta.php +++ a/src/Models/Meta.php @@ -6,6 +6,7 @@ use Koselig\Exceptions\UnsatisfiedDependencyException; use Koselig\Support\Action; use Koselig\Support\Wordpress; +use Watson\Rememberable\Rememberable; /** * Table containing all metadata about a post. @@ -14,7 +15,16 @@ */ class Meta extends Model { + use Rememberable; + public $timestamps = false; + + /** + * Length of time to cache this model for. + * + * @var integer + */ + protected $rememberFor; /** * Cache for all meta values. @@ -39,6 +49,13 @@ // Set the current table to the site's own table if we're in a multisite if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) { $this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_postmeta'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } diff --git a/src/Models/Option.php b/src/Models/Option.php index d891dd3..510774d 100644 --- a/src/Models/Option.php +++ a/src/Models/Option.php @@ -1,8 +1,9 @@ setTable(DB_PREFIX . Wordpress::getSiteId() . '_options'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } diff --git a/src/Models/Post.php b/src/Models/Post.php index 7a2bbf1..a4039bc 100644 --- a/src/Models/Post.php +++ a/src/Models/Post.php @@ -26,6 +26,13 @@ protected $prefix = DB_PREFIX; /** + * Length of time to cache this model for. + * + * @var integer + */ + protected $rememberFor; + + /** * Create a new Eloquent model instance. * * @param array $attributes @@ -40,6 +47,13 @@ if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) { $this->prefix = DB_PREFIX . Wordpress::getSiteId() . '_'; $this->setTable($this->prefix . 'posts'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } diff --git a/src/Models/Term.php b/src/Models/Term.php index b9e9e44..534a948 100644 --- a/src/Models/Term.php +++ a/src/Models/Term.php @@ -1,9 +1,10 @@ setTable(DB_PREFIX . Wordpress::getSiteId() . '_terms'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } diff --git a/src/Models/TermTaxonomy.php b/src/Models/TermTaxonomy.php index a1542b9..81237bc 100644 --- a/src/Models/TermTaxonomy.php +++ a/src/Models/TermTaxonomy.php @@ -1,8 +1,9 @@ setTable(DB_PREFIX . Wordpress::getSiteId() . '_term_taxonomy'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } } diff --git a/src/Models/User.php b/src/Models/User.php index 2c22a78..dd4e786 100644 --- a/src/Models/User.php +++ a/src/Models/User.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Koselig\Support\Wordpress; +use Watson\Rememberable\Rememberable; /** * Table containing all the users within the CMS. @@ -14,12 +15,20 @@ */ class User extends Model implements AuthenticatableContract { - use Authenticatable; + use Authenticatable, Rememberable; + public $timestamps = false; protected $table = DB_PREFIX . 'users'; protected $primaryKey = 'ID'; protected $dates = ['user_registered']; + + /** + * Length of time to cache this model for. + * + * @var integer + */ + protected $rememberFor; /** * Create a new Eloquent model instance. @@ -35,6 +44,13 @@ // Set the current table to the site's own table if we're in a multisite if (Wordpress::multisite() && (Wordpress::getSiteId() !== 0 && Wordpress::getSiteId() !== 1)) { $this->setTable(DB_PREFIX . Wordpress::getSiteId() . '_users'); + } + + // enable caching if the user has opted for it in their configuration + if (config('wordpress.caching')) { + $this->rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); } } diff --git a/src/Models/UserMeta.php b/src/Models/UserMeta.php index 7b1c9f8..0219cf4 100644 --- a/src/Models/UserMeta.php +++ a/src/Models/UserMeta.php @@ -1,8 +1,9 @@ rememberFor = config('wordpress.caching'); + } else { + unset($this->rememberFor); + } + } /** * Get metadata for a user. -- rgit 0.1.5