$row One raw row of getRedirectsExport.sql, * including its type_id, final_dest and cached_url columns. * @return array */ public static function csvColumns(array $row): array { $toUrl = $row['to_url'] ?? null; $typeId = ABJ_404_Solution_ExactInteger::read($row['type_id'] ?? null, 0); if ($typeId !== null) { $finalDest = $row['final_dest'] ?? ''; $cachedUrl = $row['cached_url'] ?? ''; $resolved = ABJ_404_Solution_PermalinkResolver::internalDestinationUrl( $typeId, is_scalar($finalDest) ? (string)$finalDest : '', is_string($cachedUrl) ? $cachedUrl : '' ); if ($resolved !== '') { $toUrl = $resolved; } elseif (in_array($typeId, array(ABJ404_TYPE_POST, ABJ404_TYPE_CAT, ABJ404_TYPE_TAG), true)) { // The query's to_url can contain a stale cached post URL. // Keep the stored id when the live destination is unavailable. $toUrl = $finalDest; } } return array( self::csvField($row['from_url'] ?? '', ''), self::csvField($row['status'] ?? '', ''), self::csvField($row['type'] ?? '', ''), self::csvField($toUrl, ''), self::csvField($row['type_wp'] ?? '', ''), self::csvField($row['engine'] ?? null, ''), self::csvField($row['code'] ?? null, '301'), self::csvField($row['query_mode'] ?? null, ''), ); } /** * A result-set value as a CSV field: scalars as they came from the driver, * anything else (null, a non-scalar) as $default. * * @param mixed $value * @param string $default * @return bool|float|int|string */ private static function csvField($value, string $default) { return is_scalar($value) ? $value : $default; } }