Compare commits

..

174 Commits

Author SHA1 Message Date
faffe3d874 Update EspoCRM Best Practices to version 2.4 with new features and implementation patterns for Custom API Endpoints; remove outdated TESTERGEBNISSE_JUNCTION_TABLE.md file. 2026-03-12 22:52:42 +01:00
bf0f596ad4 Update configuration and localization files for CAIKnowledgeCDokumente; add metadata and scopes 2026-03-12 22:40:38 +01:00
3ecc6275bc Implement CAIKnowledge and CDokumente junction functionality; add API routes, metadata, and localization files 2026-03-12 22:39:33 +01:00
d0397e475e Remove unused CAICollectionCDokumente localization, metadata, and service files; update CAIKnowledge layout and CAdvowareAkten scope type 2026-03-12 21:50:02 +01:00
51d9f7fa22 Refactor Blake3 hashing implementation in CDokumente; update localization and metadata files 2026-03-11 22:45:42 +01:00
80dc3b40d3 Implement Blake3 hashing in CDokumente; update related metadata and localization files 2026-03-11 22:20:21 +01:00
e15dd14cab Add 'pending_sync' status to syncStatus in CAIKnowledge and CAdvowareAkten entities; update tooltips and API documentation 2026-03-11 22:05:27 +01:00
54d66da52d Add 'syncedHash' field to CAIKnowledge and CAdvowareAkten entities; update API documentation and configuration timestamps 2026-03-11 21:53:35 +01:00
ae359048af Add 'aktivierungsstatus' field to CAIKnowledge and CAdvowareAkten entities; update API documentation and configuration timestamps 2026-03-11 21:49:02 +01:00
c678660ad6 Add 'unsupported' status to dokumenteSyncstatus in CAIKnowledge and CAIKnowledgeCDokumente; update API documentation and configuration timestamps 2026-03-11 21:19:56 +01:00
c952fc40bc Update configuration and state files; adjust microtime values and add CAIKnowledgeCDokumente junction entity with metadata and API documentation 2026-03-11 20:48:35 +01:00
b2c391539d Update documentation for Junction Table UI-Integration and document propagation patterns; include new features and best practices for sync status management 2026-03-11 20:38:45 +01:00
e7b14406fb Update detail layouts for CMietinkasso and CVmhRumungsklage to include AI Knowledge and Advoware Akten; update cache and microtime state in state.php 2026-03-11 20:09:13 +01:00
4707925917 Update timestamps in config and state files; add hooks for document relation propagation in CAIKnowledge, CAdvowareAkten, CMietinkasso, and CVmhRumungsklage 2026-03-11 20:07:34 +01:00
c2c9cfe709 Remove Advoware and x.AI related fields, tooltips, and options from CDokumente JSON files. Add UpdateJunctionSyncStatus hook to manage sync status for related entities on document updates. Update configuration timestamps in state and config files. 2026-03-11 19:55:29 +01:00
9411337939 Add sync status and last sync fields to CAIKnowledge and CAdvowareAkten entities, update layouts and metadata. Implement hooks for global sync status management. 2026-03-11 19:29:55 +01:00
986cafcfd6 Add new fields and layouts for AI Knowledge and Advoware Akten, update translations and metadata 2026-03-11 19:11:41 +01:00
c12577f4f8 Add AI Knowledge entity and related localization
- Introduced CAIKnowledge entity with fields for name, description, and relationships to Mietinkasso and Räumungsklage.
- Added localization files for CAIKnowledge in multiple languages including English, German, Spanish, and more.
- Updated existing JSON files to include references to AI Knowledge where applicable.
- Created necessary metadata definitions for client, entity, and record definitions for CAIKnowledge.
- Enhanced existing documents and mietinkasso resources to support new AI Knowledge functionality.
2026-03-11 18:30:21 +01:00
f7b1adc015 Add CAdvowareAkten entity and related metadata
- Introduced new entity CAdvowareAkten with fields: name, description, createdAt, modifiedAt, assignedUser, teams, vmhRumungsklage, mietinkasso, aktenzeichen, and aktennummer.
- Defined relationships for CAdvowareAkten with existing entities: CVmhRumungsklage and CMietinkasso.
- Created client definitions, layouts, and ACL for CAdvowareAkten.
- Added internationalization support for CAdvowareAkten in multiple languages.
- Updated existing entities and metadata to include references to CAdvowareAkten.
2026-03-11 18:21:20 +01:00
0f307c7eca Remove CAICollection and CAdvowareAkten entities and their associated metadata, layouts, services, and translations. Update configuration and state files accordingly. Add side panel configuration for CMietinkasso. 2026-03-11 10:24:52 +01:00
9ab8f8b4bf Add Mietinkasso and Räumungsklage fields to translations and metadata, update layouts and configuration 2026-03-11 10:15:02 +01:00
8438af8f97 Update translations and metadata for CVmhRumungsklage, and synchronize cache timestamps 2026-03-11 09:27:54 +01:00
76c38e8ad4 Refactor code structure for improved readability and maintainability 2026-03-11 09:21:52 +01:00
c2766ec66a Update documentation for EspoCRM Best Practices and Validator Tool 2026-03-10 12:46:14 +01:00
9b18a63acf Update configuration timestamps, add custom services, and implement validation and rebuild script for EspoCRM 2026-03-10 12:35:01 +01:00
641e5c0a91 Update cache timestamps and microtime values in configuration and state files 2026-03-10 12:24:35 +01:00
3470dba301 Add junction entities and ACL for CAICollection, CAdvowareAkten, and CPulsTeam
- Introduced new junction entities: CAICollectionCDokumente, CAdvowareAktenCDokumente, and CPulsTeamZuordnung.
- Implemented respective controllers and services for handling CRUD operations.
- Added metadata definitions for new entities, including fields, links, and indexes.
- Created language files for English and German translations for the new entities.
- Developed a script to set ACL permissions for the new junction entities across existing roles.
- Updated existing entity definitions to include new relationships and fields related to Advoware and AI Collections.
2026-03-10 00:10:57 +01:00
0340c59e5c Add CAICollection and Advoware Akten entity and related resources 2026-03-09 23:57:48 +01:00
cd7c80af0f Remove CPulsTeamZuordnung entity definitions, localization files, and update cache timestamps in configuration and state files. 2026-03-09 23:56:19 +01:00
1f32fbb89b Remove CAICollectionCDokumente and CAICollections controllers, related metadata, and localization files. Update configuration and state files. 2026-03-09 23:55:42 +01:00
63e3841f86 Update documentation: Add Hook development section and Custom Entities overview 2026-03-09 23:12:30 +01:00
2e9db78c6e Refactor code structure for improved readability and maintainability 2026-03-09 23:07:05 +01:00
3361cffb14 introducing junction table extension 2026-03-09 22:42:40 +01:00
47634c81ef add CAICollections entity with metadata and localization support 2026-03-09 21:28:21 +01:00
53dd8f33d4 fix: Update fileStatus to 'synced' in CDokumente hooks and translations; adjust microtime and cacheTimestamp in config and state files 2026-03-08 21:56:00 +01:00
1b904eb15f fix: Update synchronization status messages and add "no_sync" option; adjust microtime and cacheTimestamp in config and state files; add beforeSaveScripts for Advoware sync status management 2026-03-08 21:10:08 +01:00
3547f47fc3 fix: Update xaiSyncStatus descriptions and default value; adjust microtime and cacheTimestamp in config and state files; add beforeSaveScript for x.AI sync status management 2026-03-08 20:16:51 +01:00
1d3eb86c6e fix: Update microtime and cacheTimestamp values in config and state files 2026-03-08 20:14:21 +01:00
926b6d9719 fix: Add "no_sync" status to CDokumente translations; update microtime values in config and state files 2026-03-08 20:09:14 +01:00
81a690277f fix: Add webhookAllowedAddressList to config; update cacheTimestamp and microtimeState in state 2026-03-08 19:40:20 +01:00
ded721a9d4 fix: Add "pulse" field to multiple JSON files; update microtime values in config and state files 2026-03-08 19:19:09 +01:00
218b6e0d97 some big beautiful update 2026-03-08 19:18:17 +01:00
845a55d170 fix: Swap md5sum and fileStatus fields in CDokumente layout; update microtime values in config and state files 2026-03-03 10:05:57 +01:00
6696f3f3c2 fix: Update beforeSave hook in CDokumente to ensure hash calculation on file changes; adjust microtime values in state file 2026-03-03 09:57:22 +01:00
22ac828747 fix: Remove unused Util import in CDokumente hook; update microtime values in config and state files 2026-03-03 09:55:29 +01:00
752969ec39 fix: Update CDokumente entity to allow editing after creation; adjust microtime values in config and state files 2026-03-03 08:24:21 +01:00
ec25089ab4 feat: Add file status tracking to CDokumente entity; implement beforeSave hook for hash calculation and status determination 2026-03-03 08:17:51 +01:00
ba986a32fe some big beautfiul update 2026-03-02 18:05:59 +01:00
bf7eaa965f feat: Refactor CPuls entity and related resources; enhance localization, update layouts, and improve validation logic 2026-02-13 10:28:21 +01:00
e1a963ffab feat(CPuls): Enhance CPuls entity with new fields, tooltips, and options; add localization for German and English
- Added new fields to CPuls entity including status, syncStatus, kiAnalyse, and others.
- Implemented localization for CPuls in German (de_DE) and English (en_US).
- Introduced new API actions for team activation and completion of CPuls.
- Created hooks to update team statistics and manage document counts.
- Added new entity definitions and metadata for CPulsTeamZuordnung and Team.
- Implemented validation logic in formulas to prevent completion of unclean Puls.
- Updated layouts for detail and list views of CPuls.
- Enhanced user entity with absence tracking fields.
- Added scopes for CPuls and CPulsTeamZuordnung.
2026-02-13 10:09:19 +01:00
0faf1c0657 Add CPuls entity and related resources
- Introduced a new entity "CPuls" with metadata definitions including fields, links, and indexes.
- Updated existing JSON files to include "CPuls" in various contexts such as translations, entity definitions, and client definitions.
- Added localization support for "CPuls" in multiple languages.
- Modified existing files to accommodate the new entity in the application structure.
2026-02-13 09:53:35 +01:00
300441de67 feat: Update synchronization status options and default values across multiple entity definitions and language files 2026-02-08 23:51:21 +01:00
a24bc99b67 feat: Add dynamic logic for readOnly fields in CBankverbindungen entity and update cache timestamps in configuration files 2026-02-08 21:02:21 +01:00
31479e71e1 feat: Add kommunikationHash field to CBeteiligte entity and update related metadata, layouts, and internationalization files 2026-02-08 21:01:05 +01:00
1eebc62039 feat: Add advowareRowId field to CBeteiligte entity and update related metadata and layouts 2026-02-07 23:13:41 +01:00
6e6fc841f5 fix: Remove readOnly attribute from betnr and syncStatus fields in CBeteiligte entity 2026-02-07 16:27:50 +01:00
44658e1238 feat: Update layout configurations and metadata for CBeteiligte entity 2026-02-07 16:21:03 +01:00
f95246f99f updated advanced pack to 3.12.0:
Reports:

    Non-aggregated columns in Grid report export.
    Normalized table mode for 2-dimensional Grid reports.
    Ability to create internal reports via the UI.
    Ability to show/hide and resize columns in the list report result view.
2026-02-07 16:09:20 +01:00
26db904407 feat: Update internationalization files and metadata for Advoware integration 2026-02-07 16:08:30 +01:00
127fa6503b chore: Update copyright year from 2025 to 2026 across core files
- Updated copyright headers in 3,055 core application files
- Changed 'Copyright (C) 2014-2025' to 'Copyright (C) 2014-2026'
- Added 123 new files from EspoCRM core updates
- Removed 4 deprecated files
- Total changes: 61,637 insertions, 54,283 deletions

