magicalella/yii2-backgroundtask

Extension for managing the background task

v1.2.0 2025-07-23 09:57 UTC

This package is auto-updated.

Last update: 2025-07-28 16:16:03 UTC


README

Installazione

Il modo migliore per installare questa estensione è tramite composer.

Lancia

composer require --prefer-dist magicalella/yii2-backgroundtask "*"

o aggiungi

"magicalella/yii2-backgroundtask": "*"

nella sezione require del tuo file "composer.json".

E avvia la migrazione dei file

yii migrate/up --migrationPath=@vendor/magicalella/yii2-backgroundtask/migrations --interactive=0

Può essere creato manualmente. Vale a dire, la tabella backgroundtask campi:

id(primaryKey, AUTO_INCREMENT); action(varchar(350)); id_user(int(11)); progress(int(2)); params(text); output(text); log(text); stato(int(1));

Installazione

Nel file: backend/config/main.php e console/config/main.php se yii advanced se Yii basic config/web.php e config/console.php scrivi

    'components' => [
    ...
        'backgroundtask' => [
            'class'   => 'magicalella\backgroundtask\Module',
            'site_realpath' => '/var/www/vhosts/miosito.com',
            'site_root' => 'https://www.miosito.com'
        ],
    ...
    ]

I file esportati verranno esportati nella cartella @uploads/backgroundtask

Attivazione

Creazione task Inserire in view Index:

Per creare il task utilizzare il Widget

magicalella\backgroundtask\widgets\BackgroundTaskWidget;

'export_csv_articoli',//action in controller console ex: export_csv_articoli 'button_class' => '', //class button default is 'btn btn-success' 'title' => '', //title button default is Yii::t('app','Add Task') 'button_text' => '', //text button default is Yii::t('app','Add Task') 'params' => [ 'qs' => Yii::$app->request->queryParams ] //array parmas for action task in controller console BackgroundTask exemple params for query search export model ]); ?>

in _protected\console\controllers

Copia il file src/console/BackgroundtaskController.php

IMPORTANTE:

Il tuo server deve permettere il comando shell_exec

MANUTENZIONE:

Aggiungi questa chiamata al tuo pannello Crontask per mantenere pulita la cartella Export che col tempo andrebbe a riempirsi Decidi tu la schedulazione in base alla quantità di file creati

php _protected/yii backgroundtask-console/clean-export

Andrà ad eliminare i file con data di creazione più vecchia di 3 mesi