getPrevious(); $depth++; } return null; } /** * Read the build progress safely, falling back to a "stage 0/11, not * yet started" shape when the DAO call throws or is unavailable. * * @param object $abj404dao * @param ABJ_404_Solution_ViewBuildPendingException|null $pending * @return array */ public static function progress($abj404dao, $pending = null) { $progress = null; if (is_object($abj404dao) && method_exists($abj404dao, 'getViewBuildProgress')) { try { $progress = $abj404dao->getViewBuildProgress(); } catch (Throwable $ignored) { $progress = null; } } if (!is_array($progress)) { $progressText = ($pending instanceof ABJ_404_Solution_ViewBuildPendingException) ? $pending->getProgressText() : 'not yet started'; $progress = array( 'status' => 'pending', 'stage' => 0, 'of' => 11, 'build_started' => 0, 'progress_text' => $progressText !== '' ? $progressText : 'not yet started', ); } return $progress; } /** * Build the response shape `getPaginationLinks()` returns when the * fetch path is blocked on a pending build. * * @param object $abj404dao * @param string $subpage * @param string $cacheMode * @param ABJ_404_Solution_ViewBuildPendingException|null $pending * @return array */ public static function fetchResponse($abj404dao, $subpage, $cacheMode, $pending = null) { return array( 'viewBuildPending' => true, 'cacheMode' => $cacheMode, 'subpage' => $subpage, 'progress' => self::progress($abj404dao, $pending), 'message' => function_exists('__') ? __('Preparing the redirects view table. Please wait.', '404-solution') : 'Preparing the redirects view table. Please wait.', ); } /** * Build the response shape `warmTableCache()` returns when the snapshot * warm path is blocked on a pending build. Different from the fetch * shape because the JS placeholder hydration consumes `ready=false` * and the stage/stageNumber fields directly. * * @param object $abj404dao * @param ABJ_404_Solution_ViewBuildPendingException|null $pending * @return array */ public static function warmResponse($abj404dao, $pending = null) { return array( 'status' => 'pending', 'ready' => false, 'viewBuildPending' => true, 'stage' => 'rows', 'stageNumber' => 1, 'queryLabel' => 'getRedirectsForView', 'progress' => self::progress($abj404dao, $pending), ); } }