PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / Import / ImagesImporterRunner.php

ImagesImporterRunner.php in Extendify 3.2.1, at app/Shared/Services/Import/ImagesImporterRunner.php

86 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Import\Images Runner
5 */
6
7 namespace Extendify\Shared\Services\Import;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 /**
12 * This class will handle the actual imports
13 */
14
15 class ImagesImporterRunner
16 {
17 /**
18 * Process posts content to import external images.
19 *
20 * @return void
21 */
22 public function run()
23 {
24 // Return early if conditions are not met for processing images.
25 if (
26 !\get_option('extendify_check_for_image_imports')
27 || \get_transient('extendify_import_images_check_delay')
28 || \wp_get_upload_dir()['error']
29 ) {
30 return;
31 }
32
33 // Try to execute set the limit to something that will work forever.
34 // phpcs:ignore WordPress.PHP.NoSilencedErrors, Generic.PHP.NoSilencedErrors.Discouraged
35 if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
36 // phpcs:ignore WordPress.PHP.NoSilencedErrors, Generic.PHP.NoSilencedErrors.Discouraged
37 @set_time_limit(0);
38 }
39
40 // Set a marker in the future so we don't check while working.
41 $this->delayProcessing(HOUR_IN_SECONDS);
42
43 // Get the posts that we need to update.
44 $posts = Post::all();
45
46 if (!$posts) {
47 \delete_transient('extendify_import_images_check_delay');
48 return;
49 }
50
51 // loop over the posts.
52 foreach ($posts as $post) {
53 // If the post is locked we update the marker to run next hour.
54 if (Post::isLocked($post->ID)) {
55 $this->delayProcessing(15 * MINUTE_IN_SECONDS);
56 continue;
57 }
58
59 $updatedBlockContent = (new BlocksUpdater())->getModifiedBlocksInPost($post);
60 $status = Post::update($post, $updatedBlockContent);
61
62 // If something went wrong, check again (much) later.
63 if (is_wp_error($status)) {
64 $this->delayProcessing(6 * HOUR_IN_SECONDS);
65 }
66 }//end foreach
67
68 // Delete the signal that says there's something to import.
69 if (!Post::countPostsNeedingUpdate()->posts_count) {
70 \delete_option('extendify_check_for_image_imports');
71 }
72 }
73
74 /**
75 * Sets a marker to delay processing until later.
76 *
77 * @param mixed $expiration Time until expiration in seconds. Default 86400 (one day).
78 *
79 * @return void
80 */
81 public function delayProcessing($expiration)
82 {
83 \set_transient('extendify_import_images_check_delay', time(), $expiration);
84 }
85 }
86