OFFLINE-GmbH / oc-gdpr-plugin

October CMS plugin to make websites GDPR and ePrivacy compliant
https://octobercms.com/plugin/offline-gdpr
MIT License
36 stars 20 forks source link

Can't set closure for GDPR cleanup #100

Closed damsfx closed 8 months ago

damsfx commented 8 months ago

According to the documentation, this is what I use to delete old "New" orders that are not payed :

Event::listen('offline.gdpr::cleanup.register', function () {
    return [
        'id'     => 'acme-mall-plugin',
        'label'  => 'Acme Mall',
        'models' => [
            [
                'id'   => 'acme-mall-old-orders',
                'label'   => 'Orders',
                'comment' => 'Delete unpaid orders',
                'closure' => function ($deadline, $keepDays) {
                    Order::where('created_at', '<', $deadline)
                        ->withTrashed()
                        ->whereHas('order_state', function ($q) {
                            $q->where('flag', OrderState::FLAG_NEW);
                        })
                        ->where('payment_state', 'OFFLINE\Mall\Classes\PaymentState\PendingState')
                        ->get()
                        ->each(function (Order $order) {
                            DB::transaction(function () use ($order) {
                                $order->forceDelete();
                            });
                        });
                },
            ],
        ],
    ];
});

It throw an error : Undefined array key "class" on CleanupService.php.
In this case the $model array didn't have any class property!