PluginProbe
404 Solution / 4.1.19
404 Solution v4.1.19
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / PluginLogicTrait_ImportExport.php

PluginLogicTrait_ImportExport.php in 404 Solution 4.1.19, at includes/PluginLogicTrait_ImportExport.php

102 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Import/export functionality delegated to ABJ_404_Solution_ImportExportService.
9 * Used by ABJ_404_Solution_PluginLogic via `use`.
10 */
11 trait ABJ_404_Solution_PluginLogicTrait_ImportExport {
12
13 /** @return string */
14 function getExportFilename(string $format = 'native'): string {
15 return $this->getImportExportService()->getExportFilename($format);
16 }
17
18 /** @return void */
19 function doExport(): void {
20 $this->getImportExportService()->doExport();
21 }
22
23 /**
24 * Convert native export format to a Redirection-compatible CSV shape.
25 *
26 * @param string $sourceFile Native export file path.
27 * @param string $destinationFile Output file path.
28 * @return string Empty string on success, error message otherwise.
29 */
30 function convertExportCsvToRedirectionFormat($sourceFile, $destinationFile) {
31 return $this->getImportExportService()->convertExportCsvToRedirectionFormat($sourceFile, $destinationFile);
32 }
33
34 /** Expected formats are
35 * from_url,status,type,to_url,wp_type
36 * from_url,to_url
37 */
38 /** @return string */
39 function doImportFile(): string {
40 return $this->getImportExportService()->doImportFile();
41 }
42
43 /**
44 * @param array<string, mixed> $dataArray
45 * @param bool $dryRun
46 * @return array<int, string>
47 */
48 function loadDataArrayFromFile(array $dataArray, bool $dryRun = false): array {
49 return $this->getImportExportService()->loadDataArrayFromFile($dataArray, $dryRun);
50 }
51
52 /** @return array<string, string> */
53 function splitCsvLine(string $line): array {
54 return $this->getImportExportService()->splitCsvLine($line);
55 }
56
57 /**
58 * Detect whether this row appears to be a compatible competitor header row.
59 *
60 * @param array<int, string> $columns
61 * @return bool
62 */
63 function isCompatibleImportHeaderRow(array $columns): bool {
64 return $this->getImportExportService()->isCompatibleImportHeaderRow($columns);
65 }
66
67 /**
68 * Normalize import headers for matching.
69 *
70 * @param array<int, string> $columns
71 * @return array<int, string>
72 */
73 function normalizeImportHeaders(array $columns): array {
74 $result = $this->getImportExportService()->normalizeImportHeaders($columns);
75 return array_map(function ($v) {
76 return is_string($v) ? $v : '';
77 }, $result);
78 }
79
80 /**
81 * Map CSV row values into from_url/to_url using known competitor headers.
82 *
83 * @param array<int, string> $row
84 * @param array<int, string> $normalizedHeaders
85 * @return array<string, string>
86 */
87 function mapImportRowByHeaders(array $row, array $normalizedHeaders): array {
88 return $this->getImportExportService()->mapImportRowByHeaders($row, $normalizedHeaders);
89 }
90
91 /**
92 * Detect import format by CSV header row.
93 *
94 * @param array<int, string> $columns
95 * @return string
96 */
97 function detectImportFormatFromHeaders(array $columns): string {
98 return $this->getImportExportService()->detectImportFormatFromHeaders($columns);
99 }
100
101 }
102