Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructured for psr-4 and composer. #313

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ea3a80e
Merge pull request #1 from VentureCraft/master
dakshhmehta Oct 16, 2016
9ddbba8
Added autoAccept parameter and revision limit by key
dakshhmehta Oct 16, 2016
2a00211
Fixed revision issue while creation for autoAccept
dakshhmehta Oct 17, 2016
03da0d9
Fix the code to work for first time record creation
dakshhmehta Oct 19, 2016
5b28a0c
Not null should not be part of the revision
dakshhmehta Oct 21, 2016
4b34a11
Moving code from one method to other
dakshhmehta Oct 21, 2016
3c98883
if its new record, then its probably we don't want to store it
dakshhmehta Oct 22, 2016
b5c1c4d
Rollback some error
dakshhmehta Oct 22, 2016
394d9e0
Rollback code for autoAccept
dakshhmehta Oct 22, 2016
486c897
AutoAccept added for revision creations enabled
Chaitali1223 Mar 30, 2018
5c2a07f
Merge pull request #2 from Chaitali1223/patch-2
dakshhmehta Apr 17, 2018
1123eed
src is a psr directory, so get migrations out of there.
tarekadam May 1, 2018
6e47c13
namespace is directed at src by composer.json's autoload, not by file…
tarekadam May 1, 2018
2b9d603
psr 4 compliant
tarekadam May 1, 2018
99df5e0
adds laravel service provider and composer based auto-loader
tarekadam May 1, 2018
84f6e84
psr-4 namespace should end with separator
tarekadam May 1, 2018
77654c7
update readme because migration path is not needed. psr-4/ServicePro…
tarekadam May 1, 2018
4045b66
Merge remote-tracking branch 'origin/develop'
tarekadam May 1, 2018
1747b1b
Merge branch 'master' of github.com:dakshhmehta/revisionable
tarekadam May 1, 2018
97f62fb
fixes config for psr4
tarekadam May 1, 2018
f0f6c4a
removes shit file
tarekadam May 1, 2018
b3a70d2
check empty
tarekadam May 1, 2018
26a67ac
adds missing migration
tarekadam May 1, 2018
e184425
adds history view
tarekadam May 2, 2018
2630225
adds history view
tarekadam May 2, 2018
cf893c4
adds view
tarekadam May 2, 2018
b045932
logic
tarekadam May 2, 2018
f67b50a
tweaks
tarekadam May 13, 2018
89f0590
tweaks
tarekadam Oct 22, 2018
fd62545
tweaks
tarekadam Oct 22, 2018
3cd6a6c
removes compose requirements
tarekadam Oct 15, 2019
71d7376
L6
tarekadam Oct 18, 2019
9ce9b97
refactor for L6
tarekadam Oct 18, 2019
0348733
upgrade studly case
tarekadam Oct 19, 2019
12f823e
updates revisionable
tarekadam Oct 30, 2019
6acbe4c
fix revisionable shit
tarekadam Oct 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

23 changes: 15 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@
"name": "Austin Stierler",
"email": "[email protected]",
"role": "Developer/Maintainer"
}
},
{
"name": "Tarek Adam",
"email": "[email protected]",
"role": "Contributor"
}
],
"support": {
"issues": "https://github.com/VentureCraft/revisionable/issues",
"source": "https://github.com/VentureCraft/revisionable"
},
"require": {
"php": ">=5.4.0",
"illuminate/support": "~4.0|~5.0|~5.1"
},
"autoload": {
"classmap": [
"src/migrations"
],
"psr-0": {
"Venturecraft\\Revisionable": "src/"
"psr-4": {
"Venturecraft\\Revisionable\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Venturecraft\\Revisionable\\ServiceProvider"
]
}
}
}
4 changes: 3 additions & 1 deletion src/config/revisionable.php → config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
| Revision Model
|--------------------------------------------------------------------------
*/
'model' => Venturecraft\Revisionable\Revision::class,
'route-prefix' => 'revisions',
'middleware' => ['web', 'auth'],
'revisionable-model-binding' => []
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class RevisionableAddAcceptedAtTimestamp extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('revisions', function (Blueprint $table) {
//
$table->timestamp('accepted_at')->after('new_value');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('revisions', function (Blueprint $table) {
//
});
}
}
6 changes: 6 additions & 0 deletions resources/lang/en/validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

return [

'revisionable_exists' => 'Invalid model.',
];
14 changes: 14 additions & 0 deletions resources/views/history.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@foreach($model->revisionHistory as $history)
@if($history->key == 'created_at' and !$history->old_value)
<div>{{ (!empty($history->userResponsible()))? $history->userResponsible()->first_name : 'system' }} created this resource at {{ $history->newValue() }}</div>
@else
<div>{{ $history->userResponsible()->first_name }} changed {{ $history->fieldName() }} from
{{ $history->oldValue() }}
@if(is_null($history->oldValue()))
null
@endif

to {{ $history->newValue() }}
</div>
@endif
@endforeach
13 changes: 13 additions & 0 deletions routes/main.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$config = ['namespace' => 'Venturecraft\Revisionable',
'as' => Venturecraft\Revisionable\ServiceProvider::SHORT_NAME . '::',
'prefix' => config(Venturecraft\Revisionable\ServiceProvider::SHORT_NAME . '.route-prefix'),
'middleware' => config(Venturecraft\Revisionable\ServiceProvider::SHORT_NAME . '.middleware')];

Route::group($config, function (){
Route::get('{revisionable}/history', [
'as' => 'model-history',
'uses' => 'Controller@modelHistory'
]);
});
14 changes: 14 additions & 0 deletions src/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Venturecraft\Revisionable;

