PluginProbe
WP Synchro – The Ultimate WordPress Migration Tool / trunk
WP Synchro – The Ultimate WordPress Migration Tool vtrunk
1.16.1 1.16.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.11.5 1.12.0 1.13.0 1.14.0 1.15.0 1.2.0 1.3.0 1.3.1 1.3.2 All 45 releases
wpsynchro / src / API / FileFinalize.php

FileFinalize.php in WP Synchro – The Ultimate WordPress Migration Tool trunk, at src/API/FileFinalize.php

81 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPSynchro\API;
4
5 use WPSynchro\Transport\TransferAccessKey;
6 use WPSynchro\Files\FileHelperFunctions;
7 use WPSynchro\Transport\ReturnResult;
8 use WPSynchro\Transport\Transfer;
9 use WPSynchro\Utilities\SyncTimerList;
10
11 /**
12 * Class for handling service "FileFinalize"
13 * Call should already be verified by permissions callback
14 *
15 */
16 class FileFinalize extends WPSynchroService
17 {
18 public function service()
19 {
20 // Init timer
21 $timer = SyncTimerList::getInstance();
22 $timer->init();
23 // Transfer object
24 $transfer = new Transfer();
25 $transfer->setEncryptionKey(TransferAccessKey::getAccessKey());
26 $transfer->populateFromString($this->getRequestBody());
27 $body = $transfer->getDataObject();
28 // Extract parameters
29 $delete = $body->delete;
30 $allotted_time = $body->allotted_time;
31 $timer->addOtherSyncTimeLimit($allotted_time);
32 $result = new \stdClass();
33 $result->success = false;
34 $result->errors = [];
35 $result->warnings = [];
36 $result->debugs = [];
37 $result->debugs[] = "Finalize service: Start finalize with max time: " . $timer->getRemainingSyncTime();
38 // remove the old dirs/files
39 foreach ($delete as $key => &$deletepath) {
40 $filepath = $deletepath->target_file;
41 if (!file_exists($filepath) || !is_writable($filepath)) {
42 $result->debugs[] = "Finalize service: Could not find/change file/dir that is on delete array, so ignoring the file: " . $filepath;
43 $deletepath->deleted = true;
44 continue;
45 }
46
47 $deleted = false;
48 if (is_file($filepath)) {
49 unlink($filepath);
50 $deleted = true;
51 } else {
52 $delete_result = FileHelperFunctions::removeDirectory($filepath, $timer);
53 $result->debugs[] = "Finalize service: Starting deleting: " . $filepath;
54 if ($delete_result === false) {
55 // Delete did not complete within timeframe
56 $result->debugs[] = "Finalize service: Could not complete delete within max time for: " . $filepath;
57 } else {
58 $deleted = true;
59 }
60 }
61 if ($deleted) {
62 $result->debugs[] = "Finalize service: Deleted " . $filepath;
63 $deletepath->deleted = true;
64 }
65
66 if (!$timer->shouldContinueWithLastrunTime(3)) {
67 $result->debugs[] = "Finalize service: File/dir needs to abort due to max execution time";
68 break;
69 }
70 }
71
72 // When all is deleted, we have completed
73 $result->debugs[] = "Finalize service: File/dir deleted completed";
74 $result->delete = $delete;
75 $returnresult = new ReturnResult();
76 $returnresult->init();
77 $returnresult->setDataObject($result);
78 return $returnresult->echoDataFromServiceAndExit();
79 }
80 }
81