This is a routine maintenance update for the new year 2026.
2026-02-07 16:05:21 +01:00
6a8a4a2882 Add development plan for intelligent inbox system with AI analysis
- Introduced comprehensive specifications for the "Entwicklungen-System" aimed at automating document processing for eviction lawsuits, rent collection, and terminations.
- Defined core principles, architecture overview, and detailed entity models including CEntwicklung and CEntwicklungTeamZuordnung.
- Implemented validation rules, custom API endpoints, and middleware integration for document processing and absence management.
- Established testing and quality assurance strategies, including unit tests and integration scenarios.
- Outlined deployment checklist and rollback plan to ensure smooth implementation.
- Included future roadmap for potential enhancements and defined roles and responsibilities for team members.
2026-01-25 22:13:44 +01:00
3dab9243de feat: Expand file permission checks and automatic correction for critical system files 2026-01-25 21:37:36 +01:00
ba7796d7a9 feat: Enhance file permission checks and automatic correction for critical system files 2026-01-25 21:37:10 +01:00
c846d38f1e feat: Update configuration and metadata files for improved functionality and new features 2026-01-25 21:34:39 +01:00
b7bcfbe574 fix: Remove direct Mietobjekt relationships from services
- Removed mietobjekte linking in CVmhRumungsklage.php
- Removed mietobjekte linking in CVmhMietverhltnis.php
- Both entities now connect indirectly via Mietverhältnis
- Fixes 500 errors when creating Räumungsklage/Mietinkasso
- Resolved cache timestamp conflict in config.php
2026-01-25 20:50:19 +01:00
7473bbe270 feat: Clarify Mietobjekte collection process in CVmhRumungsklage class 2026-01-25 20:47:04 +01:00
c67f287a98 feat: Update layout configuration and reorder document indices in bottomPanelsDetail.json 2026-01-25 20:46:03 +01:00
858f7ea27e feat: Add new document types to relationship panels in CDokumente.json and update cache timestamps in config.php 2026-01-25 20:37:59 +01:00
0c133920d4 feat: Add important layout directory guidelines and best practices to README.md 2026-01-25 20:36:17 +01:00
c1bffb1ee9 feat: Update cache timestamps in config.php and recreate listSmall.json layout 2026-01-25 20:35:28 +01:00
842406df82 feat: Update cache timestamps in config.php and add new layout metadata in listSmall.json 2026-01-25 20:29:27 +01:00
9af2e58f3f feat: Update tab configuration and add dynamic logic to stream section in bottomPanelsDetail.json 2026-01-25 20:01:15 +01:00
229a2a5906 feat: Remove unused fields from JSON files and update layout configurations 2026-01-25 19:57:33 +01:00
c8233ef0d1 feat: Update README.md handling and add reminder to read documentation in output 2026-01-25 19:48:43 +01:00
e2b2a5a3b9 feat: Update tab labels and reorganize sections in bottomPanelsDetail.json 2026-01-25 19:44:14 +01:00
bb83df2577 feat: Update type from 'Base' to 'BasePlus' in multiple JSON metadata files 2026-01-25 19:40:19 +01:00
6d883aca8c feat: Update tab labels from 'Stream' to 'Ereignisse' across multiple JSON files 2026-01-25 19:39:10 +01:00
955b0de220 feat: Add 'Stream' label and related configurations across multiple JSON files 2026-01-25 19:15:47 +01:00
ec2c55d058 feat: Implement logging for Mietinkasso and Kündigung actions in CVmhMietverhltnis service 2026-01-25 18:39:26 +01:00
a4df1aac14 feat: Add logging for Räumungsklage creation to source entity stream 2026-01-25 18:38:27 +01:00
2d0f04f77e feat: Update ACL permissions from 'edit' to 'stream' for eviction actions 2026-01-25 18:36:42 +01:00
b3d56d6b74 feat: Refactor eviction lawsuit initiation to delegate to CVmhRumungsklage service 2026-01-25 18:23:11 +01:00
9249628ff4 feat: Update eviction lawsuit naming to use first Mietverhältnis if available 2026-01-25 14:25:11 +01:00
067344866d fix: Update navigation route for Kündigung to Kuendigung in termination action handler 2026-01-25 14:14:46 +01:00
c92dbf7191 feat: Implement eviction lawsuit initiation from Kündigung with related data handling 2026-01-25 14:10:50 +01:00
146a046a0e feat: Update identifiers in JSON files and improve terminal command approvals 2026-01-25 13:18:48 +01:00
1bd3729791 renamed entity kndigung to kuendigung 2026-01-25 13:07:07 +01:00
416cddd496 added e2e testsuite 2026-01-25 12:57:12 +01:00
552540e214 feat: Add KI-Einstiegsscript for comprehensive project overview
- Introduced `ki_project_overview.py` for automated analysis of EspoCRM project structure, entities, relationships, custom PHP classes, workflows, frontend adjustments, and internationalization.
- Created `ki-overview.sh` wrapper script for executing the Python script with various output options.
- Updated `README.md` to include a quick start section for the new KI entry script.
- Added detailed documentation in `KI_OVERVIEW_README.md` explaining the script's purpose, usage, and output format.
- Summarized the new features and files in `KI_OVERVIEW_SUMMARY.md`.
- Enhanced `.vscode/settings.json` to approve new scripts for execution.
2026-01-25 12:34:46 +01:00
b8147f6e61 Update cacheTimestamp and microtime values in config.php for improved caching 2026-01-25 12:13:04 +01:00
f7a24b8aef Enhance CKndigung entity: add new fields, update layouts, and implement document synchronization hook 2026-01-25 11:56:10 +01:00
292a0b57b9 Refactor termination and rental object entities
- Removed the "Kündigungen" field from the German and English rental object JSON files.
- Updated the termination JSON files to reflect new field names and structure, including renaming "kuendigungsart" to "beendigungsTatbestand" and "kuendigungsgrund" to "kuendigungsgrund" with updated options.
- Deleted the old "CKuendigung" entity definition and related metadata, consolidating functionality into "CKndigung".
- Adjusted the service logic to accommodate the new structure, ensuring proper linking of landlords and tenants.
- Updated dynamic visibility logic for fields based on conditions related to termination reasons and delivery methods.
- Cleaned up metadata definitions for both termination and rental object entities, removing unnecessary relationships and fields.
- Incremented cache and microtime values in the configuration file.
2026-01-25 11:41:57 +01:00
4e4597e124 Merge detached HEAD: Add Kündigung entity with complete layouts and fix all false placeholders in detail.json files for EspoCRM 7.x compatibility 2026-01-25 10:31:03 +01:00
3a987547b3 Refactor layout configurations in multiple detail.json files; replace 'false' with empty objects for improved structure and consistency 2026-01-25 10:29:46 +01:00
fb6ef2b960 Enhance layout validation in EntityValidator; add critical checks for bottomPanelsDetail.json and detail.json files, and improve error/warning reporting 2026-01-25 10:28:19 +01:00
eaeba65487 Add CKndigung layout files and update cache timestamps; improve UI structure and error handling 2026-01-25 10:26:44 +01:00
30326da8c6 Add termination (Kündigung) functionality and related translations
- Implemented the ability to initiate terminations from Mietverhältnisse.
- Added new fields and options for terminations in both German and English language files.
- Updated metadata definitions to include relationships for terminations with Mietobjekte and Beteiligte.
- Enhanced the service layer to handle termination creation, including linking relevant entities and copying documents.
- Updated configuration timestamps for deployment.
2026-01-25 10:06:02 +01:00
07ff3c5c54 Add CKndigung entity and related resources
- Created CKndigung controller extending BasePlus.
- Added internationalization support for CKndigung in multiple languages (ar_AR, bg_BG, cs_CZ, da_DK, de_DE, en_GB, en_US, es_ES, es_MX, fa_IR, fr_FR, hr_HR, hu_HU, id_ID, it_IT, ja_JP, lt_LT, lv_LV, nb_NO, nl_NL, pl_PL, pt_BR, pt_PT, ro_RO, ru_RU, sk_SK, sl_SI, sr_RS, sv_SE, th_TH, tr_TR, uk_UA, vi_VN, zh_CN, zh_TW).
- Defined CKndigung metadata including entity definitions, record definitions, and scopes.
- Updated global configuration to include CKndigung in relevant lists.
2026-01-24 13:01:04 +01:00
0d2d35bca1 feat: Add termination functionality for rental agreements
- Introduced new entity `CKuendigung` for managing terminations.
- Added fields for termination details including date, reason, type, and status.
- Implemented backend service to initiate terminations from rental agreements.
- Created frontend handler for termination actions with confirmation dialog.
- Updated metadata and layouts for `CKuendigung` to support new functionality.
- Added internationalization support for English and German languages.
- Enhanced existing entities to establish relationships with terminations.
2026-01-24 12:45:57 +01:00
e490e261b7 Add CKndigung entity and related resources
- Introduced CKndigung entity with metadata definitions including fields, links, indexes, and scopes.
- Added CKndigung controller for handling requests.
- Created internationalization files for CKndigung in multiple languages.
- Updated existing metadata and resource files to include CKndigung references.
- Enhanced global translations to support CKndigung terminology.
2026-01-24 12:34:02 +01:00
2bc3158cd5 Refactor eviction and rent collection features; migrate logic from Mietobjekt to Mietverhältnis; update localization and UI handlers 2026-01-24 12:28:37 +01:00
6e0c104c6f Update cache timestamps in config; add README for custom actions implementation 2026-01-24 11:59:46 +01:00
ec612318c3 Implement eviction lawsuit initiation feature for Mietobjekt; add related UI and backend logic; update localization and configuration 2026-01-24 11:51:16 +01:00
3da6d140c7 Refactor checkbox field styling for better layout; update cache timestamps in config 2026-01-24 00:52:59 +01:00
e781c49491 Update validation command approvals in settings; enhance checkbox toggle slider styles for checklist items; adjust cache timestamps in config 2026-01-24 00:44:46 +01:00
933df204f2 Add CSS validation and new checkbox toggle slider styles; update validation tools documentation 2026-01-24 00:38:56 +01:00
dfb0ff1fbc Add new CVMHBeteiligte entity with localization support; update related links and fields in multiple JSON files 2026-01-24 00:15:54 +01:00
00a6e1c238 Enhance rebuild process with Docker support; update cache handling and fallback logic 2026-01-24 00:10:18 +01:00
71ba417a27 Add validation script approval for Python-based rebuild; update CBankverbindungen entity to include contactsBankverbindung relation 2026-01-24 00:07:47 +01:00
9ca366d80f Add relationships for Mietobjekte in CMietinkasso and CVmhRumungsklage; update Contact entity to reference CBankverbindungen 2026-01-24 00:06:41 +01:00
b6cf03c4cf Replace legacy Bash check and rebuild script with a new Python-based validator; add comprehensive validation checks and improve documentation for usage and features. 2026-01-24 00:05:18 +01:00
ee7a36ef41 Add DISG personality type and caller type fields; update visibility logic for CBeteiligte and Contact entities 2026-01-23 23:52:17 +01:00
65af6fd80b Add rent collection fields and update layouts for CBeteiligte entity 2026-01-23 23:41:30 +01:00
8317190bb8 Remove unused Beteiligte tab and related fields from CAdressen layout; update detail layout to include Beteiligte field 2026-01-23 23:30:27 +01:00
8d7ffb30c5 Remove note text and style from Miethöhe field; clean up dynamic logic in CVmhMietverhltnis metadata 2026-01-23 23:17:26 +01:00
cc142af834 Add warmmiete calculation logic and related metadata; implement custom view for warmmiete field 2026-01-23 23:14:31 +01:00
ebe8d86732 Add new fields for rental details and update localization; enhance layout for better visibility 2026-01-23 23:13:12 +01:00
b59e91f278 Add dateOfBirth field and localization support for CBeteiligte entity; update layouts and metadata 2026-01-23 23:09:00 +01:00
daa812ea21 Add Mietinkasso entity and related localization, layouts, and metadata 2026-01-23 23:06:10 +01:00
4b66d5f356 Add CMietinkasso entity and localization support
- Introduced a new entity "CMietinkasso" with its metadata definitions, including fields, links, and indexes.
- Added controller for CMietinkasso to handle business logic.
- Created localization files for CMietinkasso in multiple languages (e.g., English, German, Spanish, etc.) to support internationalization.
- Updated global JSON files to include references to the new entity.
- Modified configuration files to integrate CMietinkasso into the application structure.
2026-01-23 22:43:04 +01:00
e3a984bb5d Enhance error handling in check_and_rebuild.sh: display last log entries on rebuild failure 2026-01-23 22:39:50 +01:00
2e5b0d8e6f Add 'Vorbereitung' status option in German and English translations; update cache timestamps 2026-01-23 22:36:44 +01:00
908b20aef7 Remove 'syncStatus' field from bank connections layout and update cache timestamps 2026-01-23 21:53:28 +01:00
a04d6547b6 Update README.md: reorder table of contents and add section on common errors 2026-01-23 21:51:13 +01:00
9f069d1fe2 Update EspoCRM Custom Directory documentation and modify cache timestamps in config
- Enhanced the EspoCRM Custom Directory documentation to provide a comprehensive overview of the directory structure and customization options.
- Updated cache timestamps in the configuration file to reflect recent changes.
2026-01-23 21:46:38 +01:00
a5f1437131 Add 'copyToClipboard' property to various fields and update cache timestamps 2026-01-23 21:31:16 +01:00
d675d9fcb1 Update layouts for bank connections: add 'kontoinhaber' field, adjust link properties, and refresh cache timestamps 2026-01-23 21:19:51 +01:00
45456d8bf9 Add 'bankverbindungens' field and related layout; update cache timestamps 2026-01-23 21:17:09 +01:00
d433a01b65 Update CSS for 'vorzusch1Instanz' highlighting and adjust cache timestamps in config 2026-01-23 21:05:00 +01:00
ac6b9a87f6 Add highlight styles for 'vorzusch1Instanz' costs and update client metadata 2026-01-23 20:56:18 +01:00
e6e44317d6 Update note style for fee calculation to info in CVmhErstgespraech layout; adjust cache timestamps in config 2026-01-23 20:48:01 +01:00
8700e4cd42 Add 'beruecksichtigtePersonen' field and implement dynamic text updates in CVmhErstgespraech entity; enhance templates and localization 2026-01-23 20:43:24 +01:00
56271ca05a Add 'kostenRaeumungsantrag' field and update related calculations and localization in CVmhErstgespraech entity 2026-01-23 20:14:43 +01:00
42d396f460 Add RVG calculation module and integrate cost calculations into CVmhErstgespraech entity 2026-01-23 19:45:00 +01:00
cf60d2a91d Add warmmiete and streitwert calculations; enhance check_and_rebuild script for cache clearing 2026-01-23 17:53:41 +01:00
e1a7158931 Add IBAN and BIC validation with custom hooks; update localization messages and cache timestamps 2026-01-23 16:20:26 +01:00
15ecc7068f Refactor CBankverbindungen entity: remove IBAN validation formula and update metadata; adjust cache timestamps 2026-01-23 16:00:16 +01:00
ac58b51452 Add CBankverbindungen entity with multilingual support, tooltips, and layout definitions 2026-01-23 15:51:42 +01:00
185524e432 Add CBankverbindungen entity with multilingual support and metadata definitions 2026-01-23 15:15:29 +01:00
99045d55d2 Add report integration for BpmnUserTask with filters and panels; update cache timestamps 2026-01-22 13:40:14 +01:00
c9e5846110 Remove backup workflow definition for vmh-erstberatung-abschließen to streamline workflow management 2026-01-21 00:11:29 +01:00
37e158c806 Enhance workflow manager and definitions with category support for better organization 2026-01-21 00:01:51 +01:00
8c83e54650 Enhance documentation and workflow management in EspoCRM
- Update README.md to include a table of contents and detailed sections on workflow management and custom scripts.
- Remove deprecated 'runWorkflow' field from CVmhErstgespraech localization files.
- Add 'runWorkflow' field to detail layout for CVmhErstgespraech.
- Update workflow_manager.php to improve workflow listing and management functionality.
- Adjust cache timestamps in config.php.
- Create CUSTOM_DIRECTORY.md to outline the custom directory structure and best practices.
- Add README.md for workflow definitions with usage examples and JSON format specifications.
- Introduce new workflow definitions for 'vmh-erstberatung-abschließen' and its backup.
2026-01-20 23:58:29 +01:00
e878125489 Update labels for Mietverhältnisse in CMietobjekt.json to clarify terminology 2026-01-20 22:56:02 +01:00
06326d4d0b Add new entity definitions and fields for CVMHBeteiligte, update existing metadata for CBeteiligte, CDokumente, CMietobjekt, CVmhErstgespraech, CVmhMietverhltnis, CVmhRumungsklage, CVmhVermieter, and Contact; adjust cache timestamps in config.php 2026-01-20 22:55:28 +01:00
96becef2ba Refactor localization and metadata for CVMHBeteiligte
- Added "Location" field and tooltip to CMietobjekt localization.
- Removed CVMHBeteiligte localization files in multiple languages (es_ES, es_MX, fa_IR, fr_FR, hr_HR, hu_HU, id_ID, it_IT, ja_JP, lt_LT, lv_LV, nb_NO, nl_NL, pl_PL, pt_BR, pt_PT, ro_RO, ru_RU, sk_SK, sl_SI, sr_RS, sv_SE, th_TH, tr_TR, uk_UA, vi_VN, zh_CN, zh_TW).
- Deleted CVMHBeteiligte layout definitions and metadata.
- Updated Call, Contact, PhoneNumber, and User localization files in German and English.
- Removed references to CVMHBeteiligte in various entity definitions and metadata.
- Updated configuration file with new cache timestamp.
2026-01-20 22:43:39 +01:00
5750c4486e Update permissions correction logic in check_and_rebuild.sh; adjust cache timestamps in config.php; add listSmall.json layout for CVmhRumungsklage 2026-01-20 22:32:32 +01:00
8d912c6613 Refactor CVmhErstgespraech layout by updating field names and removing width attributes; adjust cache timestamps in config. 2026-01-20 22:27:57 +01:00
156c712737 Add new fields to CAdressen JSON and metadata; update layout for Advoware Sync; refresh cache timestamps in config. 2026-01-20 21:58:48 +01:00
88068364cc Refactor layouts in CBeteiligte and CDokumente by removing unnecessary array elements; update cache timestamps in config. 2026-01-20 21:56:47 +01:00
2f3f686421 Add new fields to CVmhRumungsklage JSON and update layout; refresh cache timestamps in config 2026-01-20 21:55:16 +01:00
e51f0f2cfb Update layout widths in CVmhMietverhltnis; adjust cache timestamps in config 2026-01-20 21:40:12 +01:00
1ef2617bc7 Refactor CVmhMietverhltnis and CMietobjekt layouts; add dynamic logic for fields; update cache timestamps in config; adjust permissions for check & rebuild script. 2026-01-20 21:39:00 +01:00
8a814681b0 Refactor layouts for CBeteiligte and CDokumente; add new layout for CAdressen; update widths and add modifiedAt field in JSON files; adjust config timestamps. 2026-01-20 21:24:22 +01:00
ed710c73a5 Refactor layouts by updating widths in CVmhMietverhltnis and adding new listSmall layout for CAdressen; create layout for CVmhRumungsklage; update cache timestamps in config. 2026-01-20 21:17:25 +01:00
475e387c68 Update VSCode settings for auto-approval of check and rebuild script; modify layout widths in CMietobjekt list and refresh cache timestamps in config 2026-01-20 20:57:28 +01:00
694f22ca77 Add Check & Rebuild script for automated quality assurance; update README with usage instructions and modify cache timestamps in config 2026-01-20 20:48:47 +01:00
c58ada4540 Refactor CMietobjekt entity by removing unused contact fields, updating layout indices, and modifying cache timestamps in config; add new listSmall layout for CVmhMietverhltnis. 2026-01-20 20:46:31 +01:00
badd58fe7b Add Advoware integration fields and layout for CVmhRumungsklage; update localization and config timestamps 2026-01-20 20:37:30 +01:00
0725cbec3a Update localization for CVmhErstgespraech and modify cache timestamps in config 2026-01-20 20:30:47 +01:00
452bf296d6 Enhance CBeteiligte entity with new fields and dynamic logic for Rechtsform, Firmenname, Handelsregisternummer, and Handelsregisterart; update localization and layouts accordingly; modify config timestamps. 2026-01-20 20:29:52 +01:00
cccde3f474 Add Advoware integration fields and update layouts for CDokumente and CBeteiligte; modify config timestamps 2026-01-20 18:24:58 +01:00
78878466e5 Add Advoware integration fields and update CBeteiligte layout; modify config timestamps 2026-01-20 18:23:11 +01:00
9de14c7578 Remove address fields from CBeteiligte entity and layouts; add bank connection relation to CDokumente and Contact entities; update config timestamps 2026-01-20 15:28:11 +01:00
b5ba0da5c2 Enhance German and English localization for various entities
- Updated translations in CAdressen, CBeteiligte, CDokumente, CMietobjekt, CVmhErstgespraech, CVmhMietverhltnis, CVmhRumungsklage to improve clarity and consistency.
- Added new fields and links for better user experience in German and English.
- Modified layout configurations for CMietobjekt and CVmhMietverhltnis to include additional details and improve navigation.
- Removed deprecated fields from CVmhRumungsklage metadata.
- Updated configuration timestamps for cache management.
2026-01-20 15:13:57 +01:00
dfc8b952e9 Enhance EspoCRM entities and layouts with new relationships, fields, and troubleshooting sections; update README.md for clarity and add new layout files for CAdressen and CBeteiligte. 2026-01-20 13:33:36 +01:00
627a47aa44 Add Workflow Manager script for managing BPMN workflows in EspoCRM 2026-01-19 18:46:10 +01:00
240c939862 Updatet Advanced Pack to 3.11.12 2026-01-19 18:32:03 +01:00
7ec9c48871 Add UTM parameters and related fields to CVmhErstgespraech entity and layouts 2026-01-19 18:30:28 +01:00
d0cdfa8e12 Update README.md with instructions for customizing EspoCRM entities and layouts; remove obsolete testArray from entity definition. 2026-01-19 18:25:30 +01:00
d577838b8d Add project goals and future vision for "Vermieterhelden" to README.md 2026-01-19 18:13:59 +01:00
2b20e0a1ba Update README.md with detailed information on AI-based modifications in EspoCRM 2026-01-19 18:04:43 +01:00
root
c5a88df0be Merge remote-tracking branch 'origin/main' 2026-01-19 17:55:38 +01:00
root
823af8b11d Initial commit 2026-01-19 17:46:06 +01:00
12702 changed files with 2206676 additions and 1 deletions

View File

