Skip to content

Commit

Permalink
Updates (v 3.6.5) (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
glorand authored May 7, 2020
1 parent 94b41b5 commit 17292f6
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `glorand/laravel-model-settings` will be documented in this file

## 3.6.5 - 2020-05-07
### Fix
- code refactor
- use Cache facade instead of cache() helper function

## 3.6.4 - 2020-04-24
### Fix
- github actions
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</a>
<a href="https://packagist.org/packages/glorand/laravel-model-settings">
<img src="https://poser.pugx.org/glorand/laravel-model-settings/downloads" alt="Total Downloads">
</a>
<a href="https://github.com/glorand/laravel-model-settings">
<img src="https://github.com/glorand/laravel-model-settings/workflows/Test/badge.svg?branch=master">
</a>
<a href="https://travis-ci.com/glorand/laravel-model-settings">
<img src="https://travis-ci.com/glorand/laravel-model-settings.svg?branch=master" alt="Build Status">
Expand Down
21 changes: 8 additions & 13 deletions src/Traits/HasSettingsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Glorand\Model\Settings\Traits;

use Exception;
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
use Glorand\Model\Settings\Exceptions\ModelSettingsException;
use Glorand\Model\Settings\Managers\FieldSettingsManager;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema;

/**
Expand Down Expand Up @@ -93,21 +93,16 @@ public function setPersistSettings(bool $val = true)

/**
* @return mixed
* @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException
*/
private function hasSettingsField()
{
try {
return cache()->remember(
config('model_settings.settings_table_cache_prefix') . '::has_field',
now()->addDays(1),
function () {
return Schema::hasColumn($this->getTable(), $this->getSettingsFieldName());
}
);
} catch (Exception $e) {
throw new ModelSettingsException("Cache: " . $e->getMessage());
}
return Cache::remember(
config('model_settings.settings_table_cache_prefix') . '::has_field',
now()->addDays(1),
function () {
return Schema::hasColumn($this->getTable(), $this->getSettingsFieldName());
}
);
}

abstract public function getTable();
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/HasSettingsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Glorand\Model\Settings\Managers\TableSettingsManager;
use Glorand\Model\Settings\Models\ModelSettings;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Facades\Cache;

/**
* Trait HasSettingsTable
Expand All @@ -29,12 +30,11 @@ public function settings(): SettingsManagerContract

/**
* @return array
* @throws \Exception
*/
public function getSettingsValue(): array
{
if (config('model_settings.settings_table_use_cache')) {
return cache()->rememberForever($this->getSettingsCacheKey(), function () {
return Cache::rememberForever($this->getSettingsCacheKey(), function () {
return $this->__getSettingsValue();
});
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/UserWithField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Glorand\Model\Settings\Traits\HasSettingsField;
use Illuminate\Database\Eloquent\Model;

/**
* Class UserWithField
* @package Glorand\Model\Settings\Tests\Models
* @method static first()
*/
class UserWithField extends Model
{
use HasSettingsField;
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/UserWithRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Glorand\Model\Settings\Traits\HasSettingsRedis;
use Illuminate\Database\Eloquent\Model;

/**
* Class UserWithRedis
* @package Glorand\Model\Settings\Tests\Models
* @method static first()
*/
class UserWithRedis extends Model
{
use HasSettingsRedis;
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/UserWithTextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Glorand\Model\Settings\Traits\HasSettingsField;
use Illuminate\Database\Eloquent\Model;

/**
* Class UserWithTextField
* @package Glorand\Model\Settings\Tests\Models
* @method static first()
*/
class UserWithTextField extends Model
{
use HasSettingsField;
Expand Down
5 changes: 3 additions & 2 deletions tests/Models/UsersWithTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Glorand\Model\Settings\Tests\Models;

use Closure;
use Glorand\Model\Settings\Traits\HasSettingsTable;
use Illuminate\Database\Eloquent\Model;

/**
* @method static whereHas(string $string, Closure $param)
* Class UsersWithTable
* @package Glorand\Model\Settings\Tests\Models
* @method static first()
*/
class UsersWithTable extends Model
{
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/WrongUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use Illuminate\Database\Eloquent\Model;

/**
* Class WrongUser
* @package Glorand\Model\Settings\Tests\Models
* @method static first()
*/
class WrongUser extends Model
{
protected $table = 'wrong_users';
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/WrongUserWithField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Glorand\Model\Settings\Traits\HasSettingsField;
use Illuminate\Database\Eloquent\Model;

/**
* Class WrongUserWithField
* @package Glorand\Model\Settings\Tests\Models
* @method static first()
*/
class WrongUserWithField extends Model
{
use HasSettingsField;
Expand Down
1 change: 1 addition & 0 deletions tests/TextFieldSettingsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function testInit()
$traits = class_uses($this->model);
$this->assertArrayHasKey(HasSettingsField::class, $traits);
}

/**
* @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException
*/
Expand Down

0 comments on commit 17292f6

Please sign in to comment.