找不到CakePHP Shell错误插件

时间:2014-03-04 21:00:37

标签: php cakephp cron

我在/ app / Console / Command中编写了一个名为SyncVeevaShell.php的Shell文件(基本上是一些Controller函数的复制/粘贴),它应该每隔10分钟通过一个cronjob运行,但它不起作用。当我尝试通过命令“sh cake SyncVeevaShell.php”手动运行shell时,我收到错误,说找不到插件SyncVeevaShell。我不明白为什么它会提到一个插件,因为我不想使用它。

SyncVeevaShell.php:

<?php

App::uses('AppShell', 'Console/Command');

class SyncVeevaShell extends AppShell {
public $uses = array('Asset', 'VeevaVault');

public function main()
{
    $this->autoRender = false;
    App::import('Model', 'Segment');
    $Segment = new Segment();
    App::import('Vendor', 'phpVeeva', array('file' => 'veeva' . DS . 'veeva.php'));
    $veeva = new phpVeeva();
    $veevaList = $veeva->getDocList();

    $this->remove_veeva_asset($veevaList);

    $i = 0;
    while ($i < count($veevaList))
    {
        $obj = $veevaList[$i];
        $filename = $obj->{$veeva::LIST_VALUES}[8];
        $major_ver = $obj->{$veeva::LIST_VALUES}[6];
        $minor_ver = $obj->{$veeva::LIST_VALUES}[7];

        $result = $this->Asset->VeevaVault->find('count', array(
                                        'conditions' => array(
                                            'VeevaVault.title' => $filename,
                                        )
                                    ));                         
        if ($result == 0) {

            $id = $obj->{$veeva::LIST_VALUES}[0]; //get document ID
            $info = $veeva->getInfo($id);
            $ext = $veeva->extensions[$info['format__v']];
            $size = $info['size__v'];
            $mime = $info['format__v'];
            $image = 0;
            if (strpos($mime, 'image') !== false) {
                $image = 1;
            }
            $product = $info['product__v'][0];
            $brand = $Segment->getVeevaBrand($product);
            $message_description = $info['approved_content_description__c'];
            $message_title = $info['title__v'];
            $message_expire = $info['expiration_date__vs'] . ' 12:00:00';
            $message_status = $info['status__v'];
            $url = 'https://frx.veevavault.com/api/v7.0/objects/documents/' . $id . '/file';

            $this->create_veeva_asset($id, $filename, $ext, $size, $mime, $image, $brand, $message_description, $message_title, $message_expire, $message_status, $url, $major_ver, $minor_ver);
        }
        else {

            $result = $this->Asset->VeevaVault->find('count', array(
                                        'conditions' => array(
                                            'VeevaVault.title' => $filename,
                                            'VeevaVault.major_ver' => $major_ver,
                                            'VeevaVault.minor_ver' => $minor_ver
                                        )
                                    ));
            if ($result == 0) {

                $id = $obj->{$veeva::LIST_VALUES}[0];
                $info = $veeva->getInfo($id);
                $ext = $veeva->extensions[$info['format__v']];
                $size = $info['size__v'];
                $mime = $info['format__v'];
                $image = 0;
                if (strpos($mime, 'image') !== false) {
                    $image = 1;
                }
                $product = $info['product__v'][0];
                $brand = $Segment->getVeevaBrand($product);
                $message_description = $info['approved_content_description__c'];
                $message_title = $info['title__v'];
                $message_expire = $info['expiration_date__vs'] . ' 12:00:00';
                $message_status = $info['status__v'];
                $url = 'https://frx.veevavault.com/api/v7.0/objects/documents/' . $id . '/file';

                $this->update_veeva_asset($id, $filename, $ext, $size, $mime, $image, $brand, $message_description, $message_title, $message_expire, $message_status, $url, $major_ver, $minor_ver);
            }
        }
        $i++;
    }
}

public function remove_veeva_asset($remoteVeevaList)
{
    $this->autoRender = false;
    App::import('Vendor', 'phpVeeva', array('file' => 'veeva' . DS . 'veeva.php'));
    $veeva = new phpVeeva();

    if (!empty($remoteVeevaList)) {

        $db = ConnectionManager::getDataSource('default');
        $i = 0;
        while ($i < count($remoteVeevaList))
        {
            $obj = $remoteVeevaList[$i];
            $filename = $obj->{$veeva::LIST_VALUES}[8];
            $remoteVeevaFilenames[] = $filename;
            $i++;
        }

        $localVeevaList = array();
        $query = $this->Asset->VeevaVault->find('all');
        foreach($query as $veeva) {
            $localVeevaList[] = $veeva['VeevaVault'];
        }

        if (!empty($localVeevaList)) {
            foreach($localVeevaList as $localVeeva) {
                if (in_array($localVeeva['title'], $remoteVeevaFilenames) == false) {

                    $id = $localVeeva['id'];
                    $asset_id = $localVeeva['asset_id'];

                    $sql = "DELETE FROM veeva_vaults WHERE id LIKE '" . $id . "'";
                    $db->rawQuery($sql);

                    $sql = "DELETE FROM assets WHERE id LIKE '" . $asset_id . "'";
                    $db->rawQuery($sql);
                }
            }
        }
    }
}

public function create_veeva_asset($veeva_id, $filename, $ext, $size, $mime, $image, $brand, $message_description, $message_title, $message_expire, $message_status, $url, $major_ver, $minor_ver)
{
    $this->autoRender = false;

    $uuid = String::uuid();
    $db = ConnectionManager::getDataSource('default');

    $sql = "INSERT INTO assets (id, user_id, original_name, name, ext, size, mime_type, is_image, created, modified, is_veeva, message_title, message_description, brand, status, expire_date) VALUES ('" . $uuid . "', null, '" . mysql_real_escape_string($filename) . "', '" . $uuid . "', '" . mysql_real_escape_string($ext) . "', " . mysql_real_escape_string($size) . ", '" . mysql_real_escape_string($mime) . "', " . mysql_real_escape_string($image) . ", now(), now(), 1, '" . mysql_real_escape_string($message_title) . "', '" . mysql_real_escape_string($message_description) . "', '" . mysql_real_escape_string($brand) . "', '" . mysql_real_escape_string($message_status) . "', '" . mysql_real_escape_string($message_expire) . "')";
    $db->rawQuery($sql);

    $sql = "INSERT INTO veeva_vaults (id, asset_id, veeva_id, title, description, url, created, size, major_ver, minor_ver, ext) VALUES ('" . String::uuid() . "', '" . $uuid . "', '" . $veeva_id . "', '" . mysql_real_escape_string($filename) . "', '" . mysql_real_escape_string($message_description) . "', '" . $url . "', now(), " . mysql_real_escape_string($size) . ", '" . mysql_real_escape_string($major_ver) . "', '" . mysql_real_escape_string($minor_ver) . "', '" . mysql_real_escape_string($ext) . "')";
    $db->rawQuery($sql);
}

public function update_veeva_asset($id, $filename, $ext, $size, $mime, $image, $brand, $message_description, $message_title, $message_expire, $message_status, $url, $major_ver, $minor_ver)
{
    $this->autoRender = false;

    $db = ConnectionManager::getDataSource('default');

    $sql = "UPDATE assets SET ext = '," . mysql_real_escape_string($ext) . "', size = " . mysql_real_escape_string($size) . ", mime_type = '" . mysql_real_escape_string($mime) . "', modified = now(), messages_title = '" . mysql_real_escape_string($message_title) . "', message_description = '" . mysql_real_escape_string($message_description) . "', brand = '" . mysql_real_escape_string($brand) . "', status = '" . mysql_real_escape_string($message_status) . "' WHERE original_name = '" . mysql_real_escape_string($filename) . "'";
    $db->rawQuery($sql);

    $sql = "UPDATE veeva_vaults SET veeva_id = '" . $id . "', description = '" . mysql_real_escape_string($message_description) . "', url = '" . $url . "', size = " . mysql_real_escape_string($size) . ", major_ver = " . mysql_real_escape_string($major_ver) . ", minor_ver = " . mysql_real_escape_string($minor_ver) . ", ext = " . mysql_real_escape_string($ext) . " WHERE title = '" . mysql_real_escape_string($filename) . "'";
    $db->rawQuery($sql);
}
}
?>

