Technical discuss

Joomla 5.x 工作流调试脚本

More
12 Jan 2026 03:33 #1009 by service
New Topic
命令行运行生成一个文件
Code:
# 创建调试脚本 cat > "debug_Joomla5x_workflow.php" << 'EOF' <?php /**  * Joomla 5.x 工作流调试脚本  * 直接运行此脚本检查工作流配置  */ define('_JEXEC', 1); define('JPATH_BASE', dirname(__DIR__)); // Joomla根目录 require_once JPATH_BASE . '/includes/defines.php'; require_once JPATH_BASE . '/includes/framework.php'; // 初始化Joomla $app = JFactory::getApplication('site'); // 检查Joomla版本 echo "<h1>Joomla 版本: " . JVERSION . "</h1>\n"; // 检查工作流表 $db = JFactory::getDbo(); $tables = [     '#__workflows',     '#__workflow_stages',      '#__workflow_transitions',     '#__assets',     '#__content' ]; echo "<h2>数据库表检查</h2>\n"; echo "<table border='1' cellpadding='5'>\n"; echo "<tr><th>表名</th><th>状态</th><th>记录数</th></tr>\n"; foreach ($tables as $table) {     try {         // 检查表是否存在         $db->setQuery("SHOW TABLES LIKE '" . str_replace('#__', $db->getPrefix(), $table) . "'");         $exists = $db->loadResult();                  if ($exists) {             // 获取记录数             $db->setQuery("SELECT COUNT(*) FROM " . $table);             $count = $db->loadResult();             echo "<tr><td>{$table}</td><td style='color:green'>✓ 存在</td><td>{$count}</td></tr>\n";                          // 如果是workflows表,显示内容             if ($table === '#__workflows') {                 $db->setQuery("SELECT * FROM " . $table . " LIMIT 5");                 $workflows = $db->loadObjectList();                 if ($workflows) {                     echo "<tr><td colspan='3'>";                     foreach ($workflows as $wf) {                         echo "ID: {$wf->id}, 标题: {$wf->title}, 状态: {$wf->published}<br>\n";                     }                     echo "</td></tr>\n";                 }             }                          // 如果是workflow_stages表,显示内容             if ($table === '#__workflow_stages') {                 $db->setQuery("SELECT * FROM " . $table . " WHERE workflow_id = 1");                 $stages = $db->loadObjectList();                 if ($stages) {                     echo "<tr><td colspan='3'>";                     foreach ($stages as $stage) {                         echo "阶段ID: {$stage->id}, 标题: {$stage->title}, 工作流: {$stage->workflow_id}<br>\n";                     }                     echo "</td></tr>\n";                 }             }         } else {             echo "<tr><td>{$table}</td><td style='color:red'>✗ 不存在</td><td>-</td></tr>\n";         }     } catch (Exception $e) {         echo "<tr><td>{$table}</td><td style='color:orange'>⚠ 错误: " . $e->getMessage() . "</td><td>-</td></tr>\n";     } } echo "</table>\n"; // 检查最近创建的文章 echo "<h2>最近通过API创建的文章</h2>\n"; $query = $db->getQuery(true)     ->select('*')     ->from('#__content')     ->where('created_by_alias = ' . $db->quote('AI助手'))     ->order('id DESC')     ->setLimit(10); $db->setQuery($query); $articles = $db->loadObjectList(); echo "<table border='1' cellpadding='5'>\n"; echo "<tr>     <th>ID</th>     <th>标题</th>     <th>状态</th>     <th>asset_id</th>     <th>workflow_id</th>     <th>stage_id</th>     <th>创建时间</th> </tr>\n"; foreach ($articles as $article) {     $statusColor = $article->state == 1 ? 'green' : ($article->state == 0 ? 'red' : 'orange');     echo "<tr>         <td>{$article->id}</td>         <td>{$article->title}</td>         <td style='color:{$statusColor}'>{$article->state}</td>         <td>{$article->asset_id}</td>         <td>" . ($article->workflow_id ?? 'NULL') . "</td>         <td>" . ($article->stage_id ?? 'NULL') . "</td>         <td>{$article->created}</td>     </tr>\n"; } echo "</table>\n"; // 检查asset表对应的记录 echo "<h2>文章对应的Asset记录</h2>\n"; foreach ($articles as $article) {     if ($article->asset_id) {         $query = $db->getQuery(true)             ->select('*')             ->from('#__assets')             ->where('id = ' . (int)$article->asset_id);         $db->setQuery($query);         $asset = $db->loadObject();                  if ($asset) {             echo "<h3>文章 ID: {$article->id} - Asset ID: {$article->asset_id}</h3>\n";             echo "<pre>";             print_r($asset);             echo "</pre>\n";         } else {             echo "<p style='color:red'>文章 ID: {$article->id} 的asset记录不存在!</p>\n";         }     } } // 尝试创建一个测试文章 echo "<h2>创建测试文章</h2>\n"; try {     // 使用Joomla Table类     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/tables');     $table = JTable::getInstance('Content', 'ContentTable');          $testData = [         'title' => '工作流测试文章 ' . date('Y-m-d H:i:s'),         'alias' => 'workflow-test-' . time(),         'introtext' => '这是工作流测试文章的内容',         'fulltext' => '',         'catid' => 2,         'state' => 1,         'language' => '*',         'created' => JFactory::getDate()->toSql(),         'created_by' => JFactory::getUser()->id,         'created_by_alias' => '工作流测试',         'publish_up' => JFactory::getDate()->toSql(),         'access' => 1,         'workflow_id' => 1,         'stage_id' => 1,         'metadata' => '{"robots":"","author":"","rights":"","xreference":""}'     ];          if ($table->bind($testData) && $table->check() && $table->store()) {         echo "<p style='color:green'>✓ 测试文章创建成功!ID: {$table->id}</p>\n";                  // 检查创建的记录         $query = $db->getQuery(true)             ->select('*')             ->from('#__content')             ->where('id = ' . (int)$table->id);         $db->setQuery($query);         $createdArticle = $db->loadObject();                  echo "<h3>创建的文章详情:</h3>\n";         echo "<pre>";         print_r($createdArticle);         echo "</pre>\n";                  // 检查asset         if ($createdArticle->asset_id) {             $query = $db->getQuery(true)                 ->select('*')                 ->from('#__assets')                 ->where('id = ' . (int)$createdArticle->asset_id);             $db->setQuery($query);             $createdAsset = $db->loadObject();                          echo "<h3>对应的Asset记录:</h3>\n";             echo "<pre>";             print_r($createdAsset);             echo "</pre>\n";         }     } else {         echo "<p style='color:red'>✗ 测试文章创建失败: " . $table->getError() . "</p>\n";     } } catch (Exception $e) {     echo "<p style='color:red'>✗ 测试文章创建异常: " . $e->getMessage() . "</p>\n";     echo "<pre>" . $e->getTraceAsString() . "</pre>\n"; } echo "<hr>\n"; echo "<p>调试完成。</p>\n"; EOF echo "" echo "📁 创建了调试脚本: debug_workflow.php" echo "" echo "🔍 使用方法:" echo "  1. 将此文件上传到Joomla根目录" echo "  2. 通过浏览器访问: https://xxx.com/debug_workflow.php" echo "  3. 查看详细的工作流和数据库状态" echo "" echo "🎯 这个版本应该能彻底解决Joomla 5.x的工作流问题!" echo ""

Please Log in or Create an account to join the conversation.