$context Optional: level, job_id, post_id. * @return void */ public static function add( string $type, string $message, array $context = array() ): void { $entry = array( 'time' => time(), 'type' => $type, 'level' => isset( $context['level'] ) ? (string) $context['level'] : self::LEVEL_INFO, 'message' => $message, 'job_id' => isset( $context['job_id'] ) ? (int) $context['job_id'] : 0, 'post_id' => isset( $context['post_id'] ) ? (int) $context['post_id'] : 0, ); // Frisch gelesen, siehe Settings::update(): sonst ueberschriebe ein // laufender Lauf ein zwischenzeitlich geleertes Protokoll. wp_cache_delete( self::OPTION, 'options' ); $log = self::all(); array_unshift( $log, $entry ); $log = array_slice( $log, 0, self::MAX_ENTRIES ); update_option( self::OPTION, $log, false ); /** * Meldet ein Protokollereignis weiter. * * @param array $entry Der geschriebene Eintrag. */ do_action( 'aivor_content_log', $entry ); } /** * Liefert alle Eintraege, neueste zuerst. * * @return array> */ public static function all(): array { $log = get_option( self::OPTION, array() ); return is_array( $log ) ? $log : array(); } /** * Leert das Protokoll. * * @return void */ public static function clear(): void { delete_option( self::OPTION ); } /** * Uebersetzte Bezeichnung eines Ereignistyps. * * @param string $type Einer der TYPE_-Werte. * @return string */ public static function label( string $type ): string { $labels = array( self::TYPE_RUN => __( 'Run', 'aivor-content-import' ), self::TYPE_IMPORTED => __( 'Imported', 'aivor-content-import' ), self::TYPE_REPLACED => __( 'Extended version', 'aivor-content-import' ), self::TYPE_REPORTED => __( 'Reported', 'aivor-content-import' ), self::TYPE_PATCH_APPLIED => __( 'Link update applied', 'aivor-content-import' ), self::TYPE_PATCH_STALE => __( 'Link update outdated', 'aivor-content-import' ), self::TYPE_PATCH_FAILED => __( 'Link update failed', 'aivor-content-import' ), self::TYPE_PATCH_DEFERRED => __( 'Link update postponed', 'aivor-content-import' ), self::TYPE_API_ERROR => __( 'API error', 'aivor-content-import' ), self::TYPE_IMAGE_FAILED => __( 'Featured image failed', 'aivor-content-import' ), self::TYPE_URL_UNVERIFIED => __( 'Address not confirmed', 'aivor-content-import' ), self::TYPE_DISCARDED => __( 'Delivery discarded', 'aivor-content-import' ), ); return $labels[ $type ] ?? $type; } }