3 * @file src/Worker/SpoolPost.php
4 * @brief Posts items that wer spooled because they couldn't be posted.
6 namespace Friendica\Worker;
8 use Friendica\Model\Item;
9 use Friendica\Core\Config;
11 require_once("include/items.php");
14 public static function execute() {
15 $path = get_spoolpath();
17 if (($path != '') && is_writable($path)){
18 if ($dh = opendir($path)) {
19 while (($file = readdir($dh)) !== false) {
21 // It is not named like a spool file, so we don't care.
22 if (substr($file, 0, 5) != "item-") {
26 $fullfile = $path."/".$file;
28 // We don't care about directories either
29 if (filetype($fullfile) != "file") {
33 // We can't read or write the file? So we don't care about it.
34 if (!is_writable($fullfile) || !is_readable($fullfile)) {
38 $arr = json_decode(file_get_contents($fullfile), true);
40 // If it isn't an array then it is no spool file
41 if (!is_array($arr)) {
45 // Skip if it doesn't seem to be an item array
46 if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
50 $result = Item::insert($arr);
52 logger("Spool file ".$file." stored: ".$result, LOGGER_DEBUG);