-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from quetzyg/master
Fast forward the master branch and initial 4.1 features/fixes
- Loading branch information
Showing
30 changed files
with
1,175 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
tests export-ignore | ||
.gitattributes export-ignore | ||
.github export-ignore | ||
.gitignore export-ignore | ||
.travis.yml export-ignore | ||
CHANGELOG.md export-ignore | ||
phpunit.xml export-ignore | ||
README.md export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
| Q | A | ||
| ----------------- | --- | ||
| Bug? | no|yes | ||
| New Feature? | no|yes | ||
| Framework | Laravel|Lumen | ||
| Framework version | 5.x.y | ||
| Package version | 4.x.y | ||
| PHP version | 5.x.y|7.x.y | ||
|
||
#### Actual Behaviour | ||
|
||
Describe the behaviour you're experiencing. | ||
|
||
|
||
#### Expected Behaviour | ||
|
||
Describe the behaviour you're expecting. | ||
|
||
|
||
#### Steps to Reproduce | ||
|
||
List all the steps needed to reproduce the issue. Make sure to include the code you're using, | ||
any screenshots and/or other resources you find pertinent. | ||
|
||
|
||
#### Possible Solutions | ||
|
||
If you have any ideas on how to solve the issue, add them here. | ||
If not, omit this part. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
dist: trusty | ||
|
||
language: php | ||
|
||
php: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
## v4.1.0 (2017-07-??) | ||
### Added | ||
- Implemented Audit contract, enabling classes to extend other model types ([#211](https://github.com/owen-it/laravel-auditing/issues/211)) | ||
|
||
### Fixed | ||
- Allow the User primary and foreign key to be specified in the configuration ([#251](https://github.com/owen-it/laravel-auditing/issues/251)) | ||
|
||
## v4.0.7 (2017-06-04) | ||
### Added | ||
- GitHub issue template file | ||
|
||
### Fixed | ||
- Properly fixed issue ([#233](https://github.com/owen-it/laravel-auditing/issues/233)) | ||
|
||
## v4.0.6 (2017-05-21) | ||
### Fixed | ||
- Calling a member function on null ([#244](https://github.com/owen-it/laravel-auditing/issues/244)) | ||
|
||
## v4.0.5 (2017-05-03) | ||
### Fixed | ||
- Removed problematic ORDER BY from the audits() relation method in the Auditable trait | ||
|
||
## v4.0.4 (2017-05-01) | ||
### Added | ||
- Log the user agent string ([#224](https://github.com/owen-it/laravel-auditing/issues/224)) | ||
|
||
### Changed | ||
- Updated migration stub to use the DB driver ([#220](https://github.com/owen-it/laravel-auditing/issues/220)) | ||
|
||
### Fixed | ||
- Wrong class name for custom audit drivers ([#226](https://github.com/owen-it/laravel-auditing/issues/226)) | ||
- Use standards compliant SQL ([#225](https://github.com/owen-it/laravel-auditing/issues/225)) | ||
- Prevent creating an updated audit when restoring a model ([#233](https://github.com/owen-it/laravel-auditing/issues/233)) | ||
|
||
## v4.0.3 (2017-03-21) | ||
### Added | ||
- Changelog file | ||
|
||
### Fixed | ||
- Removal count in Database driver ([#215](https://github.com/owen-it/laravel-auditing/issues/215)) | ||
|
||
## v4.0.2 (2017-03-18) | ||
### Added | ||
- `OwenIt\Auditing\Contracts\UserResolver` interface | ||
- More `Auditable` tests | ||
|
||
### Fixed | ||
- Non auditable events cause a `RuntimeException` to be thrown ([#212](https://github.com/owen-it/laravel-auditing/issues/212)) | ||
- `Callable` values prevent the configuration from being cached ([#213](https://github.com/owen-it/laravel-auditing/issues/213)) | ||
|
||
## v4.0.1 (2017-03-15) | ||
### Added | ||
- Dynamic attribute getters | ||
- More `Auditable` tests | ||
|
||
### Fixed | ||
- Trait attributes can't be overridden by class implementing `Auditable` ([#205](https://github.com/owen-it/laravel-auditing/issues/205)) | ||
- Branch alias | ||
|
||
## v4.0.0 (2017-03-11) | ||
### Changed | ||
- Cleaner codebase | ||
- Better test coverage | ||
- `Auditable` attribute mutators and casts will be honoured | ||
|
||
### Fixed | ||
- Only modified attributes are stored in the `Audit` | ||
- Lumen support | ||
|
||
### Removed | ||
- Queue support | ||
- `Auditable` model custom messages/fields |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
<?php | ||
/** | ||
* This file is part of the Laravel Auditing package. | ||
* | ||
* @author Antério Vieira <[email protected]> | ||
* @author Quetzy Garcia <[email protected]> | ||
* @author Raphael França <[email protected]> | ||
* @copyright 2015-2017 | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE.md file that was distributed | ||
* with this source code. | ||
*/ | ||
|
||
namespace OwenIt\Auditing; | ||
|
||
use Illuminate\Support\Facades\Config; | ||
|
||
trait Audit | ||
{ | ||
/** | ||
* Audit data. | ||
* | ||
* @var array | ||
*/ | ||
protected $data = []; | ||
|
||
/** | ||
* The Audit attributes that belong to the metadata. | ||
* | ||
* @var array | ||
*/ | ||
protected $metadata = []; | ||
|
||
/** | ||
* The Auditable attributes that were modified. | ||
* | ||
* @var array | ||
*/ | ||
protected $modified = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getConnection() | ||
{ | ||
return static::resolveConnection(Config::get('audit.drivers.database.connection')); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTable() | ||
{ | ||
return Config::get('audit.drivers.database.table', parent::getTable()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function auditable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function user() | ||
{ | ||
return $this->belongsTo( | ||
Config::get('audit.user.model'), | ||
Config::get('audit.user.foreign_key', 'user_id'), | ||
Config::get('audit.user.primary_key', 'id') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function resolveData() | ||
{ | ||
// Metadata | ||
$this->data = [ | ||
'audit_id' => $this->id, | ||
'audit_event' => $this->event, | ||
'audit_url' => $this->url, | ||
'audit_ip_address' => $this->ip_address, | ||
'audit_user_agent' => $this->user_agent, | ||
'audit_created_at' => $this->serializeDate($this->created_at), | ||
'user_id' => $this->user_id, | ||
]; | ||
|
||
if ($this->relationLoaded('user')) { | ||
foreach ($this->user->attributesToArray() as $attribute => $value) { | ||
$this->data['user_'.$attribute] = $value; | ||
} | ||
} | ||
|
||
$this->metadata = array_keys($this->data); | ||
|
||
// Modified Auditable attributes | ||
foreach ($this->new_values as $key => $value) { | ||
$this->data['new_'.$key] = $value; | ||
} | ||
|
||
foreach ($this->old_values as $key => $value) { | ||
$this->data['old_'.$key] = $value; | ||
} | ||
|
||
$this->modified = array_diff_key(array_keys($this->data), $this->metadata); | ||
|
||
return $this->data; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDataValue($key) | ||
{ | ||
if (!array_key_exists($key, $this->data)) { | ||
return; | ||
} | ||
|
||
$value = $this->data[$key]; | ||
|
||
// Apply a mutator or a cast the Auditable model may have defined | ||
if ($this->auditable && starts_with($key, ['new_', 'old_'])) { | ||
$originalKey = substr($key, 4); | ||
|
||
if ($this->auditable->hasGetMutator($originalKey)) { | ||
return $this->auditable->mutateAttribute($originalKey, $value); | ||
} | ||
|
||
if ($this->auditable->hasCast($originalKey)) { | ||
return $this->auditable->castAttribute($originalKey, $value); | ||
} | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getMetadata($json = false, $options = 0, $depth = 512) | ||
{ | ||
if (empty($this->data)) { | ||
$this->resolveData(); | ||
} | ||
|
||
$metadata = []; | ||
|
||
foreach ($this->metadata as $key) { | ||
$metadata[$key] = $this->getDataValue($key); | ||
} | ||
|
||
return $json ? json_encode($metadata, $options, $depth) : $metadata; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getModified($json = false, $options = 0, $depth = 512) | ||
{ | ||
if (empty($this->data)) { | ||
$this->resolveData(); | ||
} | ||
|
||
$modified = []; | ||
|
||
foreach ($this->modified as $key) { | ||
$attribute = substr($key, 4); | ||
$state = substr($key, 0, 3); | ||
|
||
$modified[$attribute][$state] = $this->getDataValue($key); | ||
} | ||
|
||
return $json ? json_encode($modified, $options, $depth) : $modified; | ||
} | ||
} |
Oops, something went wrong.