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\Core\Config;
9 use Friendica\Core\Logger;
10 use Friendica\Model\Item;
12 require_once "include/items.php";
15 public static function execute() {
16 $path = get_spoolpath();
18 if (($path != '') && is_writable($path)){
19 if ($dh = opendir($path)) {
20 while (($file = readdir($dh)) !== false) {
22 // It is not named like a spool file, so we don't care.
23 if (substr($file, 0, 5) != "item-") {
27 $fullfile = $path."/".$file;
29 // We don't care about directories either
30 if (filetype($fullfile) != "file") {
34 // We can't read or write the file? So we don't care about it.
35 if (!is_writable($fullfile) || !is_readable($fullfile)) {
39 $arr = json_decode(file_get_contents($fullfile), true);
41 // If it isn't an array then it is no spool file
42 if (!is_array($arr)) {
46 // Skip if it doesn't seem to be an item array
47 if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
51 $result = Item::insert($arr);
53 Logger::log("Spool file ".$file." stored: ".$result, Logger::DEBUG);