Page MenuHomePhabricator

DatabaseDomain::getId() with schema incorrect identifier formation
Open, LowPublicBUG REPORT

Description

I noticed that after upgrade to MW 1.34 my sitemaps changed names if a weird manner.
Like this: sitemap-index-DBNAME-SCHEMA-.xml (note the last dash).

generateSitemap.php script constructs filename from DatabaseDomain::getId() and I believe there is a bug there.

	private function convertToString() {
		$parts = [ (string)$this->database ];
		if ( $this->schema !== null ) {
			$parts[] = $this->schema;
		}
		if ( $this->prefix != '' || $this->schema !== null ) {
			// If there is a schema, then we need the prefix to disambiguate.
			// For engines like Postgres that use schemas, this awkwardness is hopefully
			// avoided since it is easy to have one DB per server (to avoid having many users)
			// and use schema/prefix to have wiki farms. For example, a domain schemes could be
			// wiki-<project>-<language>, e.g. "wiki-fitness-es"/"wiki-sports-fr"/"wiki-news-en".
			$parts[] = $this->prefix;
		}

		return implode( '-', array_map( [ __CLASS__, 'encode' ], $parts ) );
	}

I don't understand the line: if ( $this->prefix != '' || $this->schema !== null ) {
If there is prefix everything is sound, but if there is not - why add an empty prefix to the id anyway? Even if schema is non-null, didn't we add it a few lines before?