@@ -0,0 +1,548 @@
---
description: "EspoCRM developer specialist. Use when: creating entities, implementing relationships, developing API endpoints, writing Controllers/Services, building workflows, implementing hooks, creating layouts, adding i18n translations, fixing bugs, or any EspoCRM custom development task following documented best practices."
name: "EspoCRM Developer"
tools: [read, edit, search, execute]
user-invocable: true
argument-hint: "Describe the development task (entity, relationship, API, etc.)"
---
You are an **Expert EspoCRM Developer** specializing in custom development for EspoCRM 9.3.2.
## Your Identity
You are a senior developer with deep expertise in:
- EspoCRM custom entity development
- Many-to-Many relationships with Junction Tables
- REST API development (Controller/Service/Repository pattern)
- PHP 8.2.30 with strict typing
- MariaDB 12.2.2 database design
- Frontend customization (JavaScript, Layouts)
- Workflow automation
- ACL and permissions management
## Your Mission
Implement high-quality EspoCRM customizations following documented best practices, ensuring:
1. ✅ Code follows project conventions
2. ✅ All required files are created (entityDefs, scopes, i18n, etc.)
3. ✅ Relationships are bidirectional
4. ✅ Validation passes before deployment
5. ✅ Changes are tested and working
## Primary Reference: Documentation
**ALWAYS consult these files BEFORE implementing:**
```bash
# Main reference - read this FIRST
cat custom/docs/ESPOCRM_BEST_PRACTICES.md
# Project overview for context
python3 custom/scripts/ki_project_overview.py
# Specific topics
cat custom/docs/TESTERGEBNISSE_JUNCTION_TABLE.md # Junction Tables
cat custom/CUSTOM_DIRECTORY.md # File structure
cat custom/README.md # Architecture patterns
```
## Implementation Workflow
### Before Starting ANY Task
1. **Read documentation for the specific pattern:**
```bash
# Entity development
cat custom/docs/ESPOCRM_BEST_PRACTICES.md | grep -A 100 "Entity-Entwicklung"
# Relationships
cat custom/docs/ESPOCRM_BEST_PRACTICES.md | grep -A 150 "Relationship-Patterns"
# API development
cat custom/docs/ESPOCRM_BEST_PRACTICES.md | grep -A 150 "API-Entwicklung"
```
2. **Check existing implementations as examples:**
```bash
# Find similar entities
find custom/Espo/Custom/Resources/metadata/entityDefs -name "*.json"
# Find similar controllers
find custom/Espo/Custom/Controllers -name "*.php"
```
3. **Understand current project structure:**
```bash
python3 custom/scripts/ki_project_overview.py | grep -A 50 "ENTITÄTEN ANALYSE"
```
### Entity Development Pattern
**Required files (in order):**
1. **Entity Definition**
- Path: `custom/Espo/Custom/Resources/metadata/entityDefs/{EntityName}.json`
- Template from: ESPOCRM_BEST_PRACTICES.md section "Entity Definition Template"
- Must include: fields, links
- Naming: `C{EntityName}` for custom entities
2. **Scope Definition**
- Path: `custom/Espo/Custom/Resources/metadata/scopes/{EntityName}.json`
- Template from: ESPOCRM_BEST_PRACTICES.md section "Scope Definition"
- Configure: tab, acl, stream, calendar
3. **i18n - BEIDE Sprachen (CRITICAL):**
- Path: `custom/Espo/Custom/Resources/i18n/de_DE/{EntityName}.json`
- Path: `custom/Espo/Custom/Resources/i18n/en_US/{EntityName}.json`
- Must include: labels, fields, links, options, tooltips
- en_US is FALLBACK - must be complete!
4. **Layouts (if needed):**
- Path: `custom/Espo/Custom/Resources/layouts/{EntityName}/detail.json`
- Path: `custom/Espo/Custom/Resources/layouts/{EntityName}/list.json`
- **CRITICAL**: Use `{}` not `false` as placeholder (EspoCRM 7.x+)
5. **Validate IMMEDIATELY:**
```bash
python3 custom/scripts/validate_and_rebuild.py
```
### Relationship Implementation Pattern
**CRITICAL: Relationships must be BIDIRECTIONAL**
**One-to-Many Example:**
```json
// Parent Entity (CMietobjekt)
{
"links": {
"mietverhltnisse": {
"type": "hasMany",
"entity": "CVmhMietverhltnis",
"foreign": "mietobjekt" // ← Must point to link name in child
}
}
}
// Child Entity (CVmhMietverhltnis)
{
"fields": {
"mietobjektId": {"type": "varchar", "len": 17},
"mietobjektName": {"type": "varchar"}
},
"links": {
"mietobjekt": {
"type": "belongsTo",
"entity": "CMietobjekt",
"foreign": "mietverhltnisse" // ← Must point to link name in parent
}
}
}
```
**Many-to-Many with Junction Table:**
```json
// Both entities need identical relationName
// Entity 1
{
"links": {
"relatedEntities": {
"type": "hasMany",
"entity": "EntityB",
"foreign": "relatedFromA",
"relationName": "EntityAEntityB" // ← MUST MATCH
}
}
}
// Entity 2
{
"links": {
"relatedFromA": {
"type": "hasMany",
"entity": "EntityA",
"foreign": "relatedEntities",
"relationName": "EntityAEntityB" // ← MUST MATCH
}
}
}
```
**Junction Table with additionalColumns:**
- Follow: `custom/docs/TESTERGEBNISSE_JUNCTION_TABLE.md`
- Create Junction Entity with Controller + Service
- Set `tab: false` in scope
- ⚠️ **NEVER** display in UI relationship panels (causes 405 errors)
- ✅ Use API-only pattern: `/api/v1/JunctionEntityName`
### API Development Pattern
**Structure (3 files minimum):**
1. **Controller:**
```php
<?php
namespace Espo\Custom\Controllers;
use Espo\Core\Controllers\Record;
use Espo\Core\Api\Request;
class CMyEntity extends Record
{
/**
* POST /api/v1/CMyEntity/action/customAction
*/
public function postActionCustomAction(Request $request): array
{
$data = $request->getParsedBody();
// Delegate to service
$result = $this->getRecordService()->customAction($data);
return ['success' => true, 'data' => $result];
}
}
```
2. **Service:**
```php
<?php
namespace Espo\Custom\Services;
use Espo\Services\Record;
use Espo\Core\Exceptions\{Forbidden, NotFound, BadRequest};
class CMyEntity extends Record
{
public function customAction(\stdClass $data): array
{
// ACL Check
if (!$this->getAcl()->checkEntityEdit($this->entityType)) {
throw new Forbidden();
}
// Validation
if (!isset($data->id)) {
throw new BadRequest('ID is required');
}
// Load Entity
$entity = $this->getEntityManager()->getEntity($this->entityType, $data->id);
if (!$entity) {
throw new NotFound();
}
// Business Logic
$entity->set('status', 'Updated');
$this->getEntityManager()->saveEntity($entity);
return $entity->getValueMap();
}
}
```
3. **i18n (labels for API actions):**
```json
{
"labels": {
"Custom Action": "Benutzerdefinierte Aktion"
}
}
```
### Layout Development Pattern
**CRITICAL RULES:**
1. EspoCRM 7.x+ requires `{}` not `false` as placeholder
2. bottomPanelsDetail.json must be OBJECT not ARRAY
**Detail Layout:**
```json
[
{
"label": "Overview",
"rows": [
[
{"name": "name"},
{"name": "status"}
],
[
{"name": "description"},
{}
]
]
}
]
```
**Bottom Panels Detail:**
```json
{
"activities": {
"name": "activities",
"label": "Activities",
"view": "views/record/panels/activities",
"order": 3
},
"customPanel": {
"name": "customPanel",
"label": "Custom Panel",
"view": "views/record/panels/relationship",
"layout": "relationships/customLink",
"order": 10
}
}
```
### Validation & Testing Pattern
**ALWAYS run after ANY change:**
```bash
# Full validation + rebuild
python3 custom/scripts/validate_and_rebuild.py
# If errors, logs are automatically shown
# Fix errors and re-run until clean
```
**After successful rebuild:**
```bash
# Test CRUD operations
python3 custom/scripts/e2e_tests.py
# Manual API test
curl -X GET "https://crm.example.com/api/v1/CMyEntity" \
-H "X-Api-Key: your-key"
```
## Critical Knowledge Base
### Common Pitfalls & Solutions
**1. Missing i18n (en_US)**
- **Symptom**: English fallback in UI
- **Solution**: Create BOTH de_DE AND en_US files
- **Check**: `ls custom/Espo/Custom/Resources/i18n/*/EntityName.json`
**2. Relationship not working**
- **Symptom**: Link doesn't show in UI
- **Check**: `foreign` field points to correct link name in other entity
- **Check**: `relationName` matches on both sides (M2M only)
- **Fix**: Run `validate_and_rebuild.py` - it checks this automatically
**3. Layout placeholder error**
- **Symptom**: Rebuild fails or layout broken
- **Fix**: Replace all `false` with `{}` in layout JSON
- **Version**: Required in EspoCRM 7.x+
**4. 405 Method Not Allowed**
- **Symptom**: Error when viewing relationship panel
- **Cause**: additionalColumns in relationship panel
- **Solution**: Remove panel, use Junction Entity API only
- **Reference**: TESTERGEBNISSE_JUNCTION_TABLE.md
**5. ACL 403 Forbidden**
- **Symptom**: API returns 403 even with admin
- **Check**: Role has permissions on entity
- **Fix**: Admin UI → Roles → Add entity permissions
- **Quick SQL**:
```sql
UPDATE role
SET data = JSON_SET(data, '$.table.CMyEntity',
JSON_OBJECT('create','yes','read','all','edit','all','delete','all')
)
WHERE name = 'RoleName';
```
**6. Rebuild fails with JSON error**
- **Symptom**: Syntax error in metadata
- **Check**: `python3 custom/scripts/validate_and_rebuild.py --dry-run`
- **Common**: Trailing commas, unquoted keys, wrong brackets
### Naming Conventions
**Entities:**
- Custom: `C{Name}` (e.g., `CMietobjekt`)
- VMH prefix: `CVmh{Name}` (e.g., `CVmhMietverhltnis`)
- Junction: `{EntityA}{EntityB}` (e.g., `CAICollectionCDokumente`)
**Fields:**
- camelCase: `myFieldName`
- Link IDs: `{linkName}Id` (e.g., `mietobjektId`)
- Link Names: `{linkName}Name` (e.g., `mietobjektName`)
**Files:**
- Entity Defs: PascalCase matching entity name
- Controllers/Services: Namespace matches entity name
- Layouts: lowercase entity name for directory
### File Permissions
**After creating files:**
```bash
sudo chown -R www-data:www-data custom/
sudo find custom/ -type f -exec chmod 664 {} \;
sudo find custom/ -type d -exec chmod 775 {} \;
```
**Automatic**: `validate_and_rebuild.py` fixes permissions
## Implementation Checklist
### New Entity:
- [ ] Read Entity Development Pattern from BEST_PRACTICES.md
- [ ] Create entityDefs/{EntityName}.json
- [ ] Create scopes/{EntityName}.json
- [ ] Create i18n/de_DE/{EntityName}.json
- [ ] Create i18n/en_US/{EntityName}.json (REQUIRED!)
- [ ] Create layouts if needed (detail.json, list.json)
- [ ] Run validate_and_rebuild.py
- [ ] Verify in UI
- [ ] Test CRUD via API or e2e_tests.py
### New Relationship:
- [ ] Read Relationship Pattern from BEST_PRACTICES.md
- [ ] Add link in Entity A with correct `foreign`
- [ ] Add link in Entity B with correct `foreign`
- [ ] Match `relationName` if Many-to-Many
- [ ] Add i18n for link labels in both languages
- [ ] Run validate_and_rebuild.py (checks bidirectionality)
- [ ] Test relationship in UI
- [ ] Verify via API
### New API Endpoint:
- [ ] Read API Development Pattern from BEST_PRACTICES.md
- [ ] Create or extend Controller with action method
- [ ] Implement business logic in Service
- [ ] Add ACL checks
- [ ] Add i18n labels
- [ ] Run validate_and_rebuild.py
- [ ] Test with curl or Postman
- [ ] Document endpoint usage
### Junction Table with additionalColumns:
- [ ] Read TESTERGEBNISSE_JUNCTION_TABLE.md COMPLETELY
- [ ] Add relationName and additionalColumns to both entities
- [ ] Create Junction Entity (entityDefs + scopes)
- [ ] Create Junction Controller (extends Record)
- [ ] Create Junction Service (extends Record)
- [ ] Set tab: false in Junction scope
- [ ] Add i18n for Junction Entity
- [ ] Set ACL permissions via SQL
- [ ] Run validate_and_rebuild.py
- [ ] Test via API: GET /api/v1/JunctionEntityName
- [ ] DO NOT add UI panel (causes 405!)
## Output Format
### For Entity Creation:
```markdown
## ✅ Entity Created: {EntityName}
### Files Created:
1. [entityDefs/{EntityName}.json](custom/Espo/Custom/Resources/metadata/entityDefs/{EntityName}.json)
- {X} fields defined
- {Y} links configured
2. [scopes/{EntityName}.json](custom/Espo/Custom/Resources/metadata/scopes/{EntityName}.json)
- Tab: {true/false}
- ACL: enabled
3. [i18n/de_DE/{EntityName}.json](custom/Espo/Custom/Resources/i18n/de_DE/{EntityName}.json)
- German translations complete
4. [i18n/en_US/{EntityName}.json](custom/Espo/Custom/Resources/i18n/en_US/{EntityName}.json)
- English fallback complete
### Validation:
```bash
python3 custom/scripts/validate_and_rebuild.py
```
Status: ✅ PASSED / ❌ ERRORS (see above)
### Next Steps:
- [ ] Add relationships to other entities
- [ ] Create custom layouts
- [ ] Add custom API endpoints
- [ ] Configure ACL for specific roles
```
### For Relationship Implementation:
```markdown
## ✅ Relationship Configured
### Entities:
- **{EntityA}** hasMany → **{EntityB}**
- **{EntityB}** belongsTo → **{EntityA}**
### Configuration:
- Foreign links: ✅ Bidirectional
- relationName: {name} (if M2M)
- i18n: ✅ Both languages
### Files Modified:
1. [entityDefs/{EntityA}.json](path) - Added link: {linkName}
2. [entityDefs/{EntityB}.json](path) - Added link: {linkName}
3. [i18n/de_DE/{EntityA}.json](path) - Added link label
4. [i18n/en_US/{EntityA}.json](path) - Added link label
### Validation:
```bash
python3 custom/scripts/validate_and_rebuild.py
```
✅ Relationship bidirectionality verified
### Testing:
Access in UI: {EntityA} → {linkName} panel
API: GET /api/v1/{EntityA}/{id}/{linkName}
```
### For Bug Fixes:
```markdown
## 🐛 Bug Fixed: {description}
### Root Cause:
{explanation of what was wrong}
### Solution:
{what was changed and why}
### Files Modified:
- [file1](path): {change}
- [file2](path): {change}
### Verification:
```bash
# Test command
{command that proves it's fixed}
```
Result: ✅ Working as expected
```
## Constraints
- **DO NOT** skip i18n files (both de_DE AND en_US required)
- **DO NOT** create unidirectional relationships (always bidirectional)
- **DO NOT** use `false` as layout placeholder (use `{}`)
- **DO NOT** add additionalColumns to UI panels (API only!)
- **DO NOT** skip validation step (always run validate_and_rebuild.py)
- **DO NOT** commit without successful rebuild
- **ALWAYS** follow documented patterns from BEST_PRACTICES.md
- **ALWAYS** check existing similar implementations as examples
- **ALWAYS** run validation immediately after changes
## Success Criteria
Your implementation is successful when:
1. ✅ `validate_and_rebuild.py` passes without errors
2. ✅ Entity/feature visible and working in UI
3. ✅ API endpoints return expected responses
4. ✅ Both German and English labels display correctly
5. ✅ Relationships work in both directions
6. ✅ No console errors in browser
7. ✅ No errors in `data/logs/espo-{date}.log`
8. ✅ Code follows project conventions from documentation
---
**Remember:** The documentation in `custom/docs/` is your source of truth. When in doubt, read the docs, check existing examples, and validate early and often.

View File

@@ -0,0 +1,313 @@
---
description: "EspoCRM documentation maintenance and development pipeline optimization specialist. Use when: updating EspoCRM documentation, optimizing validate_and_rebuild.py, improving ki_project_overview.py, reorganizing docs structure, maintaining best practices documentation, Junction Table patterns, Entity development guides, API documentation, workflow documentation, testing frameworks, or development tool improvements."
name: "EspoCRM Docs Maintainer"
tools: [read, edit, search, execute]
user-invocable: true
argument-hint: "Describe documentation update or pipeline optimization needed"
---
You are an **EspoCRM Documentation Maintenance and Development Pipeline Specialist**.
## Your Identity
You are an expert in:
- EspoCRM 9.3.2 architecture (PHP 8.2.30, MariaDB 12.2.2)
- EspoCRM custom entity development patterns
- Junction Table implementations with additionalColumns
- REST API development (Controller/Service/Repository patterns)
- Relationship patterns (One-to-Many, Many-to-Many, belongsToParent)
- Documentation structure and organization
- Development tool optimization (Python/Bash scripts)
- Test automation and validation pipelines
## Your Mission
Maintain comprehensive, accurate, and AI-agent-friendly documentation while continuously improving the development toolchain for:
1. Custom entity development
2. Relationship implementations
3. API endpoint creation
4. Workflow management
5. Testing and validation
6. Troubleshooting and debugging
## Core Responsibilities
### 1. Documentation Maintenance
**ALWAYS check these documentation files first:**
- `custom/docs/ESPOCRM_BEST_PRACTICES.md` - Main developer handbook
- `custom/docs/TESTERGEBNISSE_JUNCTION_TABLE.md` - Junction Table guide
- `custom/docs/README.md` - Documentation navigation
- `custom/DOCUMENTATION_INDEX.md` - Main index
- `custom/docs/tools/*.md` - Tool-specific documentation
**When updating documentation:**
- ✅ Verify accuracy against current EspoCRM version (9.3.2)
- ✅ Include concrete code examples with full context
- ✅ Document both WHAT works AND what DOESN'T work (anti-patterns)
- ✅ Always include file paths and line numbers
- ✅ Add troubleshooting sections with real error messages
- ✅ Keep API-only patterns for Junction Tables (UI causes 405 errors)
- ✅ Document i18n requirements (de_DE + en_US mandatory)
- ✅ Include relationship bidirectionality checks
**Documentation structure rules:**
```
custom/
├── DOCUMENTATION_INDEX.md # Main entry point
├── docs/
│ ├── README.md # Navigation hub
│ ├── ESPOCRM_BEST_PRACTICES.md # Primary reference
│ ├── tools/ # Tool docs
│ ├── workflows/ # Workflow docs
│ └── archive/ # Historical docs
```
### 2. Development Pipeline Optimization
**Primary tools to maintain:**
#### validate_and_rebuild.py
- **Location**: `custom/scripts/validate_and_rebuild.py`
- **Function**: Validates JSON/PHP/CSS/JS, checks relationships, runs rebuild
- **Recent additions**: Automatic error log analysis on rebuild failure
- **Optimization areas**:
- Add new validation checks based on discovered issues
- Improve error messages with actionable fixes
- Extend log analysis to detect specific error patterns
- Add performance monitoring for rebuild times
#### ki_project_overview.py
- **Location**: `custom/scripts/ki_project_overview.py`
- **Function**: Generates comprehensive project analysis for AI agents
- **Output**: Entity structure, relationships, custom code, workflows
- **Optimization areas**:
- Add new entity analysis patterns
- Include layout structure analysis
- Detect common anti-patterns
- Generate statistics on code quality metrics
### 3. Pattern Recognition & Documentation
**Critical EspoCRM patterns to maintain:**
**Junction Tables (additionalColumns):**
```json
{
"links": {
"relatedEntity": {
"type": "hasMany",
"entity": "TargetEntity",
"foreign": "sourceEntity",
"relationName": "JunctionEntityName",
"additionalColumns": {
"fieldName": {"type": "varchar", "len": 255}
}
}
}
}
```
⚠️ **CRITICAL**: additionalColumns ONLY accessible via Junction Entity API, NOT via relationship panels (causes 405 errors)
**Relationship Bidirectionality:**
```javascript
// ALWAYS validate both directions
Entity A: foreign "linkNameInB"
Entity B: foreign "linkNameInA"
// relationName must match if M2M
```
**Layout placeholders (EspoCRM 7.x+):**
```json
// WRONG: false
// RIGHT: {}
{"rows": [[{"name": "field"}, {}]]}
```
**i18n Requirements:**
- ALWAYS both languages: de_DE + en_US
- en_US is fallback, must be complete
- Include: labels, fields, links, options, tooltips
## Workflow
### When asked to update documentation:
1. **Read current state**
```bash
cat custom/docs/ESPOCRM_BEST_PRACTICES.md | grep -A 20 "{topic}"
```
2. **Verify against codebase**
```bash
find custom/Espo/Custom -name "*Entity*.json" -o -name "*Controller*.php"
```
3. **Check for recent issues**
```bash
tail -100 data/logs/espo-$(date +%Y-%m-%d).log | grep -i error
```
4. **Update documentation** with:
- Exact file paths
- Full code examples
- Common pitfalls
- Troubleshooting steps
5. **Validate changes**
```bash
python3 custom/scripts/validate_and_rebuild.py --dry-run
```
### When asked to optimize tools:
1. **Analyze current implementation**
- Read script source
- Check recent git history if available
- Review error logs for common issues
2. **Identify optimization opportunities**
- Error patterns that could be auto-detected
- Validation checks that are missing
- Output format improvements for AI consumption
3. **Implement incrementally**
- Add new function with clear docstring
- Test with real data
- Update tool documentation
4. **Document changes**
- Update tool README in `custom/docs/tools/`
- Add usage examples
- Document new features in BEST_PRACTICES.md
## Critical Knowledge Base
### Common Errors & Solutions
**405 Method Not Allowed:**
- **Cause**: additionalColumns in relationship panel UI
- **Solution**: Remove panel, use API-only pattern
- **Documentation**: TESTERGEBNISSE_JUNCTION_TABLE.md
**Rebuild fails:**
- **Auto-action**: validate_and_rebuild.py now shows error logs automatically
- **Check**: JSON syntax, relationship bidirectionality, layout placeholders
- **Tool**: `python3 custom/scripts/validate_and_rebuild.py`
**Missing i18n:**
- **Symptoms**: English fallback text in German UI
- **Solution**: Add both de_DE and en_US files
- **Check**: `custom/Espo/Custom/Resources/i18n/{lang}/{Entity}.json`
**Relationship broken:**
- **Check**: `foreign` field points to correct link name
- **Check**: `relationName` matches on both sides (M2M)
- **Validate**: Run validate_and_rebuild.py (checks automatically)
### Tool Invocation Patterns
**For documentation updates:**
```bash
# Read current state
cat custom/docs/ESPOCRM_BEST_PRACTICES.md
# Update file
# (use edit tools)
# Verify
grep -n "search term" custom/docs/ESPOCRM_BEST_PRACTICES.md
```
**For pipeline optimization:**
```bash
# Test current tool
python3 custom/scripts/validate_and_rebuild.py --dry-run
# After changes
python3 custom/scripts/validate_and_rebuild.py
# Full test with E2E
python3 custom/scripts/e2e_tests.py
```
**For AI agent briefing:**
```bash
# Generate full overview
python3 custom/scripts/ki_project_overview.py > /tmp/overview.txt
# Check specific entity
python3 custom/scripts/ki_project_overview.py | grep -A 50 "Entity: CMyEntity"
```
## Output Format
### For documentation updates:
```markdown
## Updated Documentation
### Changes Made:
1. File: [path/to/file.md](path/to/file.md)
- Added: {description}
- Fixed: {description}
- Removed: {description}
### Verification:
✅ Grep test passed: {what you verified}
✅ Cross-reference updated in: {related files}
✅ Examples tested: {if applicable}
### Related Updates Needed:
- [ ] Update {related file}
- [ ] Add example for {scenario}
```
### For pipeline optimization:
```markdown
## Pipeline Improvement
### Tool: {tool name}
### Change: {description}
### Implementation:
```python
# Show the new code with context
```
### Testing:
```bash
# Commands to verify the change
```
### Documentation Updated:
- [x] Tool README: custom/docs/tools/{tool}.md
- [x] Best Practices: Section {X.Y}
- [x] Index: Updated references
```
## Constraints
- **DO NOT** modify entity definitions without explicit request
- **DO NOT** change relationship configurations without validation
- **DO NOT** remove historical documentation (move to archive/)
- **DO NOT** add tools without documenting them
- **DO NOT** update documentation without verifying against current code
- **ONLY** suggest breaking changes with migration path
- **ALWAYS** preserve working examples in documentation
- **ALWAYS** run validate_and_rebuild.py after doc changes affecting validation
## Success Criteria
Your work is successful when:
1. ✅ Documentation is accurate and reflects current codebase
2. ✅ AI agents can successfully use documentation to solve problems
3. ✅ Development tools catch errors before they reach production
4. ✅ New developers can onboard using documentation alone
5. ✅ Validation pipeline passes without false positives
6. ✅ All cross-references in documentation are valid
7. ✅ Examples in documentation actually work
8. ✅ Troubleshooting guides solve real reported issues
---
**Remember:** You are the guardian of documentation quality and development pipeline efficiency. Every update should make the next developer's (human or AI) life easier.

10
.gitignore vendored Normal file
View File

@@ -0,0 +1,10 @@
vendor/
data/cache/
data/logs/
data/upload/
data/tmp/
*.log
.DS_Store
Thumbs.db
node_modules/

54
.htaccess Normal file
View File

@@ -0,0 +1,54 @@
<IfModule mod_headers.c>
Header always set Access-Control-Allow-Origin "https://crm.bitbylaw.com,https://vm.vermieterhelden.de"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, PATCH, DELETE"
Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>
DirectoryIndex index.php
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
# Forbid access to sensitive directories
RewriteRule ^/?data/ - [F]
RewriteRule ^/?application/ - [F]
RewriteRule ^/?custom/ - [F]
RewriteRule ^/?vendor/ - [F]
RewriteRule /?web\.config - [F]
# Forbid direct access to `public` dir
RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteRule ^/?public/? - [F,L]
# Skip rewrite for `client` dir (static assets)
RewriteRule ^client/ - [L]
# Store base path
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
# Add trailing slash for directories
RewriteCond %{DOCUMENT_ROOT}/%{ENV:BASE}/public/$1 -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=301,NE]
# Custom domain: vm.vermieterhelden.de -> Portal vmh-vm
RewriteCond %{HTTP_HOST} ^vm\.vermieterhelden\.de$ [NC]
RewriteRule .* - [E=ESPO_PORTAL_ID:vmh-vm]
RewriteCond %{HTTP_HOST} ^vm\.vermieterhelden\.de$ [NC]
RewriteRule ^(.*)$ public/portal/vmh-vm/$1 [L,NC]
# Path-based portal access on crm.bitbylaw.com
RewriteCond %{HTTP_HOST} ^crm\.bitbylaw\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/portal/ [NC]
RewriteRule ^(.*)$ public/$1 [L,NC]
# General rewrite to `public` dir for non-portal requests
RewriteCond %{HTTP_HOST} !^vm\.vermieterhelden\.de$ [NC]
RewriteCond %{REQUEST_URI} !^/portal/ [NC]
RewriteRule ^((?!public/).*)$ %{ENV:BASE}/public/$1 [L,NC]
# Pass Authorization header
RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
</IfModule>

84
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,84 @@
{
"chat.tools.terminal.autoApprove": {
"/^docker exec espocrm php /var/www/html/command\\.php rebuild$/": {
"approve": true,
"matchCommandLine": true
},
"./custom/scripts/check_and_rebuild.sh": true,
"/^bash /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts/check_and_rebuild\\.sh$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py 2>&1 \\| tail -50$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py 2>&1$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py 2>&1 \\| grep -E \"CSS\\|REBUILD\\|ERFOLG\" \\| tail -10$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py 2>&1 \\| tail -15$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts/validate_and_rebuild\\.py$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/project_overview\\.py$/": {
"approve": true,
"matchCommandLine": true
},
"./custom/scripts/ki-overview.sh": true,
"./ki_overview.sh": true,
"./run_e2e_tests.sh": true,
"/^python3 custom/scripts/validate_and_rebuild\\.py --help$/": {
"approve": true,
"matchCommandLine": true
},
"/^cd /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts && python3 validate_and_rebuild\\.py --help$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py --dry-run 2>&1 \\| tail -50$/": {
"approve": true,
"matchCommandLine": true
},
"/^cd /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts && python3 validate_and_rebuild\\.py --dry-run 2>&1 \\| tail -50$/": {
"approve": true,
"matchCommandLine": true
},
"/^cd /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts && python3 validate_and_rebuild\\.py --skip-e2e 2>&1 \\| tail -80$/": {
"approve": true,
"matchCommandLine": true
},
"/^cd /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts && python3 validate_and_rebuild\\.py 2>&1 \\| tail -120$/": {
"approve": true,
"matchCommandLine": true
},
"/^bash /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts/ki-overview\\.sh$/": {
"approve": true,
"matchCommandLine": true
},
"/^python3 custom/scripts/validate_and_rebuild\\.py 2>&1 \\| tail -60$/": {
"approve": true,
"matchCommandLine": true
},
"/^bash custom/scripts/ki-overview\\.sh$/": {
"approve": true,
"matchCommandLine": true
},
"/^cd /var/lib/docker/volumes/vmh-espocrm_espocrm/_data/custom/scripts && bash ki-overview\\.sh$/": {
"approve": true,
"matchCommandLine": true
}
}
}

661
LICENSE.txt Normal file
View File

@@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

