query( "SELECT id, name, google_ads_customer_id FROM clients WHERE deleted = 0 ORDER BY name ASC" ) -> fetchAll( \PDO::FETCH_ASSOC ); $rows = []; foreach ( $clients as $client ) { $client_id = (int) ( $client['id'] ?? 0 ); $scheme = ( !empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off' ) ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST'] ?? ( $_SERVER['SERVER_NAME'] ?? 'localhost' ); $relative_path = '/xml/custom-feed-' . $client_id . '.xml'; $absolute_url = $scheme . '://' . $host . $relative_path; $absolute_path = dirname( __DIR__, 2 ) . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'custom-feed-' . $client_id . '.xml'; $exists = is_file( $absolute_path ); $last_modified = $exists ? date( 'Y-m-d H:i:s', (int) filemtime( $absolute_path ) ) : ''; $rows[] = [ 'client_id' => $client_id, 'client_name' => (string) ( $client['name'] ?? '' ), 'google_ads_customer_id' => (string) ( $client['google_ads_customer_id'] ?? '' ), 'xml_relative_path' => $relative_path, 'xml_url' => $absolute_url, 'xml_exists' => $exists, 'xml_last_modified' => $last_modified ]; } return $rows; } }