# How to create a task.php for xibo version v4

**URL:** https://community.xibo.org.uk/t/how-to-create-a-task-php-for-xibo-version-v4/34460
**Category:** Widget Development
**Created:** [February 8, 2025, 12:31am UTC](https://community.xibo.org.uk/t/how-to-create-a-task-php-for-xibo-version-v4/34460 "2025-02-08T00:31:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Henrique\_Lucas](https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/henrique_lucas/32/16588_2.png) [@Henrique\_Lucas](https://community.xibo.org.uk/u/Henrique_Lucas)
#### Post date: [February 8, 2025, 12:31am UTC](https://community.xibo.org.uk/t/how-to-create-a-task-php-for-xibo-version-v4/34460/1 "2025-02-08T00:31:49Z")

</div>

@dan

I’m trying to run a task to update my data provider, but from what I read in the documentation it’s very incomplete:

> **[Xibo Digital Signage](https://xibosignage.com/docs/developer/extend/tasks)**
>
> The CMS will look in the /custom folder for any file ending in .task, these files will be loaded into the Task Add form for deployment on the CMS.

I would like to know if I’m going on the right path:

\<?php namespace Xibo\Custom; use Xibo\Controller\Task; use Xibo\Factory\ContainerFactory; use Xibo\Helper\Log; use Xibo\Widget\Provider\DataProviderInterface; use Xibo\Widget\Provider\WidgetProviderInterface; class tarefabiblia implements TaskInterface { use TaskTrait; public function run() { try { // Log de início da tarefa Log::info('Tarefa tarefabiblia iniciada.'); // Instância do provedor de dados $dataProvider = ContainerFactory::create()-\>get(DataProviderInterface::class); // Instância do provedor da Bíblia $widgetProvider = new provedorbiblia(); // Executa o método fetchData do provedor de dados $widgetProvider-\>fetchData($dataProvider); // Log de conclusão da tarefa Log::info('Tarefa tarefabiblia concluída com sucesso.'); } catch (\Exception $e) { // Log de erro Log::error('Erro na tarefa tarefabiblia: ' . $e-\>getMessage()); throw $e; // Re-lança a exceção para que o Xibo a capture } } }\<?php namespace Xibo\Custom; use Xibo\XTR\TaskInterface; use Xibo\XTR\TaskTrait; use Xibo\Widget\Provider\DataProviderInterface; use Xibo\Helper\Log; class CustomTask implements TaskInterface { use TaskTrait; /\*\* @var DataProviderInterface \*/ private $dataProvider; public function run() { try { // Log de início da tarefa Log::info('Tarefa CustomTask iniciada.'); // Instância do provedor da Bíblia $widgetProvider = new provedorbiblia(); // Executa o método fetchData do provedor de dados $widgetProvider-\>fetchData($this-\>dataProvider); // Log de conclusão da tarefa Log::info('Tarefa CustomTask concluída com sucesso.'); } catch (\Exception $e) { // Log de erro Log::error('Erro na tarefa CustomTask: ' . $e-\>getMessage()); throw $e; // Re-lança a exceção para que o Xibo a capture } } public function setFactories($container) { // Obtém uma instância do DataProviderInterface do container de dependências $this-\>dataProvider = $container-\>get(DataProviderInterface::class); } } ``` type or paste code here ``` Activate test mode to view the log and it tells me the following: XTR poll stopped

---

<div class="post-metadata">

### Author: ![Henrique\_Lucas](https://community.xibo.org.uk/user_avatar/community.xibo.org.uk/henrique_lucas/32/16588_2.png) [@Henrique\_Lucas](https://community.xibo.org.uk/u/Henrique_Lucas)
#### Post date: [February 8, 2025, 12:38am UTC](https://community.xibo.org.uk/t/how-to-create-a-task-php-for-xibo-version-v4/34460/4 "2025-02-08T00:38:12Z")

</div>

@dan

I’m trying to run a task to update my data provider, but from what I read in the documentation it’s very incomplete:

> **[Xibo Digital Signage](https://xibosignage.com/docs/developer/extend/tasks)**
>
> The CMS will look in the /custom folder for any file ending in .task, these files will be loaded into the Task Add form for deployment on the CMS.

I would like to know if I’m going on the right path:

```auto
<?php
namespace Xibo\Custom;

use Xibo\Controller\Task;
use Xibo\Factory\ContainerFactory;
use Xibo\Helper\Log;
use Xibo\Widget\Provider\DataProviderInterface;
use Xibo\Widget\Provider\WidgetProviderInterface;

class tarefabiblia implements TaskInterface
{
    use TaskTrait;

    public function run()
    {
        try {
            // Log de início da tarefa
            Log::info('Tarefa tarefabiblia iniciada.');

            // Instância do provedor de dados
            $dataProvider = ContainerFactory::create()->get(DataProviderInterface::class);

            // Instância do provedor da Bíblia
            $widgetProvider = new provedorbiblia();

            // Executa o método fetchData do provedor de dados
            $widgetProvider->fetchData($dataProvider);

            // Log de conclusão da tarefa
            Log::info('Tarefa tarefabiblia concluída com sucesso.');
        } catch (\Exception $e) {
            // Log de erro
            Log::error('Erro na tarefa tarefabiblia: ' . $e->getMessage());
            throw $e; // Re-lança a exceção para que o Xibo a capture
        }
    }
}<?php
namespace Xibo\Custom;

use Xibo\XTR\TaskInterface;
use Xibo\XTR\TaskTrait;
use Xibo\Widget\Provider\DataProviderInterface;
use Xibo\Helper\Log;

class CustomTask implements TaskInterface
{
    use TaskTrait;

    /** @var DataProviderInterface */
    private $dataProvider;

    public function run()
    {
        try {
            // Log de início da tarefa
            Log::info('Tarefa CustomTask iniciada.');

            // Instância do provedor da Bíblia
            $widgetProvider = new provedorbiblia();

            // Executa o método fetchData do provedor de dados
            $widgetProvider->fetchData($this->dataProvider);

            // Log de conclusão da tarefa
            Log::info('Tarefa CustomTask concluída com sucesso.');
        } catch (\Exception $e) {
            // Log de erro
            Log::error('Erro na tarefa CustomTask: ' . $e->getMessage());
            throw $e; // Re-lança a exceção para que o Xibo a capture
        }
    }

    public function setFactories($container)
    {
        // Obtém uma instância do DataProviderInterface do container de dependências
        $this->dataProvider = $container->get(DataProviderInterface::class);
    }
}

```

Activate test mode to view the log and it tells me the following: XTR poll stopped
