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\Logger;
9 use Friendica\Model\Item;
12 public static function execute() {
13 $path = get_spoolpath();
15 if (($path != '') && is_writable($path)){
16 if ($dh = opendir($path)) {
17 while (($file = readdir($dh)) !== false) {
19 // It is not named like a spool file, so we don't care.
20 if (substr($file, 0, 5) != "item-") {
24 $fullfile = $path."/".$file;
26 // We don't care about directories either
27 if (filetype($fullfile) != "file") {
31 // We can't read or write the file? So we don't care about it.
32 if (!is_writable($fullfile) || !is_readable($fullfile)) {
36 $arr = json_decode(file_get_contents($fullfile), true);
38 // If it isn't an array then it is no spool file
39 if (!is_array($arr)) {
43 // Skip if it doesn't seem to be an item array
44 if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
48 $result = Item::insert($arr);
50 Logger::log("Spool file ".$file." stored: ".$result, Logger::DEBUG);