Giter VIP home page Giter VIP logo

revisionable's People

Contributors

alan-smith-be avatar anarchocoder avatar argia-andreas avatar awjudd avatar dandarie avatar duellsy avatar fridzema avatar grahamcampbell avatar ivelrrat avatar laravel-shift avatar miclf avatar mmawdsleyhallnet avatar msonowal avatar paulofreitas avatar ps613 avatar rajivseelam avatar rdelorier avatar reinbier avatar rhynodesigns avatar rickmills avatar rolandsaven avatar roshangautam avatar sebastienheyd avatar seedgabo avatar sniper7kills avatar stierler avatar tabacitu avatar teaqu avatar trizz avatar vpyatnitskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

revisionable's Issues

Ability to format field value

To be used in cases of boolean values, instead of having

Chris changed public from 0 to 1

Should be able to display something like

Chris changed public from no to yes

Create / Destroy

Before I log this as an issue, is this package supposed to also log create / destroy hits on the model or is it only firing for updates? The event seems to be firing on ->save() but when I create a new object, nothing is logged.

Enhancement Request: Formatted Output for Fields Name

As we have the option to format the output regarding the field values, it would be a very nice idea to have the option to format the field name output.

For example, we could define something like:
protected $revisionFormattedFieldsName = array(
'title' => 'Title',
'small_name' => 'Nickname'
'deleted_at' => 'Deleted At'
);

So when we call, $history->fieldName(), instead of get 'title' it would show 'Title' and same for others...

Please, implement?
Really useful!

Thank you very much.

Robson Martins

Get the model state by providing a revision ID

Is there any way to retrieve all the values for a model at a specified revision ? To make it simple, I would like to checkout a model on a revision (like you would checkout a repository on a commit with Git).

If it's not possible, is it planned for the v2 ?

How can we handle Sync / Detach?

Hello,

I'm using Revisionable for some time now, and I still didn't find a way to keep history from Sync or Detach calls, when you have ManyToMany, where a third table is created to hold the relations and there is no Model for it Revisionable does not detect the sync/detach changes.

Anybody has any idea on a workaround to keep track on this?

Maybe something to be implemented so this become an ER?

Thank you,

Robson

Ordering revisionHistory?

I can't find anything on this but is it possible to order the revisionHistory? I'd like to show the most recent changes first.

Sentry fix

The Sentry works as intended if you're logged in. If you're not logged in, it still tries to use Auth::check() which throws an exception if not configured.

Replace:

if (class_exists('Sentry') && \Sentry::check()) {
    $user = \Sentry::getUser();
    return $user->id;
} else if (\Auth::check()) {
    return \Auth::user()->getAuthIdentifier();
}

With:

if (class_exists('Sentry')) {
    if( \Sentry::check() ) {
        $user = \Sentry::getUser();
        return $user->id;
    } else {
        return null;
    }
} else if (\Auth::check()) {
    return \Auth::user()->getAuthIdentifier();
}

User responsible not saved if the user model is in a namespace.

The User model is hard-coded to be in the root namespace. This means that if someone namespaces their model like namespace App\Models; It will fail to save the user id. The model to use should be put into a configuration file that way people can publish it and change to suite their needs without fear of updates breaking it.

Support for Multiauth (or custom driver)

First of all You've done a really good package, thanks a lot.

Should be a good thing to support multiple auth driver or to save also the "model" associated with the auth user. In my case (an I think in many cases) Auth::user() can be User, Admin, or another model depending on current login.

needed stuffs are ..

  • in the revision table add a field "user_type", and add a setter method to fill it on booting
  • by default "user_type" should save get_class(Auth::user()) or a user defined class name.
  • to find userResponsible revision model should use something like:
    {$this->user_type}::find($this->user_id) instead of: \Config::get('auth.model')

I'm extending my models from Revisionable because I'm on laravel 4.1 and php5.3 (so no traits).
I think I'll override postSave(), postDelete() and getUserId() in my Revisionable extended model,I'm on the right road?