的cronjob:

*/10 * * * * cd /var/www/SalesGuru/content/app/Console/Command; /usr/bin/php -q SyncVeevaShell.php > /dev/null ;

错误讯息:

Error: Plugin SyncVeevaShell could not be found.
#0 /var/www/SalesGuru/content/lib/Cake/Core/App.php(364): CakePlugin::path('SyncVeevaShell')
#1 /var/www/SalesGuru/content/lib/Cake/Core/App.php(225): App::pluginPath('SyncVeevaShell')
#2 /var/www/SalesGuru/content/lib/Cake/Core/App.php(542): App::path('Console/Command', 'SyncVeevaShell')
#3 [internal function]: App::load('PhpShell')
#4 [internal function]: spl_autoload_call('PhpShell')
#5 /var/www/SalesGuru/content/lib/Cake/Console/ShellDispatcher.php(241): class_exists('PhpShell')
#6 /var/www/SalesGuru/content/lib/Cake/Console/ShellDispatcher.php(191): ShellDispatcher->_getShell('SyncVeevaShell....')
#7 /var/www/SalesGuru/content/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#8 /var/www/SalesGuru/content/app/Console/cake.php(33): ShellDispatcher::run(Array)
#9 {main}

我是CakePHP的新手,也是Shells和cronjobs的新手。

3 个答案:

答案 0 :(得分:4)

这个用例in the book有一个确切的例子:

在你的情况下:

*/10 * * * * cd /var/www/SalesGuru/content/app && Console/cake SyncVeeva > /dev/null

  • 导航到您的APP目录
  • 致电Console/cake [ShellName without suffix] [optional command name]

The official documentation应始终是您信息的第一站。然后谷歌,然后像这样的论坛。

请注意,您应该能够使用-q( - not)param使shell保持静音,而不是使用> /dev/null

答案 1 :(得分:2)

我的具体案例很简单,但我仍然设法花时间试图解决这个问题。

我在APP/Console/Command下创建了一个脚本,并尝试从命令行运行它,但它一直给我插件无法找到错误。

原来我忘记将 Shell 部分包含在文件名中。例如,如果您的脚本名为ClearCache,则实际文件名应为ClearCacheShell.php

希望这可以节省其他人几分钟的时间,因为这篇文章是第一个出现在搜索结果上的帖子。

答案 2 :(得分:0)

应为sh cake SyncVeeva

将脚本作为shell

运行时,不需要包含“Shell.php”