Joomla 3 -从CLI文件加载模型


Joomla 3 - Loading Model from CLI file

我试图加载一个模型类,它的功能在CLI脚本中为Joomla 3.6。这是我目前所看到的:

jimport('joomla.application.component.model');
JLoader::import('JoomlaupdateModelDefault', './administrator/components/com_joomlaupdate/models');
$updater = JModelLegacy::getInstance('default');
var_dump($updater);
$updater->finaliseUpgrade();

var_dump总是返回false,最后的函数调用总是返回这个:

显示错误页面的错误:Application Instantiation Error: Call到成员函数finalisupgrade () on boolean

这个错误当然是因为这个类还没有被创建,而且它实际上是一个bool类型。

所以问题仍然存在,我如何拉模型到我的php CLI应用程序和使用它的功能?

好的,我已经得到的方式的一部分,现在它返回对象,但在运行finalise它返回一个错误的实例化。对象:

object(JoomlaupdateModelDefault)#52 (7) {
  ["__state_set":protected]=>
  NULL
  ["_db":protected]=>
  object(JDatabaseDriverMysqli)#7 (23) {
    ["name"]=>
    string(6) "mysqli"
    ["serverType"]=>
    string(5) "mysql"
    ["connection":protected]=>
    object(mysqli)#11 (19) {
      ["affected_rows"]=>
      int(1)
      ["client_info"]=>
      string(79) "mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $"
      ["client_version"]=>
      int(50012)
      ["connect_errno"]=>
      int(0)
      ["connect_error"]=>
      NULL
      ["errno"]=>
      int(0)
      ["error"]=>
      string(0) ""
      ["error_list"]=>
      array(0) {
      }
      ["field_count"]=>
      int(14)
      ["host_info"]=>
      string(25) "Localhost via UNIX socket"
      ["info"]=>
      NULL
      ["insert_id"]=>
      int(0)
      ["server_info"]=>
      string(23) "5.7.16-0ubuntu0.16.04.1"
      ["server_version"]=>
      int(50716)
      ["stat"]=>
      string(138) "Uptime: 10319  Threads: 3  Questions: 8381  Slow queries: 0  Opens: 1523  Flush tables: 1  Open tables: 184  Queries per second avg: 0.812"
      ["sqlstate"]=>
      string(5) "00000"
      ["protocol_version"]=>
      int(10)
      ["thread_id"]=>
      int(131)
      ["warning_count"]=>
      int(0)
    }
    ["nameQuote":protected]=>
    string(1) "`"
    ["nullDate":protected]=>
    string(19) "0000-00-00 00:00:00"
    ["_database":"JDatabaseDriver":private]=>
    string(3) "j34"
    ["count":protected]=>
    int(4)
    ["cursor":protected]=>
    NULL
    ["debug":protected]=>
    bool(false)
    ["limit":protected]=>
    int(0)
    ["log":protected]=>
    array(0) {
    }
    ["timings":protected]=>
    array(0) {
    }
    ["callStacks":protected]=>
    array(0) {
    }
    ["offset":protected]=>
    int(0)
    ["options":protected]=>
    array(9) {
      ["driver"]=>
      string(6) "mysqli"
      ["host"]=>
      string(9) "localhost"
      ["user"]=>
      string(4) "***"
      ["password"]=>
      string(4) "***"
      ["database"]=>
      string(3) "***"
      ["prefix"]=>
      string(6) "***_"
      ["select"]=>
      bool(true)
      ["port"]=>
      int(3306)
      ["socket"]=>
      NULL
    }
    ["sql":protected]=>
    object(JDatabaseQueryMysqli)#9 (24) {
      ["offset":protected]=>
      int(0)
      ["limit":protected]=>
      int(0)
      ["db":protected]=>
      *RECURSION*
      ["sql":protected]=>
      NULL
      ["type":protected]=>
      string(6) "select"
      ["element":protected]=>
      NULL
      ["select":protected]=>
      object(JDatabaseQueryElement)#57 (3) {
        ["name":protected]=>
        string(6) "SELECT"
        ["elements":protected]=>
        array(1) {
          [0]=>
          string(1) "*"
        }
        ["glue":protected]=>
        string(1) ","
      }
      ["delete":protected]=>
      NULL
      ["update":protected]=>
      NULL
      ["insert":protected]=>
      NULL
      ["from":protected]=>
      object(JDatabaseQueryElement)#56 (3) {
        ["name":protected]=>
        string(4) "FROM"
        ["elements":protected]=>
        array(1) {
          [0]=>
          string(12) "`#__updates`"
        }
        ["glue":protected]=>
        string(1) ","
      }
      ["join":protected]=>
      NULL
      ["set":protected]=>
      NULL
      ["where":protected]=>
      object(JDatabaseQueryElement)#55 (3) {
        ["name":protected]=>
        string(5) "WHERE"
        ["elements":protected]=>
        array(1) {
          [0]=>
          string(22) "`extension_id` = '700'"
        }
        ["glue":protected]=>
        string(5) " AND "
      }
      ["group":protected]=>
      NULL
      ["having":protected]=>
      NULL
      ["columns":protected]=>
      NULL
      ["values":protected]=>
      NULL
      ["order":protected]=>
      NULL
      ["autoIncrementField":protected]=>
      NULL
      ["call":protected]=>
      NULL
      ["exec":protected]=>
      NULL
      ["union":protected]=>
      NULL
      ["unionAll":protected]=>
      NULL
    }
    ["tablePrefix":protected]=>
    string(6) "oaetn_"
    ["utf":protected]=>
    bool(true)
    ["utf8mb4":protected]=>
    bool(true)
    ["errorNum":protected]=>
    int(0)
    ["errorMsg":protected]=>
    string(0) ""
    ["transactionDepth":protected]=>
    int(0)
    ["disconnectHandlers":protected]=>
    array(0) {
    }
  }
  ["name":protected]=>
  string(7) "default"
  ["option":protected]=>
  string(16) "com_joomlaupdate"
  ["state":protected]=>
  object(JObject)#53 (1) {
    ["_errors":protected]=>
    array(0) {
    }
  }
  ["event_clean_cache":protected]=>
  string(19) "onContentCleanCache"
  ["_errors":protected]=>
  array(0) {
  }
}

错误是:

显示错误页面的错误:Application Instantiation Error:应用程序实例化错误

是部分有效的代码:

jimport('joomla.application.component.model');
jimport('joomla.application.component.view');
JModelLegacy::addIncludePath('./administrator/components/com_joomlaupdate/models', 'JoomlaupdateModel');
$updater = JModelLegacy::getInstance('Default', 'JoomlaupdateModel');
var_dump($updater);
$updater->finaliseUpgrade();

问题是我需要欺骗Joomla,让它认为我们实际上是在后台管理中,我忘记在我的初始代码中包含:

$_SERVER['HTTP_HOST'] = 'domain.com';
JFactory::getApplication('administrator');