use App\Http\Controllers\Controller as BaseController;
use Illuminate\Support\Str;

class Controller extends BaseController{
//
public function modelHistory($revisionable){
return view(ServiceProvider::SHORT_NAME . '::history')->withModel($revisionable);
}

}
File renamed without changes.
35 changes: 27 additions & 8 deletions src/Venturecraft/Revisionable/Revision.php → src/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Venturecraft\Revisionable;

use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;


/**
* Revision.
Expand All @@ -13,13 +15,16 @@
*
* (c) Venture Craft <http://www.venturecraft.com.au>
*/
class Revision extends Eloquent
class Revision extends Model
{
/**
* @var string
*/
public $table = 'revisions';

protected $dates = ['accepted_at'];


/**
* @var array
*/
Expand All @@ -31,6 +36,10 @@ class Revision extends Eloquent
public function __construct(array $attributes = array())
{
parent::__construct($attributes);

if(empty($this->attributes['accepted_at'])){
$this->attributes['accepted_at'] = Carbon::now();
}
}

/**
Expand Down Expand Up @@ -96,7 +105,7 @@ private function formatFieldName($key)
*/
public function oldValue()
{
return $this->getValue('old');
$this->getValue('old');
}


Expand Down Expand Up @@ -163,7 +172,7 @@ private function getValue($which = 'new')
// Check if model use RevisionableTrait
if(method_exists($item, 'identifiableName')) {
// see if there's an available mutator
$mutator = 'get' . studly_case($this->key) . 'Attribute';
$mutator = 'get' . Str::studly($this->key) . 'Attribute';
if (method_exists($item, $mutator)) {
return $this->format($item->$mutator($this->key), $item->identifiableName());
}
Expand All @@ -179,7 +188,7 @@ private function getValue($which = 'new')
// if there was an issue
// or, if it's a normal value

$mutator = 'get' . studly_case($this->key) . 'Attribute';
$mutator = 'get' . Str::studly($this->key) . 'Attribute';
if (method_exists($main_model, $mutator)) {
return $this->format($this->key, $main_model->$mutator($this->$which_value));
}
Expand Down Expand Up @@ -233,10 +242,10 @@ public function userResponsible()
) {
return $class::findUserById($this->user_id);
} else {
$user_model = app('config')->get('auth.model');
$user_model = config('auth.model');

if (empty($user_model)) {
$user_model = app('config')->get('auth.providers.users.model');
$user_model = config('auth.providers.users.model');
if (empty($user_model)) {
return false;
}
Expand Down Expand Up @@ -289,4 +298,14 @@ public function format($key, $value)
return $value;
}
}

public function scopeOnlyPending($q)
{
$q->whereNull('accepted_at');
}

public function scopeOnlyAccepted($q)
{
$q->whereNotNull('accepted_at');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Venturecraft\Revisionable;

use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Support\Arr;

/*
* This file is part of the Revisionable package by Venture Craft
Expand Down Expand Up @@ -74,21 +75,23 @@ public static function boot()
});
}
/**
* @deprecated
*
* Instance the revision model
* @return \Illuminate\Database\Eloquent\Model
*/
public static function newModel()
{
$model = \Config::get('revisionable.model', 'Venturecraft\Revisionable\Revision');
return new $model;
}
// public static function newModel()
// {
// $model = config(ServiceProvider::SHORT_NAME .'.model');
// return new $model;
// }

/**
* @return mixed
*/
public function revisionHistory()
{
return $this->morphMany(get_class(static::newModel()), 'revisionable');
return $this->morphMany(Revision::class, 'revisionable');
}

/**
Expand Down Expand Up @@ -153,7 +156,7 @@ public function postSave()
'revisionable_type' => $this->getMorphClass(),
'revisionable_id' => $this->getKey(),
'key' => $key,
'old_value' => array_get($this->originalData, $key),
'old_value' => Arr::get($this->originalData, $key),
'new_value' => $this->updatedData[$key],
'user_id' => $this->getSystemUserId(),
'created_at' => new \DateTime(),
Expand All @@ -162,7 +165,7 @@ public function postSave()
}

if (count($revisions) > 0) {
$revision = static::newModel();
$revision = new Revision;
\DB::table($revision->getTable())->insert($revisions);
}
}
Expand Down Expand Up @@ -195,7 +198,7 @@ public function postCreate()
'updated_at' => new \DateTime(),
);

$revision = static::newModel();
$revision = new Revision;
\DB::table($revision->getTable())->insert($revisions);
}
}
Expand All @@ -218,7 +221,7 @@ public function postDelete()
'created_at' => new \DateTime(),
'updated_at' => new \DateTime(),
);
$revision = static::newModel();
$revision = new Revision;
\DB::table($revision->getTable())->insert($revisions);
}
}
Expand Down
40 changes: 40 additions & 0 deletions src/RevisionableResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Venturecraft\Revisionable;

use FuquIo\LaravelDisks\ServiceProvider;
use Illuminate\Routing\Route as RouteInfo;

class RevisionableResolver{
/**
* @var \Illuminate\Config\Repository
*/
private $binding_lookup;

/**
* @var RouteInfo
*/
private $route;


/**
* Readable constructor.
*
* @param RouteInfo $route
*/
public function __construct(RouteInfo $route){
$this->route = $route;
$this->binding_lookup = config(\Venturecraft\Revisionable\ServiceProvider::SHORT_NAME . '.revisionable-model-binding');
}

public function bind($revisionable){
list($alias, $id)= explode('-', $revisionable);
if(empty($this->binding_lookup[$alias])){
abort(404, 'No binding instruction found.');
}

$class = $this->binding_lookup[$alias];
return $class::findOrFail($id);
}

}
Loading