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 / DownloadLog.php

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

98 lines 3.3 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\Utilities\CommonFunctions;
6 use WPSynchro\Migration\MigrationFactory;
7 use WPSynchro\Utilities\Licensing\Licensing;
8 use WPSynchro\Utilities\PluginDirs;
9
10 /**
11 * Class for handling service to download logs
12 * Call should already be verified by permissions callback
13 *
14 */
15 class DownloadLog extends WPSynchroService
16 {
17 public function service()
18 {
19 if (!isset($_REQUEST['job_id']) || strlen($_REQUEST['job_id']) == 0) {
20 $result = new \StdClass();
21 echo json_encode($result);
22 http_response_code(400);
23 return;
24 }
25 $job_id = $_REQUEST['job_id'];
26
27 if (!isset($_REQUEST['migration_id']) || strlen($_REQUEST['migration_id']) == 0) {
28 $result = new \StdClass();
29 echo json_encode($result);
30 http_response_code(400);
31 return;
32 }
33 $migration_id = $_REQUEST['migration_id'];
34
35 $common = new CommonFunctions();
36 $migration_factory = MigrationFactory::getInstance();
37
38 $plugins_dirs = new PluginDirs();
39 $logpath = $plugins_dirs->getUploadsFilePath();
40 $filename = $common->getLogFilename($job_id);
41
42 if (file_exists($logpath . $filename)) {
43 $logcontents = "";
44
45 // Intro
46 $logcontents .= "Beware: Do not share this file with other people than WP Synchro support - It contains data that can compromise your site." . PHP_EOL . PHP_EOL;
47
48 // Licensing
49 if (CommonFunctions::isPremiumVersion()) {
50 $licensing = new Licensing();
51 $logcontents .= print_r($licensing->getLicenseState(), true);
52 $logcontents .= PHP_EOL;
53 } else {
54 $logcontents .= PHP_EOL . "License key: FREE version" . PHP_EOL;
55 $logcontents .= PHP_EOL;
56 }
57
58 // Log data
59 $logcontents .= file_get_contents($logpath . $filename);
60 $job_obj = get_option("wpsynchro_" . $migration_id . "_" . $job_id, "");
61 $migration_obj = $migration_factory->retrieveMigration($migration_id);
62
63 // migration object
64 $logcontents .= PHP_EOL . "Migration object:" . PHP_EOL;
65 $logcontents .= print_r($migration_obj, true);
66
67 // Job object
68 $logcontents .= PHP_EOL . "Job object:" . PHP_EOL;
69 $logcontents .= print_r($job_obj, true);
70
71 $zipfilename = "wpsynchro_log_" . $job_id . ".zip";
72
73 http_response_code(200); // IIS fails if this is not here
74 header("Pragma: public");
75 header("Expires: 0");
76 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
77 header("Cache-Control: public");
78 header("Content-Description: File Transfer");
79 header("Content-Type: application/zip");
80 header("Content-Disposition: attachment; filename=" . $zipfilename);
81
82 $zipfile = tempnam($logpath, "zip");
83 $zip = new \ZipArchive();
84 $zip->open($zipfile, \ZipArchive::OVERWRITE);
85 $zip->addFromString($filename, $logcontents);
86 $zip->close();
87
88 readfile($zipfile);
89 unlink($zipfile);
90
91 exit();
92 } else {
93 http_response_code(400);
94 return;
95 }
96 }
97 }
98