nimg.neuroinf.jp/etc/dumpNimgdocsBulletin.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2022-06-20 17:51:03 +09:00
<?php
require_once __DIR__.'/common.inc.php';
require_once __DIR__.'/extras.inc.php';
$prefix = $xoopsDB->prefix();
$table = 'nimgdocs_bulletin';
if (!MyDumpTool::tableExists($table)) {
exit('nimgdocs module not found'.PHP_EOL);
}
$sql = <<< SQL
SELECT
`b`.*
FROM `${prefix}_${table}` AS `b`
WHERE `b`.`accepted`=1
ORDER BY `b`.`post_date` DESC
SQL;
if (!($res = $xoopsDB->query($sql))) {
var_dump($xoopsDB);
exit();
}
$data = [];
while ($row = $xoopsDB->fetchArray($res)) {
$row['tags'] = urldecode($row['tags']);
$row['text_en'] = urldecode($row['text_en']);
$row['text_jp'] = urldecode($row['text_jp']);
MyDumpTool::decode($row);
MyDumpTool::convertToInt($row, ['id', 'accepted']);
$row['text'] = [
'en' => $row['text_en'],
'ja' => $row['text_jp'],
];
MyDumpTool::dropColumn($row, ['accepted', 'text_en', 'text_jp']);
$row['tags'] = explode(' ', $row['tags']);
$row['post_date'] = strtotime($row['post_date']);
$row['end_date'] = strtotime($row['end_date']);
$data[] = $row;
}
$xoopsDB->freeRecordSet($res);
MyDumpTool::makeDirectory('src/nimgdocs/assets');
MyDumpTool::saveJson('src/nimgdocs/assets/bulletin.json', $data);