CakePHP Shell - 模型函数总是空的

时间:2015-07-24 11:51:30

标签: git shell cakephp

我有一个发送电子邮件的工作队列。

数据库:

id | function | arguments | description | status | error | error_count

e.g。

1
email
{"to":"test@domain.com","subject":"Email from us", "body":"Hey, how are you?"}
pending

0

它通过shell处理。

function main(){
    App::uses('CakeEmail', 'Network/Email');

    $this->out('Starting Queue...');

    $this->out('...getting jobs');
    $queueJobs = $this->QueueJob->getJobs();

    if(!empty($queueJobs)) {
        //process queue
    } else {
        $this->out('......no jobs to process');
    }
}

代码在开发站点上工作正常(手动上传)但是当我将它移动到生产站点(在同一服务器上只是不同的域 - 从git中提取)时,$ queueJobs总是为空,因此不处理队列。

该模型有:

function getJobs(){
    $queueJobs = $this->find('all', array(
        'conditions'=>array(
            'OR' => array(
                array('status'=>'pending'),
                array('status'=>'error')
            )
        )
    ));

    return $queueJobs;
}

我创建了一个控制器/视图,它也调用了这个模型函数,并且工作正常,只有在使用shell时才会返回空。

public function index()
{
    $queueJobs = $this->QueueJob->getJobs();
    $this->set('queueJobs', $queueJobs);
}

1 个答案:

答案 0 :(得分:1)

感谢AD7six让我指向了正确的方向。

shell正在查看错误的数据库,因为有一个dev和live数据库,它根据URL进行切换。更新构造以包含目录检查解决了问题:

public function __construct() {
    $dir = APP;
    $live_dir = '/home/admin/domains/livedomain.com/public_html';

    if (isset($_SERVER) && isset($_SERVER['SERVER_NAME']) or isset($dir)) {
        if($_SERVER['SERVER_NAME'] == 'livedomain.com' or strpos($dir, $live_dir) !== FALSE) {
            $this->default  = $this->live;
        }
    }
}