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