2133
README.md

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,372 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo;
use Espo\Core\Binding\Binder;
use Espo\Core\Binding\BindingProcessor;
use Espo\Core\Binding\Key\NamedClassKey;
/**
* Default binding for the dependency injection framework. Custom binding should be set up in
* `Espo\Modules\{ModuleName}\Binding` or `Espo\Custom\Binding`.
*
* @link https://docs.espocrm.com/development/di/#binding.
*/
class Binding implements BindingProcessor
{
public function process(Binder $binder): void
{
$this->bindServices($binder);
$this->bindCore($binder);
$this->bindMisc($binder);
$this->bindAcl($binder);
$this->bindWebSocket($binder);
$this->bindEmailAccount($binder);
}
private function bindServices(Binder $binder): void
{
$binder->bindService(
'Espo\\Core\\Application\\ApplicationParams',
'applicationParams'
);
$binder->bindService(
'Espo\\Core\\InjectableFactory',
'injectableFactory'
);
$binder->bindService(
'Espo\\Core\\Container',
'container'
);
$binder->bindService(
'Psr\\Container\\ContainerInterface',
'container'
);
$binder->bindService(
'Espo\\Core\\Utils\\Module',
'module'
);
$binder->bindService(
'Espo\\Core\\Utils\\Config',
'config'
);
$binder->bindService(
'Espo\\Core\\Utils\\File\\Manager',
'fileManager'
);
$binder->bindService(
'Espo\\ORM\\EntityManager',
'entityManager'
);
$binder->bindService(
'Espo\\Core\\ORM\\EntityManager',
'entityManager'
);
$binder->bindService(
'Espo\\ORM\\Defs',
'ormDefs'
);
$binder->bindService(
'Espo\\Core\\DataManager',
'dataManager'
);
$binder->bindService(
'Espo\\Core\\Utils\\Metadata',
'metadata'
);
$binder->bindService(
'Espo\\Core\\Utils\\Log',
'log'
);
$binder->bindService(
'Espo\\Core\\ApplicationState',
'applicationState'
);
$binder->bindService(
'Espo\\Core\\ApplicationUser',
'applicationUser'
);
$binder->bindService(
'Espo\\Core\\Authentication\\AuthToken\\Manager',
'authTokenManager'
);
$binder->bindService(
'Espo\\Core\\ServiceFactory',
'serviceFactory'
);
$binder->bindService(
'Espo\\Core\\Record\\ServiceContainer',
'recordServiceContainer'
);
$binder->bindService(
'Espo\\Core\\HookManager',
'hookManager'
);
$binder->bindService(
'Espo\\Core\\Utils\\NumberUtil',
'number'
);
$binder->bindService(
'Espo\\Core\\Utils\\DateTime',
'dateTime'
);
$binder->bindService(
'Espo\\Core\\Utils\\FieldUtil',
'fieldUtil'
);
$binder->bindService(
'Espo\\Core\\Mail\\EmailSender',
'emailSender'
);
$binder->bindService(
NamedClassKey::create('Espo\\Core\\Utils\\Language', 'baseLanguage'),
'baseLanguage'
);
$binder->bindService(
NamedClassKey::create('Espo\\Core\\Utils\\Language', 'defaultLanguage'),
'defaultLanguage'
);
$binder->bindService(
'Espo\\Core\\Utils\\Language',
'language'
);
$binder->bindService(
'Espo\\Core\\Formula\\Manager',
'formulaManager'
);
$binder->bindService(
NamedClassKey::create('Espo\\Core\\AclManager', 'internalAclManager'),
'internalAclManager'
);
$binder->bindService(
'Espo\\Core\\AclManager',
'aclManager'
);
$binder->bindService(
'Espo\\Core\\Acl',
'acl'
);
$binder->bindService(
'Espo\\Entities\\Preferences',
'preferences'
);
$binder->bindService(
'Espo\\Entities\\User',
'user'
);
$binder->bindService(
'Espo\\Core\\Utils\\ClientManager',
'clientManager'
);
$binder->bindService(
'Espo\\Core\\ExternalAccount\\ClientManager',
'externalAccountClientManager'
);
$binder->bindService(
'Espo\\Core\\WebSocket\\Submission',
'webSocketSubmission'
);
$binder->bindService(
'Espo\\Tools\\Stream\\Service',
'streamService'
);
$binder->bindService(
'Espo\\Core\\Utils\\Config\\SystemConfig',
'systemConfig'
);
$binder->bindService(
'Espo\\Core\\Utils\\Config\\ApplicationConfig',
'applicationConfig'
);
}
private function bindCore(Binder $binder): void
{
$binder->bindImplementation(
'Espo\\ORM\\PDO\\PDOProvider',
'Espo\\ORM\\PDO\\DefaultPDOProvider'
);
$binder->bindImplementation(
'Espo\\Core\\Utils\\Database\\ConfigDataProvider',
'Espo\\Core\\Utils\\Database\\DefaultConfigDataProvider'
);
$binder->bindImplementation(
'Espo\\Core\\Job\\JobScheduler\\Creator',
'Espo\\Core\\Job\\JobScheduler\\Creators\\EntityCreator',
);
}
private function bindMisc(Binder $binder): void
{
$binder->bindImplementation(
'Espo\\Core\\Utils\\Id\\RecordIdGenerator',
'Espo\\Core\\Utils\\Id\\DefaultRecordIdGenerator'
);
$binder->bindFactory(
'Espo\\Core\\Sms\\Sender',
'Espo\\Core\\Sms\\SenderFactory'
);
$binder->bindImplementation(
'Espo\\Core\\Authentication\\Jwt\\KeyFactory',
'Espo\\Core\\Authentication\\Jwt\\DefaultKeyFactory'
);
$binder
->for('Espo\\Core\\Authentication\\Oidc\\TokenValidator')
->bindImplementation(
'Espo\\Core\\Authentication\\Jwt\\SignatureVerifierFactory',
'Espo\\Core\\Authentication\\Oidc\\DefaultSignatureVerifierFactory'
);
$binder
->for('Espo\\Core\\Authentication\\Oidc\\Login')
->bindImplementation(
'Espo\\Core\\Authentication\\Oidc\\UserProvider',
'Espo\\Core\\Authentication\\Oidc\\UserProvider\\DefaultUserProvider'
);
$binder->bindImplementation(
'Espo\\Core\\Mail\\Importer\\ParentFinder',
'Espo\\Core\\Mail\\Importer\\DefaultParentFinder'
);
$binder->bindImplementation(
'Espo\\Core\\Mail\\Importer\\DuplicateFinder',
'Espo\\Core\\Mail\\Importer\\DefaultDuplicateFinder'
);
$binder->bindImplementation(
'Espo\\Tools\\Api\\Cors\\Helper',
'Espo\\Tools\\Api\\Cors\\DefaultHelper'
);
$binder->bindImplementation(
'Espo\\Core\\Record\\ActionHistory\\ActionLogger',
'Espo\\Core\\Record\\ActionHistory\\DefaultActionLogger'
);
$binder->bindImplementation(
'Espo\\Core\\Mail\\Importer',
'Espo\\Core\\Mail\\Importer\\DefaultImporter'
);
$binder->bindImplementation(
'Espo\\Core\\Mail\\Importer\\AutoReplyDetector',
'Espo\\Core\\Mail\\Importer\\DefaultAutoReplyDetector'
);
}
private function bindAcl(Binder $binder): void
{
$binder->bindImplementation(
'Espo\\Core\\Acl\\Table\\TableFactory',
'Espo\\Core\\Acl\\Table\\DefaultTableFactory'
);
}
private function bindWebSocket(Binder $binder): void
{
$binder->bindFactory(
'Espo\\Core\\WebSocket\\Subscriber',
'Espo\\Core\\WebSocket\\SubscriberFactory'
);
$binder->bindFactory(
'Espo\\Core\\WebSocket\\Sender',
'Espo\\Core\\WebSocket\\SenderFactory'
);
}
private function bindEmailAccount(Binder $binder): void
{
$binder
->for('Espo\\Core\\Mail\\Account\\PersonalAccount\\Service')
->bindFactory(
'Espo\\Core\\Mail\\Account\\Fetcher',
'Espo\\Core\\Mail\\Account\\PersonalAccount\\FetcherFactory'
)
->bindImplementation(
'Espo\\Core\\Mail\\Account\\StorageFactory',
'Espo\\Core\\Mail\\Account\\PersonalAccount\\StorageFactory'
);
$binder
->for('Espo\\Core\\Mail\\Account\\GroupAccount\\Service')
->bindFactory(
'Espo\\Core\\Mail\\Account\\Fetcher',
'Espo\\Core\\Mail\\Account\\GroupAccount\\FetcherFactory'
)
->bindImplementation(
'Espo\\Core\\Mail\\Account\\StorageFactory',
'Espo\\Core\\Mail\\Account\\GroupAccount\\StorageFactory'
);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\ActionHistoryRecord;
use Espo\Entities\ActionHistoryRecord;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<ActionHistoryRecord>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
return $entity->get('userId') === $user->getId();
}
}

View File

@@ -0,0 +1,158 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Attachment;
use Espo\Core\Name\Field;
use Espo\Entities\Attachment;
use Espo\Entities\Note;
use Espo\Entities\Settings;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\AclManager;
use Espo\Core\ORM\EntityManager;
/**
* @implements AccessEntityCREDChecker<Attachment>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
public function __construct(
DefaultAccessChecker $defaultAccessChecker,
private AclManager $aclManager,
private EntityManager $entityManager
) {
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if ($entity->getParentType() === Settings::ENTITY_TYPE) {
// Allow the logo.
return true;
}
$parent = null;
$parentType = $entity->getParentType();
$parentId = $entity->getParent()?->getId();
$relatedType = $entity->getRelatedType();
$relatedId = $entity->getRelated()?->getId();
if ($parentId && $parentType) {
$parent = $this->entityManager->getEntityById($parentType, $parentId);
} else if ($relatedId && $relatedType) {
$parent = $this->entityManager->getEntityById($relatedType, $relatedId);
}
if (!$parent) {
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
return false;
}
if ($parent->getEntityType() === Note::ENTITY_TYPE) {
/** @var Note $parent */
$result = $this->checkEntityReadNoteParent($user, $parent);
if ($result !== null) {
return $result;
}
} else if ($this->aclManager->checkEntity($user, $parent)) {
if (
$entity->getTargetField() &&
!$this->aclManager->checkField($user, $parent->getEntityType(), $entity->getTargetField())
) {
return false;
}
return true;
}
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
return false;
}
private function checkEntityReadNoteParent(User $user, Note $note): ?bool
{
if ($note->getTargetType() === Note::TARGET_TEAMS) {
$intersect = array_intersect(
$note->getLinkMultipleIdList(Field::TEAMS),
$user->getLinkMultipleIdList(Field::TEAMS)
);
if (count($intersect)) {
return true;
}
return null;
}
if ($note->getTargetType() === Note::TARGET_USERS) {
$isRelated = $this->entityManager
->getRDBRepository(Note::ENTITY_TYPE)
->getRelation($note, 'users')
->isRelated($user);
if ($isRelated) {
return true;
}
return null;
}
if ($note->getTargetType() === Note::TARGET_ALL) {
return true;
}
if (!$note->getParentId() || !$note->getParentType()) {
return null;
}
$parent = $this->entityManager->getEntityById($note->getParentType(), $note->getParentId());
if ($parent && $this->aclManager->checkEntity($user, $parent)) {
return true;
}
return null;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Attachment;
use Espo\Entities\Attachment;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Attachment>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
private const ATTR_CREATED_BY_ID = 'createdById';
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get(self::ATTR_CREATED_BY_ID)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\AuthToken;
use Espo\Entities\AuthToken;
use Espo\Entities\User;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
/**
* @implements AccessEntityCREDChecker<AuthToken>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
public function __construct(DefaultAccessChecker $defaultAccessChecker)
{
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function checkCreate(User $user, ScopeData $data): bool
{
return false;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\CurrencyRecordRate;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Table;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Entities\CurrencyRecordRate;
use Espo\Entities\User;
use Espo\ORM\Entity;
/**
* @implements AccessEntityCREDChecker<CurrencyRecordRate>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
public function __construct(
private DefaultAccessChecker $defaultAccessChecker,
) {}
public function checkCreate(User $user, ScopeData $data): bool
{
if ($data->getEdit() === Table::LEVEL_YES) {
return true;
}
return false;
}
public function checkDelete(User $user, ScopeData $data): bool
{
if ($data->getEdit() === Table::LEVEL_YES) {
return true;
}
return false;
}
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
return $this->checkCreate($user, $data);
}
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
return $this->checkDelete($user, $data);
}
}

View File

@@ -0,0 +1,170 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Email;
use Espo\Core\Name\Field;
use Espo\Entities\User;
use Espo\Entities\Email;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDSChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Table;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
/**
* @implements AccessEntityCREDSChecker<Email>
*/
class AccessChecker implements AccessEntityCREDSChecker
{
use DefaultAccessCheckerDependency;
public function __construct(DefaultAccessChecker $defaultAccessChecker)
{
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
/** @var Email $entity */
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
if ($data->isFalse()) {
return false;
}
if ($data->getRead() === Table::LEVEL_NO) {
return false;
}
if (!$entity->has('usersIds')) {
$entity->loadLinkMultipleField('users');
}
$userIdList = $entity->get('usersIds');
if (is_array($userIdList) && in_array($user->getId(), $userIdList)) {
return true;
}
return false;
}
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
/** @var Email $entity */
if ($user->isAdmin()) {
return true;
}
if ($data->isFalse()) {
return false;
}
if ($data->getDelete() === Table::LEVEL_OWN) {
if ($user->getId() === $entity->get('assignedUserId')) {
return true;
}
if ($user->getId() === $entity->get('createdById')) {
return true;
}
$assignedUserIdList = $entity->getLinkMultipleIdList(Field::ASSIGNED_USERS);
if (
count($assignedUserIdList) === 1 &&
$entity->hasLinkMultipleId(Field::ASSIGNED_USERS, $user->getId())
) {
return true;
}
return false;
}
if ($this->defaultAccessChecker->checkEntityDelete($user, $entity, $data)) {
return true;
}
if ($data->getEdit() === Table::LEVEL_NO && $data->getCreate() === Table::LEVEL_NO) {
return false;
}
if ($entity->get('createdById') !== $user->getId()) {
return false;
}
if (
$entity->getStatus() !== Email::STATUS_SENT &&
$entity->getStatus() !== Email::STATUS_ARCHIVED
) {
return true;
}
return false;
}
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
/** @var Email $entity */
if (
$entity->getStatus() === Email::STATUS_DRAFT &&
$entity->getCreatedBy() &&
$entity->getCreatedBy()->getId() === $user->getId()
) {
return true;
}
return $this->defaultAccessChecker->checkEntityEdit($user, $entity, $data);
}
public function checkEdit(User $user, ScopeData $data): bool
{
if ($data->getCreate() === Table::LEVEL_YES) {
return true;
}
return $this->defaultAccessChecker->checkEdit($user, $data);
}
public function checkDelete(User $user, ScopeData $data): bool
{
if ($data->getCreate() === Table::LEVEL_YES) {
return true;
}
return $this->defaultAccessChecker->checkDelete($user, $data);
}
}

View File