anyway here are a lot of private methods and attributes (like getUserId(), $updating, ...) so my extended model need to overwrite many things. Please consider to switch private to protected in next relase.

What changes (if any) need to be made to existing tables?

I've been looking to revision data in a new project and I think that this will work wonderfully but I was wondering what (if any) changes I need to make to my existing database tables to support revisioning?

I looked through the issue queue and read the read me and I didn't see anything about this but I could have just missed it so I apologize if the information on this is already available.

Support inheriting from any other Eloquent implementation

If I'm using Ardent, which is derived from Eloquent, how could I also use Revisionable, since PHP doesn't support multiple inheritances.

Would be great if we could set the class from which Revisionable 'inherits' from or is 'created from' internally, so we could use any other implementation of Eloquent with the package.

Defect with revisionHistory ?

Hello,

Please, I need some assistance here, not sure if this can be a defect.

I select my objects based on its owner, becase I have a 'multiple-user-shared' database, so it is a hasMany relationship.

Also, I'm using Ardent, so I'm including/using Revisionable as Traits.

When I run:
foreach (Auth::user()->db_owner()->coreusers as $coreuser)
{
echo "
Changes for user: ".$coreuser->id."
";
foreach ($coreuser->revisionHistory as $history)
{
echo "


  • on ".date_format(date_create($history->created_at), "d-m-Y H:i:s")."
    user ".$history->userResponsible()->morph->imodpessoa->nome_razao."
    changed field ".$history->fieldName()."
    from ".$history->oldValue()."
    to ".$history->newValue()."
  • ";
    }
    }

    It does not work, returns an empty/null revisionHistory result.

    Now, if I change foreach loop:
    from -> foreach ($coreuser->revisionHistory as $history)
    to -> foreach (CoreUser::find($coreuser->id)->revisionHistory as $history)

    However, I can not change my Application and I need it to work with the first foreach loop, would someone know to confirm if this is a issue, or if maybe I'm doing something wrong?

    I really appreciate any assistance.

    Thank you very much,

    Robson.

    Support for BatchIds

    This seems like it would be fairly easy to implement. Basically it is a batch_id for each time the revision is saved. For example - I have a model that has 5 fields, I changed all of those fields from -> to something. When its saves, it saves that as a batch. Next time that particular model get changed again in multiple fields, the batch number auto-increments. Does this feature make any sense. If not, what would be the best way for me to implement this out side of your package?

    Return a name instead of an ID

    In cases where an ID was updated (e.g., foreign key), there needs to be an easy way to say the 'user' was updated, not user_id updated

    Additionally, should be able to display the name of the referenced item, e.g., instead of saying that 1 changed to 2, it should allow you to say something like

    User changed from Chris to Matt

    Unique ID of revision?

    Is there any way to get the unique ID(s) of a revision? I'm trying to link exact changes to an existing activity feed module. I realize I could query after the update but that leaves the possibility of a race condition.

    From what I've seen its not built in currently but my guess is that there would have to be some kind of "batch id" in the case of multiple fields being updated at once and that id would be set as an attribute on the model.

    Error: Class 'app\models\Eloquent' not found

    Hi, I don't know if this is the right place for this. Kindly pardon my ignorance if so.

    My problem is...I have installed the package per the instructions in my Laravel 4. I get the following error:

    Class 'app\models\Eloquent' not found
    

    when i use based on the new, trait based implementation like this:

    <?php
    use Illuminate\Auth\UserInterface;
     use Illuminate\Auth\Reminders\RemindableInterface;
    
    namespace MyApp\Models;
    
    class User extends Eloquent implements UserInterface, RemindableInterface {
    
    use Venturecraft\Revisionable\Revisionable;
    ...
    

    Please what could be the issue here?

    'updating' is Model method

    please use different flag
    and i dont really see the point.
    just use $this->exists

    if ($this->revisionEnabled AND $this->exists) {
    ...

    Overwriting of $revisionNullString and $revisionUnknownString

    Hi,

    i have overwritten $revisionNullString and $revisionUnknownString in my models like described in the readme, but i still get the default strings.

    $revisionNullString and $revisionUnknownString belong to "Revision", app models extend "Revisionable", so overwriting can't work atm?

    Or is it my fault :)

    Boolean always get an entry in history...

    If I submit a form with a single string change on it, no matter what the boolean field value is set to (even if it's the same), I always gets an entry in the revisions table. See below. Am I just doing something wrong, or did I stumble across a bug? At first I thought it was a false vs. 0 issue, but even when I change the value to 0 when setting the boolean flag, I still see the result in the database as below. Thanks!!

    id          revisionable_type  revisionable_id  user_id     key         old_value      new_value          created_at           updated_at         
    ----------  -----------------  ---------------  ----------  ----------  -------------  -----------------  -------------------  -------------------
    1           Thing              1                2           name        String         Stringtest         2013-06-13 21:32:58  2013-06-13 21:32:58
    2           Thing              1                2           disabled    0              0                  2013-06-13 21:32:58  2013-06-13 21:32:58
    3           Thing              1                2           name        Strintgtest    String             2013-06-13 21:33:24  2013-06-13 21:33:24
    4           Thing              1                2           disabled    0              0                  2013-06-13 21:33:24  2013-06-13 21:33:24
    

    Revisionable Pivot

    maybe you can implement this like said in here:
    http://forumsarchive.laravel.io/viewtopic.php?id=10935

    [quote]
    There is no real support for it, as there is no real pivot model.
    There is though a model-like object Pivot, which you can bound a listener to, but it will fire for any pivot, not just the one you want.
    It is equal to: Event::listen('eloquent.saving: Pivot', $callback).
    What you could do is to test what's is the current table inside the event.

    Pivot::saving(function($pivot) {
    if ($pivot->getTable() == with(new ModelA)->theRelation()->getTable()) {
    $pivot->hash = Hash::make(Str::random());
    }
    });
    Where ModelA is one of the models in the relation and theRelation() is the the relation method you defined which returns the belongsToMany relation object. This way you don't have to modify the table name here if it's changed.

    Edit: Btw Pivot is not an aliased class, so you can access it through the namespace: \Illuminate\Database\Eloquent\Relations\Pivot

    Related models with multiple word attributes throws error at line 105 in Revision.php

    Let's say I have a model with the following revision rules:

    protected $keepRevisionOf = array(
            'title',
            'filename',
            'published_status_id'
    );
    

    On the model, I would also have:

    public function publishedStatus() 
        {
            return $this->hasOne('PublishedStatus', 'id', 'published_status_id');
        }
    
    But it fails, because it is looking for published_status with method_exists. It should be looking for publishedStatus (from the point of view that relationships should be defined with camel case I believe). I wrapped camel_Case around the str_replace on line 102, and it seems to work fine. 
    

    Revisionable and Mutators

    Hi,

    one of my revisionable models has some mutators like getPriceAttribute / setPriceAttribute.

    Revisionable's oldValue / newValue irgnores my getter and returns the raw price atrribute?

    Migrations break

    You should rename the migration file, as it breaks in (at least) the latest version of the Laravel framework.

    the resolve file method in Migrator.php slices the first four (date values) of the filename, causing the create_revisionstable.php migration to fail, as Laravel thinks the filname is an empty string.

    Toggle auto field naming on foreign keys

    I do like the feature where it will try to find the name/label of the given foreign key ids object, but in the case where the value does not represent a foreign key but actually references something in the data called "whatever_id" (easily could have been called whatever_number, but this is the verbage the client used), how do I/can I disable that on a given field to prevent it from automatically looking for an object? Instead showing the actual Id represented?

    e.g
    Right now I have:
    my_special_id [ code is looking for ] my_special_object

    my_special_id references the name of the data in the column, not a foreign dependent object. So it needs to actually output the exact data in the column.

    If this does not make sense, please let me know and I will clarify. Thanks for the great work. I really like using this tool.

    Trait Mode Not Working?

    I can swap out Eloquent for Revisionable and add use Venturecraft\Revisionable\Revisionable; to the top and it works, but in trait mode it doesn't record my revision history. Existing revision history recorded in extend mode is still accessible. How would I go about debugging this?

    from composer:

        "require": {
            "laravel/framework": "4.1.*",
            "doctrine/dbal": "~2.3",
            "intervention/image": "dev-master",
            "way/generators": "dev-master",
            "sebklaus/profiler": "dev-master",
            "davejamesmiller/laravel-breadcrumbs": "dev-master",
            "liuggio/excelbundle": ">=1.0.4",
            "ezyang/htmlpurifier": ">=4.6",
            "mews/purifier": "dev-master",
            "robclancy/presenter": "1.1.*",
            "symfony/yaml":"*",
            "venturecraft/revisionable": "1.5.0",
            "jenssegers/agent": "*"
        },
    

    from models/User.php

    use Illuminate\Auth\UserInterface;
    use Illuminate\Auth\Reminders\RemindableInterface;
    
    class User extends Eloquent implements UserInterface, RemindableInterface {
          [...]
        /*******************************************************************
         *  Revision History
         */
    
        use \Venturecraft\Revisionable\RevisionableTrait;
        //protected $revisionEnabled = true;
    
        // The $keepRevisionOf setting takes precendence over $dontKeepRevisionOf
        //protected $keepRevisionOf = array('phone');
    
        protected $dontKeepRevisionOf = array(
            'verify',
            'deleted_at',
            'created_at',
            'updated_at',
        );
    
        //protected $revisionFormattedFields = array(
            //'title'  => 'string:<strong>%s</strong>',
            //'public' => 'boolean:No|Yes'
        //);
    
        //protected $revisionNullString = 'nothing';
        //protected $revisionUnknownString = 'unknown';
    
        /******************************************************************/
         [...]
    }
    

    Exceptions when saving relationships in seed files

    I came across two exceptions when running a seed script. Both occur in the afterSave method.

    The first is an undefined index Revisionable.php line 112. Occurs because the originalData array does not contain the new items key.

    The second is trying to get property of non-object on line 114. Auth::user() will return null as no User will be present when running seed files via artisan.

    Struggling to get _id ref / formatting working

    Hi Chris

    I have the following migration:

    use Illuminate\Database\Migrations\Migration;
    use Illuminate\Database\Schema\Blueprint;
    
    class CreateTables extends Migration {
    
        public function up()
        {
            Schema::create('person_types', function(Blueprint $table)
            {
                $table->increments('id');
                $table->timestamps();
                $table->string('description');
            });
    
            Schema::create('people', function(Blueprint $table)
            {
                $table->increments('id');
                $table->unsignedInteger('person_type_id');
                $table->foreign('person_type_id')->references('id')->on('person_types');
                $table->string('first_name');
                $table->string('last_name');
                $table->string('id_number', 13)->unique();
                $table->date('birth_date')->nullable();
                $table->unsignedInteger('age')->nullable();
                $table->string('email')->unique();
                $table->string('mobile', 10)->unique();
                $table->text('postal_address')->nullable();
                $table->text('physical_address')->nullable();
                $table->timestamps();
                $table->softDeletes();
            });
    
        }
    
        public function down()
        {
            Schema::drop('people');
            Schema::drop('person_types');
        }
    
    }

    and the following model:

    use Watson\Validating\ValidatingTrait; // Model Validation
    use Illuminate\Database\Eloquent\SoftDeletingTrait; // Soft Deletes
    use Venturecraft\Revisionable\RevisionableTrait; // Model Auditing
    
    class Person extends Eloquent
    {
        use SoftDeletingTrait,RevisionableTrait,ValidatingTrait;
    
        protected $softDelete = true;
        protected $guarded = array();
    
        protected $rules = [
            'first_name'    => 'required',
            'last_name'     => 'required',
            'id_number'     => 'required|numeric|digits:13|id_number|unique:people',
            'mobile'        => 'required|numeric|digits:10|unique:people',
            'email'         => 'required|email|unique:people',
            'age'           => 'numeric|between:1,120',
            'birth_date'    => 'date|date_past',
            'person_type_id'=> 'required|numeric'
        ];
    
        /**
         * Person Type: One to One Relationship
         *
         * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
         */
        public function personType()
        {
            return $this->belongsTo('PersonType');
        }
    
        /**
         * Scope: Sort by Last Name Ascending
         *
         * @param $query
         * @return mixed
         */
        public function scopeLastNameAscending($query)
        {
            return $query->orderBy('last_name','ASC');
        }
    
    }

    However, I cannot get the foreign key description to display for the person_type_id, nor can I change the field format displayed. (I tried the $revisionFormattedFieldName. Also tried to do the accessor / mutator thing to no avail (copied and modified the examples from laravel's docs))

    Any idea what I could be doing wrong?

    image

    Provide pre-formatted history string

    Instead of forcing people to write out their own history, provide both the breakdown methods so they can still do this, but also a pre-formatted full string.

    Create tests

    There's currently no tests, need to make some and setup the package to auto validate via travis-ci

    Foreign key problem with namespaced Models

    Hi,

    first of all thanks for the revisionable package, saving me hours of work!

    I made most of my namspaced models "revisionable" and everything works fine. Bit if i try to get the oldValue() from a foreign key relation, Class "myrelatedmodel" can't be found. If i look in Revision.php line 72, i know why:

    $item  = $model::find($this->old_value);
    

    This will try to get myrelatedmodel, not App/Models/myrelatedmodel.

    I don't know how to solve the issue - un-namespacing all my models would work but is no option for me. Perhaps revisionable can extract the model namespace (if there is any) stored in revisionable_type like 'App\Models\Mymodel'? Ir is there a simple solution i can't think about?

    Thanks in advance!

    Trait please

    Could we also get a Revisionable trait for those of us already extending our models?

    Batch inserts

    At the moment, it seems that each attribtue change in a model results in a separate query being run

    $revision = new Revision();
    $revision->revisionable_type = get_class($this);
    $revision->revisionable_id = $this->id;
    $revision->key = $key;
    $revision->old_value = (isset($this->originalData[$key]) ? $this->originalData[$key]: null);
    $revision->new_value = $this->updatedData[$key];
    $revision->user_id = (\Auth::user() ? \Auth::user()->id : null);
    $revision->save();

    If only a few attributes were changed, then this is fine. However, if there are a large number of attributes, then its much better to do a batch insert.

    I would suggest moving all saves to using the QueryBuilder's batch insert method (http://four.laravel.com/docs/queries#inserts).

    Display revision log for all

    It would be great if you provided a method to output all of the revision logs for a specific model. I would like to output all revisions to a table. I can do that now with a custom query, but it would be nice to output in a way that is "Laravel" friendly :)

    Show complete history for all models

    It's possible to load the history for a specific model using $history = $article->revisionHistory;. I'm wondering if it's also possible to load the complete history for all the records in the revisions table, independent of the model. Are there any shortcuts for this in the package?

    Getting single revision out of revisionHistory

    Hi,

    in my app i generate a list out with revisionHistory without oldValue and newValue to keep it clean.

    I offer a revision details modal where i load the details with ajax. Is there a smarter way to load one revision by revision_id (with working relations) than this:

    $revision = $modelfull::find($id)->revisionHistory->find($revision_id)

    I think this is much overhead? If there is no better way perhaps you might consider this as a feature request :)

    Use Cartalyst Sentry user id

    We're using Sentry to handle our users. It would be great there was an option to use Sentry's user id instead of Laravel's built it one.

    I know what needs to be changed, but I'm just not sure how to make it easily configurable for others.

    Line #120 would be replaced with the following:

    'user_id' => (\Sentry::check() ? \Sentry::getUser()->id : null),

    Maybe a solution would be to have a package configuration file with an option like culpa. https://github.com/rmasters/culpa#changing-the-user-source

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.