php - 调度 Windows 作业以运行 PHP 脚本失败
问题描述
我有一个 PHP 脚本,可以将 SQL 表中的数据导出到 Drupal 内容中。我想将作业安排为 Windows 任务并按照以下步骤操作:
- 我的 PHP 文件包含以下代码:
<?php
namespace Drupal\Import\Commands;
use Drush\Commands\DrushCommands;
use Drupal\node\Entity\Node;
class ImportCommands extends DrushCommands
{
public function loadData()
{
$tx = \Drupal::database()->startTransaction();
try
{
$query_result = \Drupal::entityQuery('node')
->condition('type', 'test_mod')
->execute();
entity_delete_multiple('node', $query_result);
$database = \Drupal::database();
$result = $database->query("SELECT * FROM my_sql_table");
$records = $result->fetchAll();
foreach($records as $key => $record) {
$node = Node::create(['type' => 'test_mod']);
$node->set('title', $key);
$node->set('field_IDVal', $record->ID);
$node->set('field_name', $record->Name);
$node->status = 1;
$node->enforceIsNew();
$node->save();
}
}
catch (Exception $e) {
$tx->rollBack();
// log/report failure
}
// $tx->commit();
}
}
- 创建 .bat 文件并具有以下查询:
调用 C:\MyProj\web\Commands\php.exe -f C:\MyProj\web\Commands\ExportCommands.php
- 创建了一个 windows 任务来链接这个文件。
我所看到的只是任务成功的 0x1。任何帮助使这项工作?
预期行为:我想创建一个调用此 PHP 的 wndows 任务,并且文件中的命令将数据从 SQL 表加载到 Drupal。
现在我通过命令提示符执行文件并执行: drush MyProj:loaddata
有什么帮助吗?!
解决方案
php.exe 放错地方了。将其移至其原始位置
推荐阅读
- javascript - 反应过渡组过渡动画无法退出
- sql - 组合/折叠行与 group_by + 以列为下一行的条件
- python - pandas.io.sql 中哪个方法等价于 mysqlDB fetchone()
- node.js - Node js服务不返回任何东西
- excel - Excel 到 MS Access 连接:连接字符串中的空格问题
- powershell - VSCode 覆盖 PowerShell ExecutionPolicy
- r - 删除一系列时间戳,其中某个条件为 True
- ajax - Ajax:我需要将值从 php 脚本文件传递到 html 文件
- python - Python (Selenium) 从 HHPRED 中选择下拉列表
- javascript - Bootstrap 手风琴在 Angular 9 中不起作用