Cakephp 3.6:在Linux上作为计划任务执行命令

时间:2019-04-04 11:23:09

标签: php linux cakephp scheduled-tasks plesk

我正在尝试在CakePHP应用程序中创建计划任务。因此,我在/src/Command/下创建了以下文件:CreateExpensesCommand.php。当我通过cmd在Windows笔记本电脑上运行此程序时,它可以正常运行。但是,当我在Plesk中上传它并尝试创建一个scheduled task来每月运行时,会出现此错误:

  

PHP致命错误:在第11行的/app_dir/src/Command/CreateExpensesCommand.php中找不到类'Cake \ Console \ Command'

这是CreateExpensesCommand.php的代码:

<?php
namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
use Cake\I18n\FrozenTime;
use Cake\Http\Session;

class CreateExpensesCommand extends Command //line 11
{

    public function initialize()
    {
        parent::initialize();
        $this->loadModel('Expenses');
        $this->loadModel('Suppliers');
    }

    public function execute(Arguments $args, ConsoleIo $io)
    {
        $recurringSuppliers = $this->Suppliers->find('all', [
                            'conditions' => ['reccuring'=> 1]
                        ]);
        $now = FrozenTime::now();
        $session = new Session();
        foreach($recurringSuppliers as $recSup){

            $expense = $this->Expenses->newEntity();
            $expense->supplier_id = $recSup->id;
            $expense->amount = $recSup->price;
            $expense->created_date = $now;
            $expense->created_by = 999; //System user
            $expense->year = $now->year;
            $expense->month = $now->month;

            if($this->Expenses->save($expense)){
                $io->out($expense->amount);
            }


        }

    }
}

这是我在Plesk计划任务中运行的PHP脚本:

app_dir/src/Command/CreateExpensesCommand.php

0 个答案:

没有答案
相关问题