@@ -78,12 +78,17 @@ protected function getSiteConfig(string $siteName = 'default'): array
7878 * The site configuration key to load.
7979 * @param string $siteName
8080 * The site name.
81+ * @param bool $required
82+ * Whether the config item is expected to always be present.
8183 */
82- public function getSiteConfigItem (string $ key , string $ siteName = 'default ' ): mixed
84+ public function getSiteConfigItem (string $ key , string $ siteName = 'default ' , bool $ required = true ): mixed
8385 {
8486 $ siteConfig = $ this ->getSiteConfig (siteName: $ siteName );
8587 if (!isset ($ siteConfig [$ key ])) {
86- throw new TaskException ($ this , "Key $ key not found for ' $ siteName' in $ this ->sitesConfigFile . " );
88+ if ($ required ) {
89+ throw new TaskException ($ this , "Key $ key not found for ' $ siteName' in $ this ->sitesConfigFile . " );
90+ }
91+ return null ;
8792 }
8893 return $ siteConfig [$ key ];
8994 }
@@ -99,4 +104,24 @@ protected function writeSitesConfig(array $sitesConfig): void
99104 ksort ($ sitesConfig );
100105 file_put_contents ($ this ->sitesConfigFile , Yaml::dump ($ sitesConfig ));
101106 }
107+
108+ /**
109+ * Get the Drupal site admin user ID.
110+ *
111+ * @param string $siteName
112+ * The site name.
113+ *
114+ * @return int
115+ * The Drupal admin user ID.
116+ */
117+ protected function getDrupalSiteAdminUid (string $ siteName = 'default ' ): int
118+ {
119+ return $ this ->getSiteConfigItem (
120+ key: 'drupal_user_login_uid ' ,
121+ siteName: $ siteName ,
122+ required: false ,
123+ // @todo: Replace the use of '1' with a constant once we drop PHP
124+ // 8.1 support.
125+ ) ?? 1 ;
126+ }
102127}
0 commit comments