]> git.mxchange.org Git - friendica.git/blob - src/Worker/SpoolPost.php
wrapping up 2019.12
[friendica.git] / src / Worker / SpoolPost.php
1 <?php
2 /**
3  * @file src/Worker/SpoolPost.php
4  * @brief Posts items that wer spooled because they couldn't be posted.
5  */
6 namespace Friendica\Worker;
7
8 use Friendica\Core\Logger;
9 use Friendica\Model\Item;
10
11 class SpoolPost {
12         public static function execute() {
13                 $path = get_spoolpath();
14
15                 if (($path != '') && is_writable($path)){
16                         if ($dh = opendir($path)) {
17                                 while (($file = readdir($dh)) !== false) {
18
19                                         // It is not named like a spool file, so we don't care.
20                                         if (substr($file, 0, 5) != "item-") {
21                                                 continue;
22                                         }
23
24                                         $fullfile = $path."/".$file;
25
26                                         // We don't care about directories either
27                                         if (filetype($fullfile) != "file") {
28                                                 continue;
29                                         }
30
31                                         // We can't read or write the file? So we don't care about it.
32                                         if (!is_writable($fullfile) || !is_readable($fullfile)) {
33                                                 continue;
34                                         }
35
36                                         $arr = json_decode(file_get_contents($fullfile), true);
37
38                                         // If it isn't an array then it is no spool file
39                                         if (!is_array($arr)) {
40                                                 continue;
41                                         }
42
43                                         // Skip if it doesn't seem to be an item array
44                                         if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
45                                                 continue;
46                                         }
47
48                                         $result = Item::insert($arr);
49
50                                         Logger::log("Spool file ".$file." stored: ".$result, Logger::DEBUG);
51                                         unlink($fullfile);
52                                 }
53                                 closedir($dh);
54                         }
55                 }
56         }
57 }