laravel-doctrine / extensions

Extensions integration for Doctrine2 and Laravel
http://laraveldoctrine.org/
MIT License
48 stars 24 forks source link

LogEntry table not created #52

Closed seifane closed 1 year ago

seifane commented 3 years ago

Hello,

I've been trying to setup the Loggable extension on one entity and I keep getting an error that the table for log entries is not created.

An exception occurred while executing 'INSERT INTO ext_log_entries (action, logged_at, object_id, object_class, version, data, username) VALUES (?, ?, ?, ?, ?, ?, ?)' with params ["create", "2020-11-10 13:12:29", null, "App\\Entities\\Service", 1, "a:13:{s:4:\"name\";O:24:\"App\\Doctrine\\Translation\":1:{s:38:\"\u0000App\\Doctrine\\Translation\u0000translations\";a:5:{s:5:\"en_US\";s:16:\"Translation test\";s:5:\"fr_FR\";s:18:\"Test de traduction\";s:5:\"es_ES\";N;s:5:\"nl_NL\";N;i:0;a:1:{i:0;i:1;}}}s:5:\"infos\";r:2;s:15:\"longDescription\";r:2;s:16:\"shortDescription\";r:2;s:11:\"seoMetaDesc\";r:2;s:8:\"seoTitle\";r:2;s:5:\"seoH1\";r:2;s:13:\"specialOffers\";r:2;s:8:\"included\";r:2;s:11:\"notIncluded\";r:2;s:17:\"petsAllowedDetail\";r:2;s:10:\"otherMeals\";r:2;s:16:\"moderationStatus\";s:7:\"PENDING\";}", null]:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laraveltest.ext_log_entries' doesn't exist

I added the extension to the extensions list as stated in the docs :

'extensions'                 => [
        LaravelDoctrine\Extensions\Loggable\LoggableExtension::class,
        //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class,
        LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class,
        LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class,
        //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class,
        //LaravelDoctrine\Extensions\Sortable\SortableExtension::class,
        //LaravelDoctrine\Extensions\Tree\TreeExtension::class,
        //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class,
        //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class,
        //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class
    ],

Timestampable and SoftDeleteable have been working fine. I made sure to refresh and generate a migration using :

php artisan doctrine:migrations:refresh
php artisan doctrine:migrations:diff

and the table still doesn't appear in the migration.

I really don't know if this is an issue on my side but I feel like I've exhausted all options at this point. If it's relevant I recently upgraded my laravel to version 8 here's a list of my dependencies with versions.

"require": {
        "php": "^7.4",
        "doctrine/inflector": "^1.4",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^2.0",
        "gedmo/doctrine-extensions": "^2.4",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel-doctrine/acl": "^1.3",
        "laravel-doctrine/extensions": "^1.3",
        "laravel-doctrine/migrations": "^2.2",
        "laravel-doctrine/orm": "^1.7",
        "laravel/framework": "^8.0",
        "laravel/tinker": "^2.0",
      "ext-json": "*"
    },
    "require-dev": {
        "facade/ignition": "^2.0",
        "fzaninotto/faker": "^1.9.1",
        "knuckleswtf/scribe": "^1.3",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^5.0",
        "phpunit/phpunit": "^9.0"
    }, 
eigan commented 3 years ago

Not familiar with this, but do you use Annotation driver? Seems like you should add the GedmoExtensionsServiceProvider service provider in that case (http://www.laraveldoctrine.org/docs/1.0/extensions/installation)

seifane commented 3 years ago

I indeed use the annonation driver and used it previously successfully with SoftDeletable and Timestampable.

'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        LaravelDoctrine\ORM\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,
        \LaravelDoctrine\ORM\DoctrineServiceProvider::class,
        \LaravelDoctrine\ACL\AclServiceProvider::class,
        \LaravelDoctrine\Extensions\GedmoExtensionsServiceProvider::class,

Here's my providers as declared in app.php

seifane commented 3 years ago

Just an update I've managed to get the table created by creating my own LogEntry entity and making it extend AbstractLogEntry. I also added @Gedmo\Loggable(logEntryClass="VacationLogEntry") on the entity that I want to be logged.

/**
 * @ORM\Table(
 *     name="ext_log_entries",
 *     options={"row_format":"DYNAMIC"},
 *  indexes={
 *      @ORM\Index(name="log_class_lookup_idx", columns={"object_class"}),
 *      @ORM\Index(name="log_date_lookup_idx", columns={"logged_at"}),
 *      @ORM\Index(name="log_user_lookup_idx", columns={"username"}),
 *      @ORM\Index(name="log_version_lookup_idx", columns={"object_id", "object_class", "version"})
 *  }
 * )
 * @ORM\Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository")
 */
class VacationLogEntry extends AbstractLogEntry
{

}

Now the table is created and I am able to retrieve log entries using EntityManager::getRepository(VacationLogEntry::class)->getLogEntries($entity).

Now I encounter another issue where when I want to revert an entity I get a Gedmo\Exception\RuntimeException throw with the message The loggable listener could not be found.

seifane commented 3 years ago

After investigating I found that the issue may come from gedmo/doctrine-extensions. I recently upgraded to version 2.4.42 and it seems the matching on the listener is done using an instanceof expecting a LoggableListener but a ResolveUserDecorator is passed instead. I made a quick and dirty patch to unlock the situation for myself as I don't know why this was implemented that way in the first place. Let me know if you want me to create a pull request to fix this.

eigan commented 3 years ago

If you believe this is an issue with laravel-doctrine/extensions then please do open a PR and I will look into it, thanks! :+1:

tchenu commented 3 years ago

Hi,

I have the same problem, is there anything new about it?

Thank you