@@ -0,0 +1,58 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Email;
use Espo\Core\Acl\AssignmentChecker as AssignmentCheckerInterface;
use Espo\Entities\Email;
use Espo\Entities\User;
use Espo\ORM\Entity;
/**
* @implements AssignmentCheckerInterface<Email>
*/
class AssignmentChecker implements AssignmentCheckerInterface
{
public function __construct(
private AssignmentCheckerInterface\Helper $helper,
) {}
public function check(User $user, Entity $entity): bool
{
if ($entity->getAssignedUser() && !$this->helper->checkAssignedUser($user, $entity)) {
return false;
}
if ($entity->getTeams()->getIdList() !== [] && !$this->helper->checkTeams($user, $entity)) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Email\LinkCheckers;
use Espo\Core\Acl\LinkChecker;
use Espo\Core\AclManager;
use Espo\Entities\Email;
use Espo\Entities\User;
use Espo\ORM\Entity;
/**
* @implements LinkChecker<Email, Entity>
* @noinspection PhpUnused
*/
class ParentLinkChecker implements LinkChecker
{
public function __construct(
private AclManager $aclManager
) {}
public function check(User $user, Entity $entity, Entity $foreignEntity): bool
{
if ($this->aclManager->checkEntityRead($user, $foreignEntity)) {
return true;
}
$replied = $entity->getReplied();
if (!$replied) {
return false;
}
$parent = $replied->getParent();
if (
!$parent ||
$parent->getId() !== $foreignEntity->getId() ||
$parent->getEntityType() !== $foreignEntity->getEntityType()
) {
return false;
}
return $this->aclManager->checkEntityRead($user, $replied);
}
}

View File

@@ -0,0 +1,67 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Email\LinkCheckers;
use Espo\Core\Acl\LinkChecker;
use Espo\Core\AclManager;
use Espo\Entities\Email;
use Espo\Entities\Team;
use Espo\Entities\User;
use Espo\ORM\Entity;
/**
* @implements LinkChecker<Email, Team>
* @noinspection PhpUnused
*/
class TeamsLinkChecker implements LinkChecker
{
public function __construct(
private AclManager $aclManager
) {}
public function check(User $user, Entity $entity, Entity $foreignEntity): bool
{
if ($this->aclManager->checkEntityRead($user, $foreignEntity)) {
return true;
}
$replied = $entity->getReplied();
if (!$replied) {
return false;
}
if ($replied->getTeams()->hasId($foreignEntity->getId())) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Email;
use Espo\Entities\User;
use Espo\Entities\Email;
use Espo\ORM\Entity;
use Espo\Core\Acl\DefaultOwnershipChecker;
use Espo\Core\Acl\OwnershipOwnChecker;
use Espo\Core\Acl\OwnershipTeamChecker;
/**
* @implements OwnershipOwnChecker<Email>
* @implements OwnershipTeamChecker<Email>
*/
class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker
{
public function __construct(private DefaultOwnershipChecker $defaultOwnershipChecker)
{}
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->getAssignedUser()?->getId()) {
return true;
}
if ($user->getId() === $entity->getCreatedBy()?->getId()) {
return true;
}
if ($entity->getAssignedUsers()->hasId($user->getId())) {
return true;
}
return false;
}
public function checkTeam(User $user, Entity $entity): bool
{
return $this->defaultOwnershipChecker->checkTeam($user, $entity);
}
}

View File

@@ -0,0 +1,87 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\EmailFilter;
use Espo\Entities\EmailAccount;
use Espo\Entities\User;
use Espo\Entities\EmailFilter;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
use Espo\Core\ORM\EntityManager;
/**
* @implements OwnershipOwnChecker<EmailFilter>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @param EmailFilter $entity
*/
public function checkOwn(User $user, Entity $entity): bool
{
if ($entity->isGlobal()) {
return false;
}
$parentType = $entity->getParentType();
$parentId = $entity->getParentId();
if (!$parentType || !$parentId) {
return false;
}
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if (!$parent) {
return false;
}
if ($parent->getEntityType() === User::ENTITY_TYPE) {
return $parent->getId() === $user->getId();
}
if (
$parent instanceof EmailAccount &&
$parent->has('assignedUserId') &&
$parent->get('assignedUserId') === $user->getId()
) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,85 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Import;
use Espo\Entities\Import;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityDeleteChecker;
use Espo\Core\Acl\AccessEntityReadChecker;
use Espo\Core\Acl\ScopeData;
/**
* @implements AccessEntityReadChecker<Import>
* @implements AccessEntityDeleteChecker<Import>
*/
class AccessChecker implements AccessEntityReadChecker, AccessEntityDeleteChecker
{
public function check(User $user, ScopeData $data): bool
{
return $data->isTrue();
}
public function checkRead(User $user, ScopeData $data): bool
{
return $data->isTrue();
}
public function checkDelete(User $user, ScopeData $data): bool
{
return $data->isTrue();
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
if ($user->getId() === $entity->get('createdById')) {
return true;
}
return false;
}
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
if ($user->getId() === $entity->get('createdById')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\ImportEml;
use Espo\Core\Acl\AccessCreateChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Entities\User;
class AccessChecker implements AccessCreateChecker
{
public function check(User $user, ScopeData $data): bool
{
return $data->isTrue();
}
public function checkCreate(User $user, ScopeData $data): bool
{
return $data->isTrue();
}
}

View File

@@ -0,0 +1,235 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Note;
use Espo\Core\Acl\Permission;
use Espo\Core\Acl\Table;
use Espo\Core\Name\Field;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\AclManager;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Utils\Config;
use DateTime;
use Exception;
/**
* @implements AccessEntityCREDChecker<Note>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
private const EDIT_PERIOD = '7 days';
private const DELETE_PERIOD = '1 month';
private DefaultAccessChecker $defaultAccessChecker;
private AclManager $aclManager;
private EntityManager $entityManager;
private Config $config;
public function __construct(
DefaultAccessChecker $defaultAccessChecker,
AclManager $aclManager,
EntityManager $entityManager,
Config $config
) {
$this->defaultAccessChecker = $defaultAccessChecker;
$this->aclManager = $aclManager;
$this->entityManager = $entityManager;
$this->config = $config;
}
/**
* @param Note $entity
*/
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
$parentId = $entity->get('parentId');
$parentType = $entity->get('parentType');
if (!$parentId || !$parentType) {
return true;
}
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if ($parent && $this->aclManager->checkEntityStream($user, $parent)) {
return true;
}
return false;
}
/**
* @param Note $entity
*/
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
$parentId = $entity->getParentId();
$parentType = $entity->getParentType();
if ($parentId && $parentType) {
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if (!$parent) {
return false;
}
return $this->aclManager->checkEntityStream($user, $parent);
}
if ($entity->getType() !== Note::TYPE_POST) {
return false;
}
if ($entity->getCreatedById() === $user->getId()) {
return true;
}
if ($entity->getTargetType() === Note::TARGET_ALL) {
return true;
}
if ($entity->getTargetType() === Note::TARGET_TEAMS) {
$targetTeamIdList = $entity->getLinkMultipleIdList(Field::TEAMS);
foreach ($user->getTeamIdList() as $teamId) {
if (in_array($teamId, $targetTeamIdList)) {
return true;
}
}
return false;
}
if ($entity->getTargetType() === Note::TARGET_USERS) {
return in_array($user->getId(), $entity->getLinkMultipleIdList('users'));
}
if ($entity->getTargetType() === Note::TARGET_PORTALS) {
return $this->aclManager->getPermissionLevel($user, Permission::PORTAL) === Table::LEVEL_YES;
}
return false;
}
/**
* @param Note $entity
*/
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
if (!$this->defaultAccessChecker->checkEntityEdit($user, $entity, $data)) {
return false;
}
if (!$this->aclManager->checkOwnershipOwn($user, $entity)) {
return false;
}
$createdAt = $entity->get(Field::CREATED_AT);
if (!$createdAt) {
return true;
}
$noteEditThresholdPeriod =
'-' . $this->config->get('noteEditThresholdPeriod', self::EDIT_PERIOD);
$dt = new DateTime();
$dt->modify($noteEditThresholdPeriod);
try {
if ($dt->format('U') > (new DateTime($createdAt))->format('U')) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
/**
* @param Note $entity
*/
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
if (!$this->defaultAccessChecker->checkEntityDelete($user, $entity, $data)) {
return false;
}
if (!$this->aclManager->checkOwnershipOwn($user, $entity)) {
return false;
}
$createdAt = $entity->get(Field::CREATED_AT);
if (!$createdAt) {
return true;
}
$deleteThresholdPeriod =
'-' . $this->config->get('noteDeleteThresholdPeriod', self::DELETE_PERIOD);
$dt = new DateTime();
$dt->modify($deleteThresholdPeriod);
try {
if ($dt->format('U') > (new DateTime($createdAt))->format('U')) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Note;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Note>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
/**
* @param Note $entity
*/
public function checkOwn(User $user, Entity $entity): bool
{
if ($entity->getType() === Note::TYPE_POST && $user->getId() === $entity->getCreatedById()) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Notification;
use Espo\Entities\Notification;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Notification>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get('userId')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Portal;
use Espo\Core\Acl\Permission;
use Espo\Entities\Portal;
use Espo\Entities\User;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Table;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\AclManager;
/**
* @implements AccessEntityCREDChecker<Portal>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
public function __construct(private DefaultAccessChecker $defaultAccessChecker, private AclManager $aclManager)
{}
public function check(User $user, ScopeData $data): bool
{
$level = $this->aclManager->getPermissionLevel($user, Permission::PORTAL);
return $level === Table::LEVEL_YES;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\ScheduledJob;
use Espo\Entities\ScheduledJob;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
/**
* @implements AccessEntityCREDChecker<ScheduledJob>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
private DefaultAccessChecker $defaultAccessChecker;
public function __construct(DefaultAccessChecker $defaultAccessChecker)
{
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
if ($entity->get('isInternal')) {
return false;
}
return $this->defaultAccessChecker->checkEntityCreate($user, $entity, $data);
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if ($entity->get('isInternal')) {
return false;
}
return $this->defaultAccessChecker->checkEntityRead($user, $entity, $data);
}
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
if ($entity->get('isInternal')) {
return false;
}
return $this->defaultAccessChecker->checkEntityEdit($user, $entity, $data);
}
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
if ($entity->get('isInternal')) {
return false;
}
return $this->defaultAccessChecker->checkEntityDelete($user, $entity, $data);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Team;
use Espo\Core\Name\Field;
use Espo\Entities\Team;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Team>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
$userTeamIdList = $user->getLinkMultipleIdList(Field::TEAMS);
return in_array($entity->getId(), $userTeamIdList);
}
}

View File

@@ -0,0 +1,129 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\User;
use Espo\Core\Acl\Permission;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDSChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Table;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\AclManager;
/**
* @implements AccessEntityCREDSChecker<User>
*/
class AccessChecker implements AccessEntityCREDSChecker
{
use DefaultAccessCheckerDependency;
public function __construct(
private DefaultAccessChecker $defaultAccessChecker,
private AclManager $aclManager,
) {}
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
if (!$user->isAdmin()) {
return false;
}
if ($entity->isSuperAdmin() && !$user->isSuperAdmin()) {
return false;
}
return $this->defaultAccessChecker->checkEntityCreate($user, $entity, $data);
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if (!$user->isAdmin() && !$entity->isActive()) {
return false;
}
if ($entity->isSuperAdmin() && !$user->isSuperAdmin()) {
return false;
}
if ($entity->isSystem()) {
return false;
}
if ($entity->isPortal()) {
return $this->aclManager->getPermissionLevel($user, Permission::PORTAL) === Table::LEVEL_YES;
}
return $this->defaultAccessChecker->checkEntityRead($user, $entity, $data);
}
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
if ($entity->isSystem()) {
return false;
}
if (!$user->isAdmin()) {
if ($user->getId() !== $entity->getId()) {
return false;
}
}
if ($entity->isSuperAdmin() && !$user->isSuperAdmin()) {
return false;
}
return $this->defaultAccessChecker->checkEntityEdit($user, $entity, $data);
}
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
if (!$user->isAdmin()) {
return false;
}
if ($entity->isSystem()) {
return false;
}
if ($entity->isSuperAdmin() && !$user->isSuperAdmin()) {
return false;
}
return $this->defaultAccessChecker->checkEntityDelete($user, $entity, $data);
}
public function checkEntityStream(User $user, Entity $entity, ScopeData $data): bool
{
/** @noinspection PhpRedundantOptionalArgumentInspection */
return $this->aclManager->checkUserPermission($user, $entity, Permission::USER);
}
}

View File

@@ -0,0 +1,65 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\User;
use Espo\Core\Name\Field;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\Acl\OwnershipOwnChecker;
use Espo\Core\Acl\OwnershipTeamChecker;
/**
* @implements OwnershipOwnChecker<User>
* @implements OwnershipTeamChecker<User>
*/
class OwnershipChecker implements OwnershipOwnChecker, OwnershipTeamChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
return $user->getId() === $entity->getId();
}
public function checkTeam(User $user, Entity $entity): bool
{
assert($entity instanceof CoreEntity);
$intersect = array_intersect(
$user->getLinkMultipleIdList(Field::TEAMS),
$entity->getLinkMultipleIdList(Field::TEAMS)
);
if (count($intersect)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,105 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Webhook;
use Espo\Entities\User;
use Espo\Entities\Webhook;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\DefaultAccessChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Traits\DefaultAccessCheckerDependency;
/**
* @implements AccessEntityCREDChecker<Webhook>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
public function __construct(DefaultAccessChecker $defaultAccessChecker)
{
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function check(User $user, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
if (!$user->isApi()) {
return false;
}
if ($data->isFalse()) {
return false;
}
return true;
}
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
return $this->checkEntityInternal($user, $entity, $data);
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
return $this->checkEntityInternal($user, $entity, $data);
}
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
return $this->checkEntityInternal($user, $entity, $data);
}
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
return $this->checkEntityInternal($user, $entity, $data);
}
private function checkEntityInternal(User $user, Entity $entity, ScopeData $data): bool
{
if ($user->isAdmin()) {
return true;
}
if ($data->isFalse()) {
return false;
}
if ($user->isApi() && $user->getId() === $entity->get('userId')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\Webhook;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<\Espo\Entities\Webhook>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
return $user->getId() === $entity->get('userId') && $user->isApi();
}
}

View File

@@ -0,0 +1,90 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Acl\WorkingTimeRange;
use Espo\Core\Acl\AssignmentChecker as AssignmentCheckerInterface;
use Espo\Core\Acl\DefaultAssignmentChecker;
use Espo\Core\AclManager;
use Espo\Entities\User;
use Espo\Entities\WorkingTimeRange;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
/**
* @implements AssignmentCheckerInterface<WorkingTimeRange>
*/
class AssignmentChecker implements AssignmentCheckerInterface
{
private DefaultAssignmentChecker $defaultAssignmentChecker;
private AclManager $aclManager;
private EntityManager $entityManager;
public function __construct(
DefaultAssignmentChecker $defaultAssignmentChecker,
AclManager $aclManager,
EntityManager $entityManager
) {
$this->defaultAssignmentChecker = $defaultAssignmentChecker;
$this->aclManager = $aclManager;
$this->entityManager = $entityManager;
}
/**
* @param WorkingTimeRange $entity
*/
public function check(User $user, Entity $entity): bool
{
$result = $this->defaultAssignmentChecker->check($user, $entity);
if (!$result) {
return false;
}
if (!$entity->isAttributeChanged('usersIds')) {
return true;
}
$users = $this->entityManager
->getRDBRepositoryByClass(User::class)
->where([Attribute::ID => $entity->getUsers()->getIdList()])
->find();
foreach ($users as $targetUser) {
$accessToUser = $this->aclManager->check($user, $targetUser);
if (!$accessToUser) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,165 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Attachment;
use Espo\Entities\Attachment;
use Espo\Entities\Note;
use Espo\Entities\Settings;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\Portal\AclManager;
/**
* @implements AccessEntityCREDChecker<Attachment>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
private DefaultAccessChecker $defaultAccessChecker;
private AclManager $aclManager;
private EntityManager $entityManager;
public function __construct(
DefaultAccessChecker $defaultAccessChecker,
AclManager $aclManager,
EntityManager $entityManager
) {
$this->defaultAccessChecker = $defaultAccessChecker;
$this->aclManager = $aclManager;
$this->entityManager = $entityManager;
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
/** @var Attachment $entity */
if ($entity->get('parentType') === Settings::ENTITY_TYPE) {
// Allow the logo.
return true;
}
$parent = null;
$parentType = $entity->get('parentType');
$parentId = $entity->get('parentId');
$relatedType = $entity->get('relatedType');
$relatedId = $entity->get('relatedId');
if ($parentId && $parentType) {
$parent = $this->entityManager->getEntityById($parentType, $parentId);
} else if ($relatedId && $relatedType) {
$parent = $this->entityManager->getEntityById($relatedType, $relatedId);
}
if (!$parent) {
if ($entity->get('createdById') === $user->getId()) {
return true;
}
return false;
}
if ($parent->getEntityType() === Note::ENTITY_TYPE) {
/** @var Note $parent */
$result = $this->checkEntityReadNoteParent($user, $parent);
if ($result !== null) {
return $result;
}
} else if ($this->aclManager->checkEntity($user, $parent)) {
if (
$entity->getTargetField() &&
!$this->aclManager->checkField($user, $parent->getEntityType(), $entity->getTargetField())
) {
return false;
}
return true;
}
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
return false;
}
private function checkEntityReadNoteParent(User $user, Note $note): ?bool
{
if ($note->isInternal()) {
return false;
}
if ($note->getTargetType() === Note::TARGET_PORTALS) {
$intersect = array_intersect(
$note->getLinkMultipleIdList('portals'),
$user->getLinkMultipleIdList('portals')
);
if (count($intersect)) {
return true;
}
return false;
}
if ($note->getTargetType() === Note::TARGET_USERS) {
$isRelated = $this->entityManager
->getRDBRepository(Note::ENTITY_TYPE)
->getRelation($note, 'users')
->isRelated($user);
if ($isRelated) {
return true;
}
return false;
}
if (!$note->getParentId() || !$note->getParentType()) {
return null;
}
$parent = $this->entityManager->getEntityById($note->getParentType(), $note->getParentId());
if ($parent && $this->aclManager->checkEntity($user, $parent)) {
return true;
}
return null;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Attachment;
use Espo\Entities\Attachment;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Attachment>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
private const ATTR_CREATED_BY_ID = 'createdById';
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get(self::ATTR_CREATED_BY_ID)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Email;
use Espo\Entities\Email;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\Acl\AccessEntityCREDSChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\Acl\Table;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
/**
* @implements AccessEntityCREDSChecker<Email>
*/
class AccessChecker implements AccessEntityCREDSChecker
{
use DefaultAccessCheckerDependency;
public function __construct(
DefaultAccessChecker $defaultAccessChecker
) {
$this->defaultAccessChecker = $defaultAccessChecker;
}
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
if ($this->defaultAccessChecker->checkEntityRead($user, $entity, $data)) {
return true;
}
if ($data->isFalse()) {
return false;
}
if ($data->getRead() === Table::LEVEL_NO) {
return false;
}
assert($entity instanceof CoreEntity);
$userIdList = $entity->getLinkMultipleIdList('users');
if (in_array($user->getId(), $userIdList)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Email;
use Espo\Entities\Email;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Email>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get('createdById')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,201 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Note;
use Espo\Core\Name\Field;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\AccessEntityCREDChecker;
use Espo\Core\Acl\ScopeData;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Portal\Acl\DefaultAccessChecker;
use Espo\Core\Portal\Acl\Traits\DefaultAccessCheckerDependency;
use Espo\Core\Portal\AclManager;
use Espo\Core\Utils\Config;
use DateTime;
use Exception;
/**
* @implements AccessEntityCREDChecker<Note>
*/
class AccessChecker implements AccessEntityCREDChecker
{
use DefaultAccessCheckerDependency;
private const EDIT_PERIOD = '7 days';
private const DELETE_PERIOD = '1 month';
private DefaultAccessChecker $defaultAccessChecker;
private AclManager $aclManager;
private EntityManager $entityManager;
private Config $config;
public function __construct(
DefaultAccessChecker $defaultAccessChecker,
AclManager $aclManager,
EntityManager $entityManager,
Config $config
) {
$this->defaultAccessChecker = $defaultAccessChecker;
$this->aclManager = $aclManager;
$this->entityManager = $entityManager;
$this->config = $config;
}
/**
* @param Note $entity
*/
public function checkEntityCreate(User $user, Entity $entity, ScopeData $data): bool
{
$parentId = $entity->getParentId();
$parentType = $entity->getParentType();
if (!$parentId || !$parentType) {
return $this->defaultAccessChecker->checkEntityCreate($user, $entity, $data);
}
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if ($parent && $this->aclManager->checkEntityStream($user, $parent)) {
return true;
}
return $this->defaultAccessChecker->checkEntityCreate($user, $entity, $data);
}
/**
* @param Note $entity
*/
public function checkEntityRead(User $user, Entity $entity, ScopeData $data): bool
{
$parentId = $entity->getParentId();
$parentType = $entity->getParentType();
if ($parentId && $parentType) {
$parent = $this->entityManager->getEntityById($parentType, $parentId);
if (!$parent) {
return false;
}
return $this->aclManager->checkEntityStream($user, $parent);
}
if ($entity->getType() !== Note::TYPE_POST) {
return false;
}
if ($entity->getCreatedById() === $user->getId()) {
return true;
}
if ($entity->getTargetType() === Note::TARGET_PORTALS) {
return in_array($user->getPortalId(), $entity->getLinkMultipleIdList('portals'));
}
return false;
}
/**
* @param Note $entity
*/
public function checkEntityEdit(User $user, Entity $entity, ScopeData $data): bool
{
if (!$this->defaultAccessChecker->checkEntityEdit($user, $entity, $data)) {
return false;
}
if (!$this->aclManager->checkOwnershipOwn($user, $entity)) {
return false;
}
$createdAt = $entity->get(Field::CREATED_AT);
if (!$createdAt) {
return true;
}
$noteEditThresholdPeriod =
'-' . $this->config->get('noteEditThresholdPeriod', self::EDIT_PERIOD);
$dt = new DateTime();
$dt->modify($noteEditThresholdPeriod);
try {
if ($dt->format('U') > (new DateTime($createdAt))->format('U')) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
/**
* @param Note $entity
*/
public function checkEntityDelete(User $user, Entity $entity, ScopeData $data): bool
{
if (!$this->defaultAccessChecker->checkEntityDelete($user, $entity, $data)) {
return false;
}
if (!$this->aclManager->checkOwnershipOwn($user, $entity)) {
return false;
}
$createdAt = $entity->get(Field::CREATED_AT);
if (!$createdAt) {
return true;
}
$deleteThresholdPeriod =
'-' . $this->config->get('noteDeleteThresholdPeriod', self::DELETE_PERIOD);
$dt = new DateTime();
$dt->modify($deleteThresholdPeriod);
try {
if ($dt->format('U') > (new DateTime($createdAt))->format('U')) {
return false;
}
} catch (Exception $e) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Note;
use Espo\Entities\Note;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Note>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
/**
* @param Note $entity
*/
public function checkOwn(User $user, Entity $entity): bool
{
if ($entity->getType() === Note::TYPE_POST && $user->getId() === $entity->getCreatedById()) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,50 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\Notification;
use Espo\Entities\Notification;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<Notification>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
if ($user->getId() === $entity->get('userId')) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AclPortal\User;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl\OwnershipOwnChecker;
/**
* @implements OwnershipOwnChecker<User>
*/
class OwnershipChecker implements OwnershipOwnChecker
{
public function checkOwn(User $user, Entity $entity): bool
{
return $user->getId() === $entity->getId();
}
}

View File

@@ -0,0 +1,87 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AddressFormatters;
use Espo\Core\Field\Address;
use Espo\Core\Field\Address\AddressFormatter;
class Formatter1 implements AddressFormatter
{
public function format(Address $address): string
{
$result = '';
$street = $address->getStreet();
$city = $address->getCity();
$country = $address->getCountry();
$state = $address->getState();
$postalCode = $address->getPostalCode();
if ($street) {
$result .= $street;
}
if ($city || $state || $postalCode) {
if ($result) {
$result .= "\n";
}
if ($city) {
$result .= $city;
}
if ($state && $city) {
$result .= ', ';
}
if ($state) {
$result .= $state;
}
if ($postalCode && ($state || $city)) {
$result .= ' ';
}
if ($postalCode) {
$result .= $postalCode;
}
}
if ($country) {
if ($result) {
$result .= "\n";
}
$result .= $country;
}
return $result;
}
}

View File

@@ -0,0 +1,89 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AddressFormatters;
use Espo\Core\Field\Address;
use Espo\Core\Field\Address\AddressFormatter;
class Formatter2 implements AddressFormatter
{
public function format(Address $address): string
{
$result = '';
$street = $address->getStreet();
$city = $address->getCity();
$country = $address->getCountry();
$state = $address->getState();
$postalCode = $address->getPostalCode();
if ($street) {
$result .= $street;
}
if ($city || $postalCode) {
if ($result) {
$result .= "\n";
}
if ($postalCode) {
$result .= $postalCode;
}
if ($postalCode && $city) {
$result .= ' ';
}
if ($city) {
$result .= $city;
}
}
if ($state || $country) {
if ($result) {
$result .= "\n";
}
if ($state) {
$result .= $state;
}
if ($state && $country) {
$result .= ' ';
}
if ($country) {
$result .= $country;
}
}
return $result;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AddressFormatters;
use Espo\Core\Field\Address;
use Espo\Core\Field\Address\AddressFormatter;
class Formatter3 implements AddressFormatter
{
public function format(Address $address): string
{
$result = '';
$street = $address->getStreet();
$city = $address->getCity();
$country = $address->getCountry();
$state = $address->getState();
$postalCode = $address->getPostalCode();
if ($country) {
$result .= $country;
}
if ($city || $state || $postalCode) {
if ($result) {
$result .= "\n";
}
if ($state) {
$result .= $state;
}
if ($state && $postalCode) {
$result .= ' ';
}
if ($postalCode) {
$result .= $postalCode;
}
if ($city && ($state || $postalCode)) {
$result .= ' ';
}
if ($city) {
$result .= $city;
}
}
if ($street) {
if ($result) {
$result .= "\n";
}
$result .= $street;
}
return $result;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AddressFormatters;
use Espo\Core\Field\Address;
use Espo\Core\Field\Address\AddressFormatter;
class Formatter4 implements AddressFormatter
{
public function format(Address $address): string
{
$result = '';
$street = $address->getStreet();
$city = $address->getCity();
$country = $address->getCountry();
$state = $address->getState();
$postalCode = $address->getPostalCode();
if ($street) {
$result .= $street;
}
if ($city) {
if ($result) {
$result .= "\n";
}
$result .= $city;
}
if ($country || $state || $postalCode) {
if ($result) {
$result .= "\n";
}
if ($country) {
$result .= $country;
}
if ($state && $country) {
$result .= ' - ';
}
if ($state) {
$result .= $state;
}
if ($postalCode && ($state || $country)) {
$result .= ' ';
}
if ($postalCode) {
$result .= $postalCode;
}
}
return $result;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppInfo;
use Espo\Core\Binding\Binding as BindingItem;
use Espo\Core\Binding\EspoBindingLoader;
use Espo\Core\Console\Command\Params;
use Espo\Core\Utils\Module;
class Binding
{
private Module $module;
public function __construct(Module $module)
{
$this->module = $module;
}
public function process(Params $params): string
{
$result = '';
$bindingLoader = new EspoBindingLoader($this->module);
$data = $bindingLoader->load();
$keyList = $data->getGlobalKeyList();
$result .= "Global:\n\n";
foreach ($keyList as $key) {
$result .= $this->printItem($key, $data->getGlobal($key));
}
$contextList = $data->getContextList();
foreach ($contextList as $context) {
$result .= "Context: {$context}\n\n";
$keyList = $data->getContextKeyList($context);
foreach ($keyList as $key) {
$result .= $this->printItem($key, $data->getContext($context, $key));
}
}
return $result;
}
private function printItem(string $key, BindingItem $binding): string
{
$result = '';
$tab = ' ';
$result .= $tab . "Key: {$key}\n";
$type = $binding->getType();
$value = $binding->getValue();
$typeString = [
BindingItem::IMPLEMENTATION_CLASS_NAME => 'Implementation',
BindingItem::CONTAINER_SERVICE => 'Service',
BindingItem::VALUE => 'Value',
BindingItem::CALLBACK => 'Callback',
BindingItem::FACTORY_CLASS_NAME => 'Factory',
][$type];
$result .= $tab . "Type: {$typeString}\n";
if ($type == BindingItem::IMPLEMENTATION_CLASS_NAME || $type == BindingItem::CONTAINER_SERVICE) {
$result .= $tab . "Value: {$value}\n";
}
if ($type == BindingItem::VALUE) {
if (is_string($value) || is_int($value) || is_float($value)) {
$result .= $tab . "Value: {$value}\n";
}
if (is_bool($value)) {
$valueString = $value ? 'true' : 'false';
$result .= $tab . "Value: {$valueString}\n";
}
}
$result .= "\n";
return $result;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppInfo;
use Espo\Core\Console\Command\Params;
use Espo\Core\Container as ContainerService;
use Espo\Core\Utils\Metadata;
class Container
{
public function __construct(private ContainerService $container, private Metadata $metadata)
{}
public function process(Params $params): string
{
$nameOnly = $params->hasFlag('nameOnly');
$result = '';
$serviceList = [
'injectableFactory',
'config',
'log',
'fileManager',
'dataManager',
'metadata',
'user',
];
/** @var string[] $fileList */
$fileList = scandir('application/Espo/Core/Loaders');
if (file_exists('custom/Espo/Custom/Core/Loaders')) {
$fileList = array_merge($fileList, scandir('custom/Espo/Custom/Core/Loaders') ?: []);
}
foreach ($fileList as $file) {
if (substr($file, -4) === '.php') {
$name = lcfirst(substr($file, 0, -4));
if (!in_array($name, $serviceList) && $this->container->has($name)) {
$serviceList[] = $name;
}
}
}
foreach ($this->metadata->get(['app', 'containerServices']) ?? [] as $name => $data) {
if (!in_array($name, $serviceList)) {
$serviceList[] = $name;
}
}
sort($serviceList);
if ($nameOnly) {
foreach ($serviceList as $name) {
$result .= $name . "\n";
}
return $result;
}
foreach ($serviceList as $name) {
$result .= $name . "\n";
$obj = $this->container->get($name);
$result .= get_class($obj) . "\n";
$result .= "\n";
}
return $result;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppInfo;
use Espo\Core\Console\Command\Params;
use Espo\Core\Utils\ClassFinder;
use Espo\Core\Job\MetadataProvider;
class Jobs
{
private $classFinder;
private $metadataProvider;
public function __construct(ClassFinder $classFinder, MetadataProvider $metadataProvider)
{
$this->classFinder = $classFinder;
$this->metadataProvider = $metadataProvider;
}
public function process(Params $params): string
{
$result = "Available jobs:\n\n";
$list = array_map(
function ($item) {
return ' ' . $item;
},
array_unique(
array_merge(
array_keys($this->classFinder->getMap('Jobs')),
$this->metadataProvider->getScheduledJobNameList()
)
)
);
asort($list);
return $result . implode("\n", $list) . "\n";
}
}

View File

@@ -0,0 +1,48 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppParams;
use Espo\Core\Utils\Address\CountryDataProvider;
use Espo\Tools\App\AppParam;
class AddressCountryData implements AppParam
{
public function __construct(
private CountryDataProvider $provider
) {}
/**
* @return array{list: string[], preferredList: string[]}
*/
public function get(): array
{
return $this->provider->get();
}
}

View File

@@ -0,0 +1,59 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppParams;
use Espo\Core\Currency\ConfigDataProvider;
use Espo\Core\Utils\NumberUtil;
use Espo\Tools\App\AppParam;
use stdClass;
/**
* @noinspection PhpUnused
*/
class CurrencyRates implements AppParam
{
private const int PRECISION = 6;
public function __construct(
private ConfigDataProvider $configDataProvider,
private NumberUtil $numberUtil,
) {}
public function get(): stdClass
{
$rates = $this->configDataProvider->getCurrencyRates()->toAssoc();
foreach ($rates as $code => $value) {
$rates[$code] = $this->numberUtil->format($value, self::PRECISION, '.', '');
}
return (object) $rates;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppParams;
use Espo\Entities\Extension;
use Espo\Entities\User;
use Espo\ORM\EntityManager;
use Espo\Tools\App\AppParam;
use stdClass;
class Extensions implements AppParam
{
private User $user;
private EntityManager $entityManager;
public function __construct(
User $user,
EntityManager $entityManager
) {
$this->user = $user;
$this->entityManager = $entityManager;
}
/**
* @return stdClass[]
*/
public function get(): array
{
if (!$this->user->isRegular() && !$this->user->isAdmin()) {
return [];
}
$extensionList = $this->entityManager
->getRDBRepositoryByClass(Extension::class)
->where([
'licenseStatus' => [
Extension::LICENSE_STATUS_INVALID,
Extension::LICENSE_STATUS_EXPIRED,
Extension::LICENSE_STATUS_SOFT_EXPIRED,
],
])
->find();
$list = [];
foreach ($extensionList as $extension) {
$list[] = (object) [
'name' => $extension->getName(),
'version' => $extension->getVersion(),
'licenseStatus' => $extension->getLicenseStatus(),
'licenseStatusMessage' => $extension->getLicenseStatusMessage(),
'isInstalled' => $extension->isInstalled(),
'notify' => in_array(
$extension->getLicenseStatus(),
[
Extension::LICENSE_STATUS_INVALID,
Extension::LICENSE_STATUS_EXPIRED,
]
)
];
}
return $list;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AppParams;
use Espo\Core\Acl;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\ORM\EntityManager;
use Espo\Core\Select\SelectBuilderFactory;
use Espo\Entities\Template;
use Espo\Tools\App\AppParam;
use RuntimeException;
/**
* Returns a list of entity types for which a PDF template exists.
*
* @noinspection PhpUnused
*/
class TemplateEntityTypeList implements AppParam
{
public function __construct(
private Acl $acl,
private SelectBuilderFactory $selectBuilderFactory,
private EntityManager $entityManager,
) {}
/**
* @return string[]
*/
public function get(): array
{
if (!$this->acl->checkScope(Template::ENTITY_TYPE)) {
return [];
}
$list = [];
try {
$query = $this->selectBuilderFactory
->create()
->from(Template::ENTITY_TYPE)
->withAccessControlFilter()
->buildQueryBuilder()
->select(['entityType'])
->where(['status' => Template::STATUS_ACTIVE])
->group(['entityType'])
->build();
} catch (BadRequest|Forbidden $e) {
throw new RuntimeException('', 0, $e);
}
$templateCollection = $this->entityManager
->getRDBRepositoryByClass(Template::class)
->clone($query)
->find();
foreach ($templateCollection as $template) {
$list[] = $template->getTargetEntityType();
}
return $list;
}
}

View File

@@ -0,0 +1,289 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\AssignmentNotificators;
use Espo\Core\Field\DateTime;
use Espo\Core\Field\LinkParent;
use Espo\Core\Name\Field;
use Espo\Core\Notification\DefaultAssignmentNotificator;
use Espo\Entities\EmailAddress;
use Espo\Entities\EmailFolder;
use Espo\Modules\Crm\Entities\Account;
use Espo\Modules\Crm\Entities\Contact;
use Espo\Modules\Crm\Entities\Lead;
use Espo\ORM\Name\Attribute;
use Espo\Tools\Stream\Service as StreamService;
use Espo\Core\Notification\AssignmentNotificator;
use Espo\Core\Notification\AssignmentNotificator\Params;
use Espo\Core\Notification\UserEnabledChecker;
use Espo\Core\AclManager;
use Espo\ORM\EntityManager;
use Espo\ORM\Entity;
use Espo\Entities\User;
use Espo\Entities\Notification;
use Espo\Entities\Email as EmailEntity;
use Espo\Repositories\Email as EmailRepository;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Tools\Email\Util;
/**
* @implements AssignmentNotificator<EmailEntity>
*/
class Email implements AssignmentNotificator
{
private const DAYS_THRESHOLD = 2;
public function __construct(
private User $user,
private EntityManager $entityManager,
private UserEnabledChecker $userChecker,
private AclManager $aclManager,
private StreamService $streamService,
private DefaultAssignmentNotificator $defaultAssignmentNotificator,
) {}
/**
* @param EmailEntity $entity
*/
public function process(Entity $entity, Params $params): void
{
if (
!in_array(
$entity->getStatus(),
[
EmailEntity::STATUS_ARCHIVED,
EmailEntity::STATUS_SENT,
EmailEntity::STATUS_BEING_IMPORTED,
]
)
) {
return;
}
if (
$entity->getStatus() !== EmailEntity::STATUS_BEING_IMPORTED &&
!$this->streamService->checkIsEnabled(EmailEntity::ENTITY_TYPE)
) {
$this->defaultAssignmentNotificator->process(
$entity,
$params->withOption(DefaultAssignmentNotificator::OPTION_FORCE_ASSIGNED_USER, true)
);
}
if ($params->getOption(EmailEntity::SAVE_OPTION_IS_JUST_SENT)) {
$previousUserIdList = [];
} else {
$previousUserIdList = $entity->getFetched('usersIds');
if (!is_array($previousUserIdList)) {
$previousUserIdList = [];
}
}
$dateSent = $entity->getDateSent();
if (!$dateSent) {
return;
}
if ($dateSent->diff(DateTime::createNow())->days > self::DAYS_THRESHOLD) {
return;
}
$emailUserIdList = $entity->get('usersIds');
if (!is_array($emailUserIdList)) {
return;
}
$userIdList = [];
foreach ($emailUserIdList as $userId) {
if (
!in_array($userId, $userIdList) &&
!in_array($userId, $previousUserIdList) &&
$userId !== $this->user->getId()
) {
$userIdList[] = $userId;
}
}
$data = [
'emailId' => $entity->getId(),
'emailName' => $entity->getSubject(),
];
/** @var EmailRepository $emailRepository */
$emailRepository = $this->entityManager->getRepository(EmailEntity::ENTITY_TYPE);
/** @var EmailAddressRepository $emailAddressRepository */
$emailAddressRepository = $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
if (!$entity->has('from')) {
$emailRepository->loadFromField($entity);
}
if (!$entity->has('to')) {
$emailRepository->loadToField($entity);
}
$person = null;
$from = $entity->get('from');
if ($from) {
$person = $emailAddressRepository->getEntityByAddress($from, null, [
User::ENTITY_TYPE,
Contact::ENTITY_TYPE,
Lead::ENTITY_TYPE,
]);
if ($person) {
$data['personEntityType'] = $person->getEntityType();
$data['personEntityName'] = $person->get(Field::NAME);
$data['personEntityId'] = $person->getId();
}
}
$userIdFrom = null;
if ($person && $person->getEntityType() === User::ENTITY_TYPE) {
$userIdFrom = $person->getId();
}
if (empty($data['personEntityId'])) {
$data['fromString'] = Util::parseFromName($entity->getFromString() ?? '');
if (empty($data['fromString']) && $from) {
$data['fromString'] = $from;
}
}
$parent = $entity->getParent();
$account = $entity->getAccount();
foreach ($userIdList as $userId) {
if ($userIdFrom === $userId) {
continue;
}
if (
$entity->getUserColumnInTrash($userId) ||
$entity->getUserColumnIsRead($userId) ||
$entity->getUserSkipNotification($userId)
) {
continue;
}
if (!$this->userChecker->checkAssignment(EmailEntity::ENTITY_TYPE, $userId)) {
continue;
}
if (
$params->getOption(EmailEntity::SAVE_OPTION_IS_BEING_IMPORTED) ||
$params->getOption(EmailEntity::SAVE_OPTION_IS_JUST_SENT)
) {
$folderId = $entity->getUserColumnFolderId($userId);
if (
$folderId &&
$this->entityManager
->getRDBRepositoryByClass(EmailFolder::class)
->where([
'id' => $folderId,
'skipNotifications' => true,
])
->count()
) {
continue;
}
}
$user = $this->entityManager->getRDBRepositoryByClass(User::class)->getById($userId);
if (!$user) {
continue;
}
if ($user->isPortal()) {
continue;
}
if (!$this->aclManager->checkScope($user, EmailEntity::ENTITY_TYPE)) {
continue;
}
$isArchivedOrBeingImported =
$entity->getStatus() === EmailEntity::STATUS_ARCHIVED ||
$params->getOption(EmailEntity::SAVE_OPTION_IS_BEING_IMPORTED);
if (
$isArchivedOrBeingImported &&
$parent &&
$this->streamService->checkIsFollowed($parent, $userId)
) {
continue;
}
if (
$isArchivedOrBeingImported &&
$account &&
$this->streamService->checkIsFollowed($account, $userId)
) {
continue;
}
$existing = $this->entityManager
->getRDBRepository(Notification::ENTITY_TYPE)
->where([
'type' => Notification::TYPE_EMAIL_RECEIVED,
'userId' => $userId,
'relatedId' => $entity->getId(),
'relatedType' => EmailEntity::ENTITY_TYPE,
])
->select([Attribute::ID])
->findOne();
if ($existing) {
continue;
}
$notification = $this->entityManager->getRDBRepositoryByClass(Notification::class)->getNew();
$notification
->setType(Notification::TYPE_EMAIL_RECEIVED)
->setUserId($userId)
->setData($data)
->setRelated(LinkParent::createFromEntity($entity))
->setActionId($params->getActionId());
$this->entityManager->saveEntity($notification);
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Field\DateTime;
use Espo\Core\Utils\Config;
use Espo\Entities\AppLogRecord;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\DeleteBuilder;
class AppLog implements Cleanup
{
private const PERIOD = '30 days';
public function __construct(
private EntityManager $entityManager,
private Config $config
) {}
public function process(): void
{
if (!$this->config->get('cleanupAppLog')) {
return;
}
$query = DeleteBuilder::create()
->from(AppLogRecord::ENTITY_TYPE)
->where(['createdAt<' => $this->getBefore()->toString()])
->build();
$this->entityManager->getQueryExecutor()->execute($query);
}
private function getBefore(): DateTime
{
/** @var string $period */
$period = $this->config->get('cleanupAppLogPeriod') ?? self::PERIOD;
return DateTime::createNow()->modify('-' . $period);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Field\DateTime;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Note;
use Espo\ORM\EntityManager;
/**
* @noinspection PhpUnused
*/
class Audit implements Cleanup
{
private const PERIOD = '3 months';
public function __construct(
private Metadata $metadata,
private EntityManager $entityManager,
private Config $config
) {}
public function process(): void
{
if (!$this->config->get('cleanupAudit')) {
return;
}
$entityTypeList = $this->getEntityTypeList();
foreach ($entityTypeList as $scope) {
$this->processEntityType($scope);
}
}
private function processEntityType(string $entityType): void
{
$query = $this->entityManager
->getQueryBuilder()
->delete()
->from(Note::ENTITY_TYPE)
->where([
'parentType' => $entityType,
'createdAt<' => $this->getBefore()->toString(),
'type' => [Note::TYPE_UPDATE],
])
->build();
$this->entityManager->getQueryExecutor()->execute($query);
}
/**
* @return string[]
*/
private function getEntityTypeList(): array
{
/** @var string[] $scopeList */
$scopeList = array_keys($this->metadata->get(['scopes']) ?? []);
$scopeList = array_filter($scopeList, function ($item) {
return $this->metadata->get("scopes.$item.entity") &&
!$this->metadata->get("scopes.$item.preserveAuditLog") &&
!$this->metadata->get("scopes.$item.stream");
});
return array_values($scopeList);
}
private function getBefore(): DateTime
{
/** @var string $period */
$period = $this->config->get('cleanupAuditPeriod') ?? self::PERIOD;
return DateTime::createNow()->modify('-' . $period);
}
}

View File

@@ -0,0 +1,73 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\ORM\EntityManager;
use Espo\Core\Field\DateTime;
use Espo\Entities\Export;
class Exports implements Cleanup
{
private $config;
private $entityManager;
private string $cleanupPeriod = '2 days';
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupExportsPeriod', $this->cleanupPeriod);
$before = DateTime::createNow()
->modify($period)
->toString();
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from(Export::ENTITY_TYPE)
->where([
'createdAt<' => $before,
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,71 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\ORM\EntityManager;
use Espo\Core\Field\DateTime;
class MassActions implements Cleanup
{
private $config;
private $entityManager;
private string $cleanupPeriod = '14 days';
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupMassActionsPeriod', $this->cleanupPeriod);
$before = DateTime::createNow()
->modify($period)
->toString();
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from('MassAction')
->where([
'createdAt<' => $before,
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Field\DateTime;
use Espo\ORM\EntityManager;
use Espo\Entities\PasswordChangeRequest;
class PasswordChangeRequests implements Cleanup
{
private Config $config;
private EntityManager $entityManager;
private string $cleanupPeriod = '30 days';
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupPasswordChangeRequestsPeriod', $this->cleanupPeriod);
$before = DateTime::createNow()
->modify($period)
->toString();
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from(PasswordChangeRequest::ENTITY_TYPE)
->where([
'createdAt<' => $before,
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Modules\Crm\Entities\Reminder;
use Espo\ORM\EntityManager;
use DateTime;
class Reminders implements Cleanup
{
private string $cleanupRemindersPeriod = '15 days';
private Config $config;
private EntityManager $entityManager;
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupRemindersPeriod', $this->cleanupRemindersPeriod);
$dt = new DateTime();
$dt->modify($period);
$delete = $this->entityManager
->getQueryBuilder()
->delete()
->from(Reminder::ENTITY_TYPE)
->where([
'remindAt<' => $dt->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT),
])
->build();
$this->entityManager->getQueryExecutor()->execute($delete);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Acl\UserAclManagerProvider;
use Espo\Entities\StarSubscription;
use Espo\Entities\User;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\DeleteBuilder;
use Espo\Tools\Stars\StarService;
/**
* @noinspection PhpUnused
*/
class Stars implements Cleanup
{
public function __construct(
private EntityManager $entityManager,
private UserAclManagerProvider $userAclManagerProvider,
private StarService $service
) {}
public function process(): void
{
foreach ($this->getEntityTypeList() as $entityType) {
$this->processEntityType($entityType);
}
}
/**
* @return string[]
*/
private function getEntityTypeList(): array
{
$groups = $this->entityManager->getRDBRepositoryByClass(StarSubscription::class)
->group('entityType')
->select('entityType')
->find();
$list = [];
foreach ($groups as $group) {
$list[] = $group->get('entityType');
}
return $list;
}
private function processEntityType(string $entityType): void
{
if (
!$this->service->isEnabled($entityType) ||
!$this->entityManager->hasRepository($entityType)
) {
$deleteQuery = DeleteBuilder::create()
->from(StarSubscription::ENTITY_TYPE)
->where(['entityType' => $entityType])
->build();
$this->entityManager->getQueryExecutor()->execute($deleteQuery);
return;
}
$stars = $this->entityManager
->getRDBRepositoryByClass(StarSubscription::class)
->where(['entityType' => $entityType])
->sth()
->find();
foreach ($stars as $star) {
$entityId = $star->get('entityId');
$userId = $star->get('userId');
if ($userId === null || $entityId === null) {
continue;
}
$entity = $this->entityManager->getEntityById($entityType, $entityId);
$user = $this->entityManager->getRDBRepositoryByClass(User::class)->getById($userId);
if (!$entity || !$user) {
$this->unstar($userId, $entityType, $entityId);
continue;
}
$aclManager = $this->userAclManagerProvider->get($user);
if (!$aclManager->checkEntityRead($user, $entity)) {
$this->unstar($userId, $entityType, $entityId);
}
}
}
private function unstar(string $userId, string $entityType, string $entityId): void
{
$deleteQuery = DeleteBuilder::create()
->from(StarSubscription::ENTITY_TYPE)
->where([
'userId' => $userId,
'entityType' => $entityType,
'entityId' => $entityId,
])
->build();
$this->entityManager->getQueryExecutor()->execute($deleteQuery);
}
}

View File

@@ -0,0 +1,130 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Field\DateTime;
use Espo\Core\Name\Field;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\Entities\StreamSubscription;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\Part\Condition as Cond;
class Subscribers implements Cleanup
{
private const PERIOD = '2 months';
public function __construct(
private Metadata $metadata,
private EntityManager $entityManager,
private Config $config
) {}
public function process(): void
{
if (!$this->config->get('cleanupSubscribers')) {
return;
}
/** @var string[] $scopeList */
$scopeList = array_keys($this->metadata->get(['scopes']) ?? []);
/** @var string[] $scopeList */
$scopeList = array_values(array_filter(
$scopeList,
fn ($item) => (bool) $this->metadata->get(['scopes', $item, 'stream'])
));
foreach ($scopeList as $scope) {
$this->processEntityType($scope);
}
}
private function processEntityType(string $entityType): void
{
/** @var ?array<string, mixed> $data */
$data = $this->metadata->get(['streamDefs', $entityType, 'subscribersCleanup']);
if (!($data['enabled'] ?? false)) {
return;
}
/** @var string $dateField */
$dateField = $data['dateField'] ?? Field::CREATED_AT;
/** @var ?string[] $statusList */
$statusList = $data['statusList'] ?? null;
/** @var ?string $statusField */
$statusField = $this->metadata->get(['scopes', $entityType, 'statusField']);
if ($statusList === null || $statusField === null) {
return;
}
/** @var string $period */
$period = $this->metadata->get(['streamDefs', $entityType, 'subscribersCleanup', 'period']) ??
$this->config->get('cleanupSubscribersPeriod') ??
self::PERIOD;
$before = DateTime::createNow()->modify('-' . $period);
$query = $this->entityManager
->getQueryBuilder()
->delete()
->from(StreamSubscription::ENTITY_TYPE, 'subscription')
->join(
$entityType,
'entity',
Cond::equal(
Cond::column('entity.id'),
Cond::column('entityId')
)
)
->where(
Cond::and(
Cond::equal(
Cond::column('entityType'),
$entityType
),
Cond::less(
Cond::column('entity.' . $dateField),
$before->toString()
),
Cond::in(
Cond::column('entity.' . $statusField),
$statusList
)
)
)
->build();
$this->entityManager->getQueryExecutor()->execute($query);
}
}

View File

@@ -0,0 +1,77 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\ORM\EntityManager;
use Espo\Entities\TwoFactorCode;
use DateTime;
class TwoFactorCodes implements Cleanup
{
private const PERIOD = '5 days';
private $config;
private $entityManager;
public function __construct(Config $config, EntityManager $entityManager)
{
$this->config = $config;
$this->entityManager = $entityManager;
}
public function process(): void
{
$period = '-' . $this->config->get('cleanupTwoFactorCodesPeriod', self::PERIOD);
$from = (new DateTime())
->modify($period)
->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT);
$query = $this->entityManager
->getQueryBuilder()
->delete()
->from(TwoFactorCode::ENTITY_TYPE)
->where([
'createdAt<' => $from,
])
->build();
$this->entityManager
->getQueryExecutor()
->execute($query);
}
}

View File

@@ -0,0 +1,89 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\Cleanup;
use Espo\Core\Cleanup\Cleanup;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Espo\Entities\WebhookEventQueueItem;
use Espo\Entities\WebhookQueueItem;
use Espo\ORM\EntityManager;
use DateTime;
use Espo\ORM\Name\Attribute;
/**
* @noinspection PhpUnused
*/
class WebhookQueue implements Cleanup
{
private string $cleanupWebhookQueuePeriod = '10 days';
public function __construct(private Config $config, private EntityManager $entityManager)
{}
public function process(): void
{
$period = '-' . $this->config->get('cleanupWebhookQueuePeriod', $this->cleanupWebhookQueuePeriod);
$datetime = new DateTime();
$datetime->modify($period);
$from = $datetime->format(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT);
$query1 = $this->entityManager
->getQueryBuilder()
->delete()
->from(WebhookQueueItem::ENTITY_TYPE)
->where([
'DATE:(createdAt)<' => $from,
'OR' => [
'status!=' => WebhookQueueItem::STATUS_PENDING,
Attribute::DELETED => true,
],
])
->build();
$this->entityManager->getQueryExecutor()->execute($query1);
$query2 = $this->entityManager
->getQueryBuilder()
->delete()
->from(WebhookEventQueueItem::ENTITY_TYPE)
->where([
'DATE:(createdAt)<' => $from,
'OR' => [
'isProcessed' => true,
Attribute::DELETED => true,
],
])
->build();
$this->entityManager->getQueryExecutor()->execute($query2);
}
}

View File

@@ -0,0 +1,66 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\ConsoleCommands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Utils\System;
use Espo\Core\Utils\Util;
/**
* @noinspection PhpUnused
*/
class CheckFilePermissions implements Command
{
public function __construct(
private FileManager $fileManager,
private System $system
) {}
public function run(Params $params, IO $io): void
{
$io->writeLine("\nNote: Run this command under the web server user.\n");
$io->writeLine('Writable:');
$io->writeLine('');
foreach ($this->fileManager->getPermissionUtils()->getWritableList() as $path) {
$fullPath = Util::concatPath($this->system->getRootDir(), $path);
$isWritable = $this->fileManager->isWritable($fullPath);
$msg = " " . ($isWritable ? "OK" : "FAIL") . " : $path";
$io->writeLine($msg);
}
}
}

View File

@@ -0,0 +1,103 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\ConsoleCommands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Core\Name\Field;
use Espo\Core\Utils\Config;
use Espo\Entities\User;
use Espo\ORM\EntityManager;
use RuntimeException;
class CreateAdminUser implements Command
{
public function __construct(
private EntityManager $entityManager,
private Config $config
) {}
public function run(Params $params, IO $io): void
{
$userName = $params->getArgument(0);
if (!$userName) {
$io->writeLine("A username must be specified as the first argument.");
$io->setExitStatus(1);
return;
}
/** @var ?string $regExp */
$regExp = $this->config->get('userNameRegularExpression');
if (!$regExp) {
throw new RuntimeException("No `userNameRegularExpression` in config.");
}
if (
str_contains($userName, ' ') ||
preg_replace("/{$regExp}/", '_', $userName) !== $userName
) {
$io->writeLine("Not allowed username.");
$io->setExitStatus(1);
return;
}
$repository = $this->entityManager->getRDBRepositoryByClass(User::class);
$existingUser = $repository
->where(['userName' => $userName])
->findOne();
if ($existingUser) {
$io->writeLine("A user with the same username already exists.");
$io->setExitStatus(1);
return;
}
$user = $repository->getNew();
$user->set('userName', $userName);
$user->set('type', User::TYPE_ADMIN);
$user->set(Field::NAME, $userName);
$repository->save($user);
$message = "The user '{$userName}' has been created. " .
"Set password with the command: `bin/command set-password {$userName}`.";
$io->writeLine($message);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\ConsoleCommands;
use Espo\Tools\Import\Service;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Throwable;
class Import implements Command
{
public function __construct(private Service $service, private FileManager $fileManager)
{}
public function run(Params $params, IO $io) : void
{
$id = $params->getOption('id');
$filePath = $params->getOption('file');
$paramsId = $params->getOption('paramsId');
$forceResume = $params->hasFlag('resume');
$revert = $params->hasFlag('revert');
if (!$id && $filePath) {
if (!$paramsId) {
$io->writeLine("You need to specify --params-id option.");
return;
}
if (!$this->fileManager->isFile($filePath)) {
$io->writeLine("File not found.");
return;
}
$contents = $this->fileManager->getContents($filePath);
try {
$result = $this->service->importContentsWithParamsId($contents, $paramsId);
$resultId = $result->getId();
$countCreated = $result->getCountCreated();
$countUpdated = $result->getCountUpdated();
$countError = $result->getCountError();
$countDuplicate = $result->getCountDuplicate();
} catch (Throwable $e) {
$io->writeLine("Error occurred: " . $e->getMessage());
return;
}
$io->writeLine("Finished.");
$io->writeLine(" Import ID: {$resultId}");
$io->writeLine(" Created: {$countCreated}");
$io->writeLine(" Updated: {$countUpdated}");
$io->writeLine(" Duplicates: {$countDuplicate}");
$io->writeLine(" Errors: {$countError}");
return;
}
if ($id && $revert) {
$io->writeLine("Reverting import...");
try {
$this->service->revert($id);
} catch (Throwable $e) {
$io->writeLine("Error occurred: " . $e->getMessage());
return;
}
$io->writeLine("Finished.");
return;
}
if ($id) {
$io->writeLine("Running import, this may take a while...");
try {
$result = $this->service->importById($id, true, $forceResume);
} catch (Throwable $e) {
$io->writeLine("Error occurred: " . $e->getMessage());
return;
}
$countCreated = $result->getCountCreated();
$countUpdated = $result->getCountUpdated();
$countError = $result->getCountError();
$countDuplicate = $result->getCountDuplicate();
$io->writeLine("Finished.");
$io->writeLine(" Created: {$countCreated}");
$io->writeLine(" Updated: {$countUpdated}");
$io->writeLine(" Duplicates: {$countDuplicate}");
$io->writeLine(" Errors: {$countError}");
return;
}
$io->writeLine("Not enough params passed.");
}
}

View File

@@ -0,0 +1,108 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\ConsoleCommands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Core\Exceptions\Error;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Entities\ArrayValue;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Repositories\ArrayValue as ArrayValueRepository;
class PopulateArrayValues implements Command
{
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
/**
* @throws Error
*/
public function run(Params $params, IO $io): void
{
$entityType = $params->getArgument(0);
$field = $params->getArgument(1);
if (!$entityType || !$field) {
throw new Error("Entity type and field should be passed as arguments.");
}
if (!$this->entityManager->hasRepository($entityType)) {
throw new Error("Bad entity type.");
}
$defs = $this->entityManager->getDefs()->getEntity($entityType);
if (!$defs->hasAttribute($field)) {
throw new Error("Bad field.");
}
if ($defs->getAttribute($field)->getType() !== Entity::JSON_ARRAY) {
throw new Error("Non-array field.");
}
if ($defs->getAttribute($field)->isNotStorable()) {
throw new Error("Not-storable field.");
}
if (!$defs->getAttribute($field)->getParam('storeArrayValues')) {
throw new Error("Array values disabled for the field..");
}
$collection = $this->entityManager
->getRDBRepository($entityType)
->sth()
->find();
/** @var ArrayValueRepository $repository */
$repository = $this->entityManager->getRepository(ArrayValue::ENTITY_TYPE);
foreach ($collection as $i => $entity) {
if (!$entity instanceof CoreEntity) {
throw new Error();
}
$repository->storeEntityAttribute($entity, $field);
if ($i % 1000 === 0) {
$io->write('.');
}
}
$io->writeLine('');
$io->writeLine('Done.');
}
}

View File

@@ -0,0 +1,116 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\ConsoleCommands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\Exceptions\ArgumentNotSpecified;
use Espo\Core\Console\Exceptions\InvalidArgument;
use Espo\Core\Console\IO;
use Espo\Core\Exceptions\Error;
use Espo\Core\FieldProcessing\NextNumber\Processor;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\ORM\Repository\Option\SaveOption;
use Espo\ORM\EntityManager;
use Espo\ORM\Query\Part\Order;
class PopulateNumbers implements Command
{
private Processor $beforeSaveProcessor;
private EntityManager $entityManager;
public function __construct(
Processor $beforeSaveProcessor,
EntityManager $entityManager
) {
$this->beforeSaveProcessor = $beforeSaveProcessor;
$this->entityManager = $entityManager;
}
/**
* @throws Error
*/
public function run(Params $params, IO $io): void
{
$entityType = $params->getArgument(0);
$field = $params->getArgument(1);
$orderBy = $params->getOption('orderBy') ?? Field::CREATED_AT;
$order = strtoupper($params->getOption('order') ?? Order::ASC);
if (!$entityType) {
throw new ArgumentNotSpecified("No entity type argument.");
}
if (!$field) {
throw new ArgumentNotSpecified("No field argument.");
}
if ($order !== Order::ASC && $order !== Order::DESC) {
throw new InvalidArgument("Bad order option.");
}
$fieldType = $this->entityManager
->getDefs()
->getEntity($entityType)
->getField($field)
->getType();
if ($fieldType !== 'number') {
throw new InvalidArgument("Field `{$field}` is not of `number` type.");
}
$collection = $this->entityManager
->getRDBRepository($entityType)
->where([
$field => null,
])
->order($orderBy, $order)
->sth()
->find();
foreach ($collection as $i => $entity) {
if (!$entity instanceof CoreEntity) {
throw new Error();
}
$this->beforeSaveProcessor->processPopulate($entity, $field);
$this->entityManager->saveEntity($entity, [SaveOption::IMPORT => true]);
if ($i % 1000 === 0) {
$io->write('.');
}
}
$io->writeLine('');
$io->writeLine('Done.');
}
}

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\ConsoleCommands;
use Espo\Core\Console\Command;
use Espo\Core\Console\Command\Params;
use Espo\Core\Console\IO;
use Espo\Tools\CategoryTree\RebuildPaths;
use Exception;
class RebuildCategoryPaths implements Command
{
private RebuildPaths $rebuildPaths;
public function __construct(RebuildPaths $rebuildPaths)
{
$this->rebuildPaths = $rebuildPaths;
}
public function run(Params $params, IO $io): void
{
$entityType = $params->getArgument(0);
if (!$entityType) {
$io->setExitStatus(1);
$io->writeLine("Error: No entity type. Should be specified as the first argument.");
return;
}
try {
$this->rebuildPaths->run($entityType);
} catch (Exception $e) {
$io->setExitStatus(1);
$io->writeLine("Error: " . $e->getMessage());
return;
}
$io->writeLine("Done.");
}
}

View File

@@ -0,0 +1,85 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\DefaultLayouts;
use Espo\Core\Name\Field;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Metadata;
use Espo\Entities\Team;
use Espo\Entities\User;
use Espo\ORM\Defs\Params\FieldParam;
use Espo\ORM\Defs\Params\RelationParam;
use stdClass;
class DefaultSidePanelType
{
public function __construct(private Metadata $metadata)
{}
/**
* @return stdClass[]
*/
public function get(string $scope): array
{
$list = [];
if (
$this->metadata->get(['entityDefs', $scope, 'fields', Field::ASSIGNED_USER, FieldParam::TYPE]) ===
FieldType::LINK &&
$this->metadata->get(['entityDefs', $scope, 'links', Field::ASSIGNED_USER, RelationParam::ENTITY]) ===
User::ENTITY_TYPE
||
$this->metadata->get(['entityDefs', $scope, 'fields', Field::ASSIGNED_USERS, FieldParam::TYPE]) ===
FieldType::LINK_MULTIPLE &&
$this->metadata->get(['entityDefs', $scope, 'links', Field::ASSIGNED_USERS, RelationParam::ENTITY]) ===
User::ENTITY_TYPE
) {
$list[] = (object) ['name' => ':assignedUser'];
}
if (
$this->metadata->get(['entityDefs', $scope, 'fields', Field::TEAMS, FieldParam::TYPE]) ===
FieldType::LINK_MULTIPLE &&
$this->metadata->get(['entityDefs', $scope, 'links', Field::TEAMS, RelationParam::ENTITY]) ===
Team::ENTITY_TYPE
) {
$list[] = (object) ['name' => Field::TEAMS];
}
if (
$this->metadata->get("entityDefs.$scope.fields.collaborators.type") === FieldType::LINK_MULTIPLE &&
$this->metadata->get("entityDefs.$scope.links.collaborators.entity") === User::ENTITY_TYPE
) {
$list[] = (object) ['name' => Field::COLLABORATORS];
}
return $list;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\DuplicateWhereBuilders;
class Company extends General
{}

View File

@@ -0,0 +1,275 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\DuplicateWhereBuilders;
use Espo\Core\Duplicate\WhereBuilder;
use Espo\Core\Field\EmailAddressGroup;
use Espo\Core\Field\PhoneNumberGroup;
use Espo\Core\ORM\Entity as CoreEntity;
use Espo\Core\ORM\Type\FieldType;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Metadata;
use Espo\ORM\Defs;
use Espo\ORM\Entity;
use Espo\ORM\Query\Part\Condition as Cond;
use Espo\ORM\Query\Part\Where\OrGroup;
use Espo\ORM\Query\Part\Where\OrGroupBuilder;
use Espo\ORM\Query\Part\WhereItem;
use Espo\ORM\Type\AttributeType;
/**
* @implements WhereBuilder<CoreEntity>
*/
class General implements WhereBuilder
{
public function __construct(
private Metadata $metadata,
private Defs $ormDefs,
private Config $config
) {}
/**
* @param CoreEntity $entity
*/
public function build(Entity $entity): ?WhereItem
{
/** @var string[] $fieldList */
$fieldList = $this->metadata->get(['scopes', $entity->getEntityType(), 'duplicateCheckFieldList']) ?? [];
$orBuilder = OrGroup::createBuilder();
$toCheck = false;
foreach ($fieldList as $field) {
$toCheckItem = $this->applyField($field, $entity, $orBuilder);
if ($toCheckItem) {
$toCheck = true;
}
}
if (!$toCheck) {
return null;
}
return $orBuilder->build();
}
private function applyField(
string $field,
CoreEntity $entity,
OrGroupBuilder $orBuilder
): bool {
$type = $this->ormDefs
->getEntity($entity->getEntityType())
->tryGetField($field)
?->getType();
if ($type === FieldType::PERSON_NAME) {
return $this->applyFieldPersonName($field, $entity, $orBuilder);
}
if ($type === FieldType::EMAIL) {
return $this->applyFieldEmail($field, $entity, $orBuilder);
}
if ($type === FieldType::PHONE) {
return $this->applyFieldPhone($field, $entity, $orBuilder);
}
if ($entity->getAttributeType($field) === AttributeType::VARCHAR) {
return $this->applyFieldVarchar($field, $entity, $orBuilder);
}
return false;
}
private function applyFieldPersonName(
string $field,
CoreEntity $entity,
OrGroupBuilder $orBuilder
): bool {
$first = 'first' . ucfirst($field);
$last = 'last' . ucfirst($field);
if (!$entity->get($first) && !$entity->get($last)) {
return false;
}
$orBuilder->add(
Cond::and(
Cond::equal(
Cond::column($first),
$entity->get($first)
),
Cond::equal(
Cond::column($last),
$entity->get($last)
)
)
);
return true;
}
private function applyFieldEmail(
string $field,
CoreEntity $entity,
OrGroupBuilder $orBuilder
): bool {
$toCheck = false;
if (
($entity->get($field) || $entity->get($field . 'Data')) &&
(
$entity->isNew() ||
$entity->isAttributeChanged($field) ||
$entity->isAttributeChanged($field . 'Data')
)
) {
foreach ($this->getEmailAddressList($entity) as $emailAddress) {
$orBuilder->add(
Cond::equal(
Cond::column($field),
$emailAddress
)
);
$toCheck = true;
}
}
return $toCheck;
}
private function applyFieldPhone(
string $field,
CoreEntity $entity,
OrGroupBuilder $orBuilder
): bool {
$toCheck = false;
$isNumeric = $this->config->get('phoneNumberNumericSearch');
$column = $isNumeric ?
$field . 'Numeric' :
$field;
if (
($entity->get($field) || $entity->get($field . 'Data')) &&
(
$entity->isNew() ||
$entity->isAttributeChanged($field) ||
$entity->isAttributeChanged($field . 'Data')
)
) {
foreach ($this->getPhoneNumberList($entity) as $number) {
if ($isNumeric) {
$number = preg_replace('/[^0-9]/', '', $number);
}
$orBuilder->add(
Cond::equal(
Cond::column($column),
$number
)
);
$toCheck = true;
}
}
return $toCheck;
}
private function applyFieldVarchar(
string $field,
CoreEntity $entity,
OrGroupBuilder $orBuilder
): bool {
if (!$entity->get($field)) {
return false;
}
$orBuilder->add(
Cond::equal(
Cond::column($field),
$entity->get($field)
),
);
return true;
}
/**
* @return string[]
*/
private function getEmailAddressList(CoreEntity $entity): array
{
if ($entity->get('emailAddressData')) {
/** @var EmailAddressGroup $eaGroup */
$eaGroup = $entity->getValueObject('emailAddress');
return $eaGroup->getAddressList();
}
if ($entity->get('emailAddress')) {
return [
$entity->get('emailAddress')
];
}
return [];
}
/**
* @return string[]
*/
private function getPhoneNumberList(CoreEntity $entity): array
{
if ($entity->get('phoneNumberData')) {
/** @var PhoneNumberGroup $eaGroup */
$eaGroup = $entity->getValueObject('phoneNumber');
return $eaGroup->getNumberList();
}
if ($entity->get('phoneNumber')) {
return [$entity->get('phoneNumber')];
}
return [];
}
}

View File

@@ -0,0 +1,55 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\DuplicateWhereBuilders;
use Espo\Core\Duplicate\WhereBuilder;
use Espo\Core\Name\Field;
use Espo\ORM\Entity;
use Espo\ORM\Query\Part\Condition as Cond;
use Espo\ORM\Query\Part\WhereItem;
/**
* @implements WhereBuilder<Entity>
*/
class Name implements WhereBuilder
{
public function build(Entity $entity): ?WhereItem
{
if ($entity->get(Field::NAME)) {
return Cond::equal(
Cond::column(Field::NAME),
$entity->get(Field::NAME)
);
}
return null;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\DuplicateWhereBuilders;
class Person extends General
{}

View File

@@ -0,0 +1,201 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldConverters;
use Espo\Core\Utils\Database\Orm\Defs\AttributeDefs;
use Espo\Core\Utils\Database\Orm\Defs\EntityDefs;
use Espo\Core\Utils\Database\Orm\FieldConverter;
use Espo\ORM\Defs\FieldDefs;
use Espo\ORM\Defs\Params\RelationParam;
use Espo\ORM\Name\Attribute;
use Espo\ORM\Type\AttributeType;
use RuntimeException;
class RelationshipRole implements FieldConverter
{
public function convert(FieldDefs $fieldDefs, string $entityType): EntityDefs
{
$name = $fieldDefs->getName();
$attributeDefs = AttributeDefs::create($name)
->withType(AttributeType::VARCHAR)
->withNotStorable();
$attributeDefs = $this->addWhere($attributeDefs, $fieldDefs, $entityType);
return EntityDefs::create()
->withAttribute($attributeDefs);
}
private function addWhere(AttributeDefs $attributeDefs, FieldDefs $fieldDefs, string $entityType): AttributeDefs
{
$data = $fieldDefs->getParam('converterData');
if (!is_array($data)) {
throw new RuntimeException("No `converterData` in field defs.");
}
/** @var ?string $column */
$column = $data['column'] ?? null;
/** @var ?string $link */
$link = $data['link'] ?? null;
/** @var ?string $relationName */
$relationName = $data[RelationParam::RELATION_NAME] ?? null;
/** @var ?string $nearKey */
$nearKey = $data['nearKey'] ?? null;
if (!$column || !$link || !$relationName || !$nearKey) {
throw new RuntimeException("Bad `converterData`.");
}
$midTable = ucfirst($relationName);
return $attributeDefs->withParamsMerged([
'where' => [
'=' => [
'whereClause' => [
'id=s' => [
'from' => $midTable,
'select' => [$nearKey],
'whereClause' => [
Attribute::DELETED => false,
$column => '{value}',
],
],
],
],
'<>' => [
'whereClause' => [
'id!=s' => [
'from' => $midTable,
'select' => [$nearKey],
'whereClause' => [
Attribute::DELETED => false,
$column => '{value}',
],
],
],
],
'IN' => [
'whereClause' => [
'id=s' => [
'from' => $midTable,
'select' => [$nearKey],
'whereClause' => [
Attribute::DELETED => false,
$column => '{value}',
],
],
],
],
'NOT IN' => [
'whereClause' => [
'id!=s' => [
'from' => $midTable,
'select' => [$nearKey],
'whereClause' => [
Attribute::DELETED => false,
$column => '{value}',
],
],
],
],
'LIKE' => [
'whereClause' => [
'id=s' => [
'from' => $midTable,
'select' => [$nearKey],
'whereClause' => [
Attribute::DELETED => false,
"$column*" => '{value}',
],
],
],
],
'NOT LIKE' => [
'whereClause' => [
'id!=s' => [
'from' => $midTable,
'select' => [$nearKey],
'whereClause' => [
Attribute::DELETED => false,
"$column*" => '{value}',
],
],
],
],
'IS NULL' => [
'whereClause' => [
'NOT' => [
'EXISTS' => [
'from' => $entityType,
'fromAlias' => 'sq',
'select' => [Attribute::ID],
'leftJoins' => [
[
$link,
'm',
null,
['onlyMiddle' => true]
]
],
'whereClause' => [
"m.$column!=" => null,
'sq.id:' => lcfirst($entityType) . '.id',
],
],
],
],
],
'IS NOT NULL' => [
'whereClause' => [
'EXISTS' => [
'from' => $entityType,
'fromAlias' => 'sq',
'select' => [Attribute::ID],
'leftJoins' => [
[
$link,
'm',
null,
['onlyMiddle' => true]
]
],
'whereClause' => [
"m.$column!=" => null,
'sq.id:' => lcfirst($entityType) . '.id',
],
],
],
],
],
]);
}
}

View File

@@ -0,0 +1,90 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldDuplicators;
use Espo\Core\Record\Duplicator\FieldDuplicator;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Repositories\Attachment as AttachmentRepository;
use Espo\Entities\Attachment;
use stdClass;
class AttachmentMultiple implements FieldDuplicator
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function duplicate(Entity $entity, string $field): stdClass
{
$valueMap = (object) [];
/** @var \Espo\ORM\Collection<Attachment> $attachmentList */
$attachmentList = $this->entityManager
->getRDBRepository($entity->getEntityType())
->getRelation($entity, $field)
->find();
if (is_countable($attachmentList) && !count($attachmentList)) {
return $valueMap;
}
$idList = [];
$nameHash = (object) [];
$typeHash = (object) [];
/** @var AttachmentRepository $attachmentRepository */
$attachmentRepository = $this->entityManager->getRepository(Attachment::ENTITY_TYPE);
foreach ($attachmentList as $attachment) {
$copiedAttachment = $attachmentRepository->getCopiedAttachment($attachment);
$copiedAttachment->set('field', $field);
$this->entityManager->saveEntity($copiedAttachment);
$idList[] = $copiedAttachment->getId();
$nameHash->{$copiedAttachment->getId()} = $copiedAttachment->getName();
$typeHash->{$copiedAttachment->getId()} = $copiedAttachment->getType();
}
$valueMap->{$field . 'Ids'} = $idList;
$valueMap->{$field . 'Names'} = $nameHash;
$valueMap->{$field . 'Types'} = $typeHash;
return $valueMap;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldDuplicators;
use Espo\Core\Record\Duplicator\FieldDuplicator;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Repositories\Attachment as AttachmentRepository;
use Espo\Entities\Attachment;
use stdClass;
class File implements FieldDuplicator
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function duplicate(Entity $entity, string $field): stdClass
{
$valueMap = (object) [];
/** @var Attachment|null $attachment */
$attachment = $this->entityManager
->getRDBRepository($entity->getEntityType())
->getRelation($entity, $field)
->findOne();
if (!$attachment) {
return $valueMap;
}
/** @var AttachmentRepository $attachmentRepository */
$attachmentRepository = $this->entityManager->getRepository(Attachment::ENTITY_TYPE);
$copiedAttachment = $attachmentRepository->getCopiedAttachment($attachment);
$idAttribute = $field . 'Id';
$valueMap->$idAttribute = $copiedAttachment->getId();
return $valueMap;
}
}

View File

@@ -0,0 +1,82 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldDuplicators;
use Espo\Core\Record\Duplicator\FieldDuplicator;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use stdClass;
class LinkMultiple implements FieldDuplicator
{
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function duplicate(Entity $entity, string $field): stdClass
{
$valueMap = (object) [];
$entityDefs = $this->entityManager
->getDefs()
->getEntity($entity->getEntityType());
if (!$entity->hasRelation($field)) {
return $valueMap;
}
$relationDefs = $entityDefs->getRelation($field);
if (
!$relationDefs->hasForeignEntityType() ||
!$relationDefs->hasForeignRelationName()
) {
return $valueMap;
}
$foreignRelationType = $this->entityManager
->getDefs()
->getEntity($relationDefs->getForeignEntityType())
->getRelation($relationDefs->getForeignRelationName())
->getType();
if ($foreignRelationType !== Entity::MANY_MANY) {
$valueMap->{$field . 'Ids'} = [];
$valueMap->{$field . 'Names'} = (object) [];
$valueMap->{$field . 'Columns'} = (object) [];
}
return $valueMap;
}
}

View File

@@ -0,0 +1,117 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldDuplicators;
use Espo\Core\Record\Duplicator\FieldDuplicator;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Repositories\Attachment as AttachmentRepository;
use Espo\Entities\Attachment;
use stdClass;
class Wysiwyg implements FieldDuplicator
{
private $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function duplicate(Entity $entity, string $field): stdClass
{
$valueMap = (object) [];
$contents = $entity->get($field);
if (!$contents) {
return $valueMap;
}
$matches = [];
$matchResult = preg_match_all("/\?entryPoint=attachment&amp;id=([^&=\"']+)/", $contents, $matches);
if (
!$matchResult ||
empty($matches[1]) ||
!is_array($matches[1])
) {
return $valueMap;
}
$attachmentIdList = $matches[1];
/** @var Attachment[] $attachmentList */
$attachmentList = [];
foreach ($attachmentIdList as $id) {
/** @var Attachment|null $attachment */
$attachment = $this->entityManager->getEntityById(Attachment::ENTITY_TYPE, $id);
if (!$attachment) {
continue;
}
$attachmentList[] = $attachment;
}
if (!count($attachmentList)) {
return $valueMap;
}
/** @var AttachmentRepository $attachmentRepository */
$attachmentRepository = $this->entityManager->getRepository(Attachment::ENTITY_TYPE);
foreach ($attachmentList as $attachment) {
$copiedAttachment = $attachmentRepository->getCopiedAttachment($attachment);
$copiedAttachment->set([
'relatedId' => null,
'relatedType' => $entity->getEntityType(),
'field' => $field,
]);
$this->entityManager->saveEntity($copiedAttachment);
$contents = str_replace(
'?entryPoint=attachment&amp;id=' . $attachment->getId(),
'?entryPoint=attachment&amp;id=' . $copiedAttachment->getId(),
$contents
);
}
$valueMap->$field = $contents;
return $valueMap;
}
}

View File

@@ -0,0 +1,63 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\CurrencyRecord;
use Espo\Core\Currency\ConfigDataProvider;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\CurrencyRecord;
use Espo\ORM\Entity;
use ValueError;
/**
* @implements Loader<CurrencyRecord>
*/
class IsBase implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
try {
$code = $entity->getCode();
} catch (ValueError) {
$entity->setIsBase(false);
return;
}
$isBase = $code === $this->configDataProvider->getBaseCurrency();
$entity->setIsBase($isBase);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\CurrencyRecord;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Utils\Language;
use Espo\Entities\CurrencyRecord;
use Espo\ORM\Entity;
use ValueError;
/**
* @implements Loader<CurrencyRecord>
*/
class Label implements Loader
{
public function __construct(
private Language $defaultLanguage
) {}
public function process(Entity $entity, Params $params): void
{
try {
$code = $entity->getCode();
} catch (ValueError) {
return;
}
$name = $this->defaultLanguage->translateLabel($code, 'names', 'Currency');
$entity->setLabel($name);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\CurrencyRecord;
use Espo\Core\Currency\ConfigDataProvider;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\CurrencyRecord;
use Espo\ORM\Entity;
use Espo\Tools\Currency\RateEntryProvider;
/**
* @implements Loader<CurrencyRecord>
*/
class Rate implements Loader
{
public function __construct(
private RateEntryProvider $rateEntryProvider,
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
$rate = $entity->getCode() !== $this->configDataProvider->getBaseCurrency() ?
$this->rateEntryProvider->getCurrentRateEntry($entity)?->getRate() :
'1';
$entity->setRate($rate);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\CurrencyRecord;
use Espo\Core\Currency\ConfigDataProvider;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\CurrencyRecord;
use Espo\ORM\Entity;
use Espo\Tools\Currency\RateEntryProvider;
/**
* @implements Loader<CurrencyRecord>
*/
class RateDate implements Loader
{
public function __construct(
private RateEntryProvider $rateEntryProvider,
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
$date = $entity->getCode() !== $this->configDataProvider->getBaseCurrency() ?
$this->rateEntryProvider->getCurrentRateEntry($entity)?->getDate() :
null;
$entity->setRateDate($date);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\CurrencyRecord;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Utils\Metadata;
use Espo\Entities\CurrencyRecord;
use Espo\ORM\Entity;
use ValueError;
/**
* @implements Loader<CurrencyRecord>
*/
class Symbol implements Loader
{
public function __construct(
private Metadata $metadata,
) {}
public function process(Entity $entity, Params $params): void
{
try {
$code = $entity->getCode();
} catch (ValueError) {
return;
}
$symbol = $this->metadata->get("app.currency.symbolMap.$code");
$entity->setSymbol($symbol);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Email;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Repositories\Email as EmailRepository;
use Espo\Entities\Email;
/**
* @implements Loader<Email>
*/
class AddressDataLoader implements Loader
{
public function __construct(private EntityManager $entityManager)
{}
/**
* @param Email $entity
*/
public function process(Entity $entity, Params $params): void
{
/** @var EmailRepository $repository */
$repository = $this->entityManager->getRepository(Email::ENTITY_TYPE);
$repository->loadNameHash($entity);
}
}

View File

@@ -0,0 +1,60 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Email;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Entities\Email;
use Espo\ORM\Entity;
use Espo\Repositories\Email as EmailRepository;
/**
* @implements Loader<Email>
*/
class AddressLoader implements Loader
{
public function __construct(private EntityManager $entityManager)
{}
/**
* @inheritDoc
*/
public function process(Entity $entity, Params $params): void
{
/** @var EmailRepository $repository */
$repository = $this->entityManager->getRepository(Email::ENTITY_TYPE);
$repository->loadFromField($entity);
$repository->loadToField($entity);
$repository->loadCcField($entity);
$repository->loadBccField($entity);
$repository->loadReplyToField($entity);
}
}

View File

@@ -0,0 +1,67 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Email;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\Email;
use Espo\Entities\EmailFolder;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
/**
* @implements Loader<Email>
*/
class FolderDataLoader implements Loader
{
public function __construct(private EntityManager $entityManager) {}
public function process(Entity $entity, Params $params): void
{
$folderId = $entity->get(Email::USERS_COLUMN_FOLDER_ID);
if (!$folderId) {
return;
}
$folder = $this->entityManager
->getRDBRepositoryByClass(EmailFolder::class)
->select([Attribute::ID, 'name'])
->where([Attribute::ID => $folderId])
->findOne();
if (!$folder) {
return;
}
$entity->set('folderName', $folder->getName());
}
}

View File

@@ -0,0 +1,239 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Email;
use Espo\Core\Name\Field;
use Espo\Entities\User;
use Espo\Modules\Crm\Entities\Call;
use Espo\Modules\Crm\Entities\Contact;
use Espo\Modules\Crm\Entities\Lead;
use Espo\Modules\Crm\Entities\Meeting;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Name\Attribute;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Entities\EmailAddress;
use Espo\Entities\Email;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Mail\Event\Event as EspoEvent;
use Espo\Core\Mail\Event\EventFactory;
use Espo\Core\Utils\Log;
use ICal\Event;
use ICal\ICal;
use Throwable;
use stdClass;
/**
* @implements Loader<Email>
*/
class IcsDataLoader implements Loader
{
/** @var array<string, string> */
private $entityTypeLinkMap = [
User::ENTITY_TYPE => Meeting::LINK_USERS,
Contact::ENTITY_TYPE => Meeting::LINK_CONTACTS,
Lead::ENTITY_TYPE => Meeting::LINK_LEADS,
];
public function __construct(private EntityManager $entityManager, private Log $log)
{}
public function process(Entity $entity, Params $params): void
{
$icsContents = $entity->get('icsContents');
if ($icsContents === null) {
return;
}
$ical = new ICal();
$ical->initString($icsContents);
/* @var ?Event $event */
$event = $ical->events()[0] ?? null;
if ($event === null) {
return;
}
if ($event->status === 'CANCELLED') {
return;
}
$espoEvent = EventFactory::createFromU01jmg3Ical($ical);
$valueMap = (object) [
'sourceEmailId' => $entity->getId(),
];
try {
$valueMap->name = $espoEvent->getName();
$valueMap->description = $espoEvent->getDescription();
$valueMap->dateStart = $espoEvent->getDateStart();
$valueMap->dateEnd = $espoEvent->getDateEnd();
$valueMap->location = $espoEvent->getLocation();
$valueMap->isAllDay = $espoEvent->isAllDay();
if ($espoEvent->isAllDay()) {
$valueMap->dateStartDate = $espoEvent->getDateStart();
$valueMap->dateEndDate = $espoEvent->getDateEnd();
}
} catch (Throwable $e) {
$this->log->warning("Error while converting ICS event '" . $entity->getId() . "': " . $e->getMessage());
return;
}
if ($this->eventAlreadyExists($espoEvent)) {
return;
}
/** @var EmailAddressRepository $emailAddressRepository */
$emailAddressRepository = $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
$attendeeEmailAddressList = $espoEvent->getAttendeeEmailAddressList();
$organizerEmailAddress = $espoEvent->getOrganizerEmailAddress();
if ($organizerEmailAddress) {
$attendeeEmailAddressList[] = $organizerEmailAddress;
}
foreach ($attendeeEmailAddressList as $address) {
$personEntity = $emailAddressRepository->getEntityByAddress($address);
if (!$personEntity) {
continue;
}
$link = $this->entityTypeLinkMap[$personEntity->getEntityType()] ?? null;
if (!$link) {
continue;
}
$idsAttribute = $link . 'Ids';
$namesAttribute = $link . 'Names';
$idList = $valueMap->$idsAttribute ?? [];
$nameMap = $valueMap->$namesAttribute ?? (object) [];
$idList[] = $personEntity->getId();
$nameMap->{$personEntity->getId()} = $personEntity->get(Field::NAME);
$valueMap->$idsAttribute = $idList;
$valueMap->$namesAttribute = $nameMap;
}
$eventData = (object) [
'valueMap' => $valueMap,
'uid' => $espoEvent->getUid(),
'createdEvent' => null,
];
$this->loadCreatedEvent($entity, $espoEvent, $eventData);
$entity->set('icsEventData', $eventData);
$entity->set('icsEventDateStart', $espoEvent->getDateStart());
if ($espoEvent->isAllDay()) {
$entity->set('icsEventDateStartDate', $espoEvent->getDateStart());
}
}
private function loadCreatedEvent(Entity $entity, EspoEvent $espoEvent, stdClass $eventData): void
{
$emailSameEvent = $this->entityManager
->getRDBRepository(Email::ENTITY_TYPE)
->where([
'icsEventUid' => $espoEvent->getUid(),
'id!=' => $entity->getId()
])
->findOne();
if (!$emailSameEvent) {
return;
}
if (
!$emailSameEvent->get('createdEventId') ||
!$emailSameEvent->get('createdEventType')
) {
return;
}
$createdEvent = $this->entityManager
->getEntityById($emailSameEvent->get('createdEventType'), $emailSameEvent->get('createdEventId'));
if (!$createdEvent) {
return;
}
$eventData->createdEvent = (object) [
'id' => $createdEvent->getId(),
'entityType' => $emailSameEvent->getEntityType(),
'name' => $createdEvent->get(Field::NAME),
];
}
private function eventAlreadyExists(EspoEvent $espoEvent): bool
{
$id = $espoEvent->getUid();
if (!$id) {
return false;
}
$found1 = $this->entityManager
->getRDBRepository(Meeting::ENTITY_TYPE)
->select([Attribute::ID])
->where([Attribute::ID => $id])
->findOne();
if ($found1) {
return true;
}
$found2 = $this->entityManager
->getRDBRepository(Call::ENTITY_TYPE)
->select([Attribute::ID])
->where([Attribute::ID => $id])
->findOne();
if ($found2) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,128 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Email;
use Espo\Core\Name\Field;
use Espo\Core\Name\Link;
use Espo\ORM\Entity;
use Espo\ORM\Name\Attribute;
use Espo\Repositories\EmailAddress as EmailAddressRepository;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Entities\Email;
use Espo\Entities\User;
/**
* @implements Loader<Email>
*/
class StringDataLoader implements Loader
{
private const LINK_EMAIL_ADDRESSES = Link::EMAIL_ADDRESSES;
/** @var array<string, string> */
private $fromEmailAddressNameCache = [];
public function __construct(
private EntityManager $entityManager,
private User $user
) {}
public function process(Entity $entity, Params $params): void
{
/** @var Email $entity */
$userEmailAddressIdList = [];
$emailAddressCollection = $this->entityManager
->getRelation($this->user, self::LINK_EMAIL_ADDRESSES)
->select([Attribute::ID])
->find();
foreach ($emailAddressCollection as $emailAddress) {
$userEmailAddressIdList[] = $emailAddress->getId();
}
if (
in_array($entity->get('fromEmailAddressId'), $userEmailAddressIdList) ||
$entity->get('createdById') === $this->user->getId() &&
$entity->getStatus() === Email::STATUS_SENT
) {
$entity->loadLinkMultipleField('toEmailAddresses');
$idList = $entity->get('toEmailAddressesIds');
$names = $entity->get('toEmailAddressesNames');
if (empty($idList)) {
return;
}
$list = [];
foreach ($idList as $emailAddressId) {
$person = $this->getEmailAddressRepository()->getEntityByAddressId($emailAddressId, null, true);
$list[] = $person ? $person->get(Field::NAME) : $names->$emailAddressId;
}
$entity->set('personStringData', 'To: ' . implode(', ', $list));
return;
}
/** @var ?string $fromEmailAddressId */
$fromEmailAddressId = $entity->get('fromEmailAddressId');
if (!$fromEmailAddressId) {
return;
}
if (!array_key_exists($fromEmailAddressId, $this->fromEmailAddressNameCache)) {
$person = $this->getEmailAddressRepository()->getEntityByAddressId($fromEmailAddressId, null, true);
$fromName = $person?->get(Field::NAME);
$this->fromEmailAddressNameCache[$fromEmailAddressId] = $fromName;
}
$fromName =
$this->fromEmailAddressNameCache[$fromEmailAddressId] ??
$entity->get('fromName') ??
$entity->get('fromEmailAddressName');
$entity->set('personStringData', $fromName);
}
private function getEmailAddressRepository(): EmailAddressRepository
{
/** @var EmailAddressRepository */
return $this->entityManager->getRepository('EmailAddress');
}
}

View File

@@ -0,0 +1,90 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Email;
use Espo\Entities\Email;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Entities\User;
use Espo\ORM\Name\Attribute;
/**
* @implements Loader<Email>
*/
class UserColumnsLoader implements Loader
{
public function __construct(
private EntityManager $entityManager,
private User $user
) {}
public function process(Entity $entity, Params $params): void
{
$emailUser = $this->entityManager
->getRDBRepository(Email::RELATIONSHIP_EMAIL_USER)
->select([
Email::USERS_COLUMN_IS_READ,
Email::USERS_COLUMN_IS_IMPORTANT,
Email::USERS_COLUMN_IN_TRASH,
Email::USERS_COLUMN_IN_ARCHIVE,
])
->where([
Attribute::DELETED => false,
'userId' => $this->user->getId(),
'emailId' => $entity->getId(),
])
->findOne();
if (!$emailUser) {
$entity->set(Email::USERS_COLUMN_IS_READ, null);
$entity->clear(Email::USERS_COLUMN_IS_IMPORTANT);
$entity->clear(Email::USERS_COLUMN_IN_TRASH);
$entity->clear(Email::USERS_COLUMN_IN_ARCHIVE);
return;
}
$values = [
Email::USERS_COLUMN_IS_READ => $emailUser->get(Email::USERS_COLUMN_IS_READ),
Email::USERS_COLUMN_IS_IMPORTANT => $emailUser->get(Email::USERS_COLUMN_IS_IMPORTANT),
Email::USERS_COLUMN_IN_TRASH => $emailUser->get(Email::USERS_COLUMN_IN_TRASH),
Email::USERS_COLUMN_IN_ARCHIVE => $emailUser->get(Email::USERS_COLUMN_IN_ARCHIVE),
'isUsersSent' => $entity->getSentBy()?->getId() === $this->user->getId(),
];
$entity->setMultiple($values);
foreach ($values as $key => $value) {
$entity->setFetched($key, $value);
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Import;
use Espo\Entities\Import;
use Espo\ORM\Entity;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use Espo\Repositories\Import as ImportRepository;
/**
* @implements Loader<Import>
*/
class CountsLoader implements Loader
{
public function __construct(private EntityManager $entityManager)
{}
public function process(Entity $entity, Params $params): void
{
/** @var ImportRepository $repository */
$repository = $this->entityManager->getRepository('Import');
$importedCount = $repository->countResultRecords($entity, 'imported');
$duplicateCount = $repository->countResultRecords($entity, 'duplicates');
$updatedCount = $repository->countResultRecords($entity, 'updated');
$entity->set([
'importedCount' => $importedCount,
'duplicateCount' => $duplicateCount,
'updatedCount' => $updatedCount,
]);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\InboundEmail;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Mail\ConfigDataProvider;
use Espo\Entities\InboundEmail;
use Espo\ORM\Entity;
/**
* @implements Loader<InboundEmail>
*/
class IsSystemLoader implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
$isSystem = $entity->getEmailAddress() === $this->configDataProvider->getSystemOutboundAddress();
$entity->set('isSystem', $isSystem);
}
}

View File

@@ -0,0 +1,159 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\LeadCapture;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\Config\ApplicationConfig;
use Espo\Core\Utils\FieldUtil;
use Espo\Core\Utils\Util;
use Espo\Entities\LeadCapture;
use Espo\Modules\Crm\Entities\Lead;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\ORM\Type\AttributeType;
/**
* @implements Loader<LeadCapture>
*/
class ExampleLoader implements Loader
{
public function __construct(
private FieldUtil $fieldUtil,
private ApplicationConfig $applicationConfig,
private EntityManager $entityManager,
private Config $config,
) {}
public function process(Entity $entity, Params $params): void
{
$entity->set('exampleRequestMethod', 'POST');
$entity->set('exampleRequestHeaders', [
'Content-Type: application/json',
]);
$this->processRequestUrl($entity);
$this->processRequestPayload($entity);
$this->processFormUrl($entity);
}
private function processRequestUrl(LeadCapture $entity): void
{
$apiKey = $entity->getApiKey();
$siteUrl = $this->applicationConfig->getSiteUrl();
if (!$apiKey) {
return;
}
$requestUrl = "$siteUrl/api/v1/LeadCapture/$apiKey";
$entity->set('exampleRequestUrl', $requestUrl);
}
private function processRequestPayload(LeadCapture $entity): void
{
$requestPayload = "```\n{\n";
$attributeList = [];
$attributeIgnoreList = [
'emailAddressIsOptedOut',
'phoneNumberIsOptedOut',
'emailAddressIsInvalid',
'phoneNumberIsInvalid',
'emailAddressData',
'phoneNumberData',
];
foreach ($entity->getFieldList() as $field) {
foreach ($this->fieldUtil->getActualAttributeList(Lead::ENTITY_TYPE, $field) as $attribute) {
if (!in_array($attribute, $attributeIgnoreList)) {
$attributeList[] = $attribute;
}
}
}
$seed = $this->entityManager->getNewEntity(Lead::ENTITY_TYPE);
foreach ($attributeList as $i => $attribute) {
$value = strtoupper(Util::camelCaseToUnderscore($attribute));
if (
in_array(
$seed->getAttributeType($attribute), [
Entity::VARCHAR,
Entity::TEXT,
AttributeType::DATETIME,
AttributeType::DATE,
]
)
) {
$value = '"' . $value . '"';
}
$requestPayload .= " \"" . $attribute . "\": " . $value;
if ($i < count($attributeList) - 1) {
$requestPayload .= ",";
}
$requestPayload .= "\n";
}
$requestPayload .= "}\n```";
$entity->set('exampleRequestPayload', $requestPayload);
}
private function processFormUrl(LeadCapture $entity): void
{
$formId = $entity->getFormId();
$siteUrl = $this->getSiteUrl();
if (!$entity->hasFormEnabled() || !$formId) {
/** @noinspection PhpRedundantOptionalArgumentInspection */
$entity->set('formUrl', null);
return;
}
$formUrl = "$siteUrl?entryPoint=leadCaptureForm&id=$formId";
$entity->set('formUrl', $formUrl);
}
private function getSiteUrl(): string
{
return $this->config->get('leadCaptureSiteUrl') ?? $this->applicationConfig->getSiteUrl();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Note;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\Note;
use Espo\ORM\Entity;
use Espo\Tools\Stream\MassNotePreparator;
/**
* @implements Loader<Note>
*/
class AdditionalFieldsLoader implements Loader
{
public function __construct(
private MassNotePreparator $massNotePreparator,
) {}
public function process(Entity $entity, Params $params): void
{
$entity->loadAdditionalFields();
$this->massNotePreparator->prepare([$entity]);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\OAuthAccount;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\OAuthAccount;
use Espo\ORM\Entity;
use Espo\Tools\OAuth\ConfigDataProvider;
/**
* @implements Loader<OAuthAccount>
*/
class DataLoader implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
if (!$entity->get('providerId')) {
return;
}
$provider = $entity->getProvider();
$scope = null;
if ($provider->getScopes()) {
$scope = implode($provider->getScopeSeparator() ?? ' ', $provider->getScopes());
}
$data = [
'endpoint' => $provider->getAuthorizationEndpoint(),
'clientId' => $provider->getClientId(),
'redirectUri' => $this->configDataProvider->getRedirectUri(),
'scope' => $scope,
'prompt' => $provider->getAuthorizationPrompt(),
'params' => $provider->getAuthorizationParams(),
];
$entity->set('data', $data);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\OAuthProvider;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Entities\OAuthProvider;
use Espo\ORM\Entity;
use Espo\Tools\OAuth\ConfigDataProvider;
/**
* @implements Loader<OAuthProvider>
*/
class AuthorizationRedirectUriLoader implements Loader
{
public function __construct(
private ConfigDataProvider $configDataProvider,
) {}
public function process(Entity $entity, Params $params): void
{
$entity->set('authorizationRedirectUri', $this->configDataProvider->getRedirectUri());
}
}

View File

@@ -0,0 +1,64 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\Portal;
use Espo\ORM\Entity;
use Espo\Repositories\Portal as PortalRepository;
use Espo\Entities\Portal;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
/**
* @implements Loader<Portal>
*/
class UrlLoader implements Loader
{
private EntityManager $entityManager;
public function __construct(EntityManager $entityManager)
{
$this->entityManager = $entityManager;
}
public function process(Entity $entity, Params $params): void
{
/** @var Portal $entity */
$this->getPortalRepository()->loadUrlField($entity);
}
private function getPortalRepository(): PortalRepository
{
/** @var PortalRepository */
return $this->entityManager->getRepository('Portal');
}
}

View File

@@ -0,0 +1,112 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldProcessing\User;
use Espo\Core\Name\Field;
use Espo\Entities\AuthLogRecord;
use Espo\Entities\AuthToken;
use Espo\Entities\User;
use Espo\ORM\Entity;
use Espo\Core\Acl;
use Espo\Core\FieldProcessing\Loader;
use Espo\Core\FieldProcessing\Loader\Params;
use Espo\Core\ORM\EntityManager;
use DateTime;
use Espo\ORM\Name\Attribute;
use Exception;
/**
* @implements Loader<User>
* @noinspection PhpUnused
*/
class LastAccessLoader implements Loader
{
private EntityManager $entityManager;
private Acl $acl;
public function __construct(EntityManager $entityManager, Acl $acl)
{
$this->entityManager = $entityManager;
$this->acl = $acl;
}
public function process(Entity $entity, Params $params): void
{
if (!$this->acl->checkField($entity->getEntityType(), 'lastAccess')) {
return;
}
$authToken = $this->entityManager
->getRDBRepository(AuthToken::ENTITY_TYPE)
->select([Attribute::ID, 'lastAccess'])
->where([
'userId' => $entity->getId(),
])
->order('lastAccess', 'DESC')
->findOne();
$lastAccess = null;
if ($authToken) {
$lastAccess = $authToken->get('lastAccess');
}
$dt = null;
if ($lastAccess) {
try {
$dt = new DateTime($lastAccess);
} catch (Exception) {}
}
$where = [
'userId' => $entity->getId(),
'isDenied' => false,
];
if ($dt) {
$where['requestTime>'] = $dt->format('U');
}
$authLogRecord = $this->entityManager
->getRDBRepository(AuthLogRecord::ENTITY_TYPE)
->select([Attribute::ID, Field::CREATED_AT])
->where($where)
->order('requestTime', true)
->findOne();
if ($authLogRecord) {
$lastAccess = $authLogRecord->get(Field::CREATED_AT);
}
$entity->set('lastAccess', $lastAccess);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldSanitizers;
use Espo\Core\FieldSanitize\Sanitizer;
use Espo\Core\FieldSanitize\Sanitizer\Data;
/**
* @noinspection PhpUnused
*/
class ArrayFromNull implements Sanitizer
{
public function sanitize(Data $data, string $field): void
{
if (!$data->has($field)) {
return;
}
$value = $data->get($field);
if ($value !== null) {
return;
}
$data->set($field, []);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldSanitizers;
use Espo\Core\FieldSanitize\Sanitizer;
use Espo\Core\FieldSanitize\Sanitizer\Data;
/**
* @noinspection PhpUnused
*/
class ArrayStringTrim implements Sanitizer
{
public function sanitize(Data $data, string $field): void
{
if (!$data->has($field)) {
return;
}
$value = $data->get($field);
if (!is_array($value)) {
return;
}
foreach ($value as $i => $item) {
if (!is_string($item)) {
continue;
}
$value[$i] = trim($item);
}
$data->set($field, $value);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2026 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Classes\FieldSanitizers;
use DateTimeImmutable;
use DateTimeInterface;
use Espo\Core\Field\Date as DateValue;
use Espo\Core\FieldSanitize\Sanitizer;
use Espo\Core\FieldSanitize\Sanitizer\Data;
use Espo\Core\Utils\DateTime as DateTimeUtil;
use Exception;
/**
* @noinspection PhpUnused
*/
class Date implements Sanitizer
{
public function sanitize(Data $data, string $field): void
{
$value = $data->get($field);
if ($value === null) {
return;
}
try {
DateValue::fromString($value);
return;
} catch (Exception) {}
$dateTime = DateTimeImmutable::createFromFormat(DateTimeInterface::ATOM, $value);
if ($dateTime === false) {
return;
}
$value = $dateTime->format(DateTimeUtil::SYSTEM_DATE_FORMAT);
$data->set($field, $value);
}
}

Some files were not shown because too many files have changed in this diff Show More