Ignore:
Timestamp:
Jan 4, 2021, 9:55:40 PM (3 years ago)
Author:
chronos
Message:
  • Modified: More work on modules models initialization.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/AppModule.php

    r891 r893  
    7373  }
    7474
    75   static function GetModels(): array
     75  function GetModels(): array
    7676  {
    7777    return array();
     
    8484    $this->Manager->EnumDependenciesCascade($this, $List, array(ModuleCondition::NotInstalled));
    8585    $this->Manager->Perform($List, array(ModuleAction::Install), array(ModuleCondition::NotInstalled));
     86    $this->InstallModels();
    8687    $this->DoInstall();
    8788    $this->Installed = true;
     
    99100    $this->Manager->Perform($List, array(ModuleAction::Uninstall), array(ModuleCondition::Installed));
    100101    $this->DoUninstall();
     102    $this->UninstallModels();
    101103  }
    102104
     
    188190  {
    189191    $this->Models[get_class($Model)] = $Model;
     192  }
     193
     194  function InstallModels(): void
     195  {
     196    foreach ($this->GetModels() as $Model)
     197    {
     198      $this->InstallModel($Model::GetDesc());
     199    }
     200  }
     201
     202  function UninstallModels(): void
     203  {
     204    foreach (array_reverse($this->GetModels()) as $Model)
     205    {
     206      $this->UninstallModel($Model::GetDesc());
     207    }
    190208  }
    191209
     
    242260        $Query .= "ALTER TABLE `".$ModelDesc->Name."` ".
    243261        "ADD CONSTRAINT `".$ModelDesc->Name."_ibfk_".$I."` FOREIGN KEY (`".$Column->Name."`) REFERENCES `".$Column->RefTable."` (`Id`);";
     262      $I++;
    244263    }
    245264    $this->Database->query($Query);
Note: See TracChangeset for help on using the changeset viewer.