Přeskočit na hlavní obsah

AfterInstall Script

This script is executed after the installation or upgrade of an extension in EspoCRM. It handles various post-installation tasks such as checking module dependencies, updating configuration, creating default records, and clearing cache.


Technické informace

The AfterInstall class is located in scripts/AfterInstall.php and implements the following key functionality:

  • Dependency Injection: Loads required dependencies through the EspoCRM container system using InjectableFactory. Key dependencies include:

  • Config - For accessing system configuration

  • ConfigWriter - For modifying configuration values

  • EntityManager - For database operations

  • DataManager - For cache management

  • Module Dependency Checking:

  • Uses REQUIRED_MODULES constant to define required modules and their version constraints

  • Validates installed modules against these requirements using checkModuleDependencies()

  • Implements complex version comparison logic in satisfiesVersionRequirement() supporting operators: \≥, \≤, !=, \>, \<, ^, ~

  • Configuration Management:

  • defaultConfig() - Applies default configuration values from DEFAULT_CONFIG constant

  • addEntitiesToTabList() - Adds entities defined in TAB_LIST_ENTITIES to the navigation tab list

  • Record Creation:

  • createDefaultRecords() - Creates default records defined in DEFAULT_RECORDS constant

  • Uses EntityManager to create entities with duplicate checking

  • Implements complex query building using Condition and Expression

  • Cache Management:

  • clearCache() - Clears system cache through DataManager

The script differentiates between fresh installs and upgrades using the isUpgrade parameter in the run() method.