@@ -167,50 +167,39 @@ private function local(): void
167167
168168 $ this ->taskLogSubStepController ->new ('updating-database ' , 'UPDATING DATABASE ' );
169169
170- // Check if repository already exists in database
170+ // If currently no rpm repo of this name exists in the database then we add it
171171 if ($ this ->repoController ->getPackageType () == 'rpm ' ) {
172- $ exists = $ this ->rpmRepoController ->exists ($ this ->repoController ->getName (), $ this ->repoController ->getReleasever ());
173- }
174- if ($ this ->repoController ->getPackageType () == 'deb ' ) {
175- $ exists = $ this ->debRepoController ->exists ($ this ->repoController ->getName (), $ this ->repoController ->getDist (), $ this ->repoController ->getSection ());
176- }
177-
178- /**
179- * If no repo of this name exists in database then we add it
180- * Note: here we set the source as $this->repoController->getName()
181- */
182- if ($ exists === false ) {
183- // Retrieve repo Id from the last insert row
184- if ($ this ->repoController ->getPackageType () == 'rpm ' ) {
172+ if (!$ this ->rpmRepoController ->exists ($ this ->repoController ->getName (), $ this ->repoController ->getReleasever ())) {
173+ // Note: for local repositories, source is set to repo name
185174 $ this ->rpmRepoController ->add ($ this ->repoController ->getName (), $ this ->repoController ->getReleasever (), $ this ->repoController ->getName ());
175+
176+ // Repository Id becomes the Id of the last inserted row in the database
186177 $ this ->repoController ->setRepoId ($ this ->rpmRepoController ->getLastInsertRowID ());
187- }
188- if ($ this ->repoController ->getPackageType () == 'deb ' ) {
189- $ this ->debRepoController ->add ($ this ->repoController ->getName (), $ this ->repoController ->getDist (), $ this ->repoController ->getSection (), $ this ->repoController ->getName ());
190- $ this ->repoController ->setRepoId ($ this ->debRepoController ->getLastInsertRowID ());
191- }
192178
193- /**
194- * Else if a repo of this name exists, we attach this new snapshot and this new env to this repo
195- */
196- } else {
197- // Retrieve and set repo Id from database
198- if ($ this ->repoController ->getPackageType () == 'rpm ' ) {
199- $ repoId = $ this ->rpmRepoController ->getIdByNameReleasever ($ this ->repoController ->getName (), $ this ->repoController ->getReleasever ());
179+ // Otherwise, if a repo of the same name exists, we retrieve its Id from the database
180+ } else {
181+ $ this ->repoController ->setRepoId ($ this ->rpmRepoController ->getIdByNameReleasever ($ this ->repoController ->getName (), $ this ->repoController ->getReleasever ()));
200182 }
183+ }
201184
202- if ($ this ->repoController ->getPackageType () == 'deb ' ) {
203- $ repoId = $ this ->debRepoController ->getIdByNameDistComponent ($ this ->repoController ->getName (), $ this ->repoController ->getDist (), $ this ->repoController ->getSection ());
204- }
185+ // If currently no deb repo of this name exists in the database then we add it
186+ if ($ this ->repoController ->getPackageType () == 'deb ' ) {
187+ if (!$ this ->debRepoController ->exists ($ this ->repoController ->getName (), $ this ->repoController ->getDist (), $ this ->repoController ->getSection ())) {
188+ // Note: for local repositories, source is set to repo name
189+ $ this ->debRepoController ->add ($ this ->repoController ->getName (), $ this ->repoController ->getDist (), $ this ->repoController ->getSection (), $ this ->repoController ->getName ());
205190
206- if (empty ($ repoId )) {
207- throw new Exception ('Could not retrieve repository Id from database ' );
208- }
191+ // Repository Id becomes the Id of the last inserted row in the database
192+ $ this ->repoController ->setRepoId ($ this ->debRepoController ->getLastInsertRowID ());
209193
210- $ this ->repoController ->setRepoId ($ repoId );
194+ // Otherwise, if a repo of the same name exists, we retrieve its Id from the database
195+ } else {
196+ $ this ->repoController ->setRepoId ($ this ->debRepoController ->getIdByNameDistComponent ($ this ->repoController ->getName (), $ this ->repoController ->getDist (), $ this ->repoController ->getSection ()));
197+ }
211198 }
212199
213- unset($ exists , $ repoId );
200+ // Apply description and tags after the repository Id has been determined,
201+ $ this ->repoController ->updateDescription ($ this ->repoController ->getRepoId (), (string ) $ this ->repoController ->getDescription ());
202+ $ this ->repoController ->updateTags ($ this ->repoController ->getRepoId (), $ this ->repoController ->getTags ());
214203
215204 // Add snapshot to database
216205 $ this ->repoSnapshotController ->add ($ this ->repoController ->getDate (), $ this ->repoController ->getTime (), 'false ' , $ this ->repoController ->getArch (), $ this ->repoController ->getAdvancedParams (), $ this ->repoController ->getType (), 'active ' , $ this ->repoController ->getRepoId ());
0 commit comments