<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">The
issue with<span> </span><strong style="font-weight: 600;">"orphan"
entities</strong><span> </span>is a significant one in<span> </span><strong
style="font-weight: 600;">Vtiger</strong>.</p>
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">The
core framework does<span> </span><strong
style="font-weight: 600;">not</strong><span> </span>check
related entities, leaving them<span> </span><strong
style="font-weight: 600;">orphaned</strong><span> </span>when
deleting or<span> </span><strong style="font-weight: 600;">unlinking</strong><span> </span>the
parent.</p>
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">For
example, deleting a<span> </span><strong
style="font-weight: 600;">Project</strong><span> </span>leaves
its<span> </span><strong style="font-weight: 600;">Project Tasks</strong><span> </span>orphaned.
The same applies to its<span> </span><strong
style="font-weight: 600;">comments, documents, activities,
etc.</strong></p>
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">We
implemented a<span> </span><strong style="font-weight: 600;">workaround</strong><span> </span>for
this with a<span> </span><strong style="font-weight: 600;">custom
handler</strong><span> </span>that catches<span> </span><code
style="font-size: 0.875em; font-weight: 500; font-family: Menlo, "Roboto Mono", "Courier New", Courier, monospace, Inter, sans-serif; background-color: rgb(236, 236, 236); border-radius: 4px; padding: 0.15rem 0.3rem;">beforedelete</code><span> </span>and<span> </span><code
style="font-size: 0.875em; font-weight: 500; font-family: Menlo, "Roboto Mono", "Courier New", Courier, monospace, Inter, sans-serif; background-color: rgb(236, 236, 236); border-radius: 4px; padding: 0.15rem 0.3rem;">beforeunrelate</code><span> </span>events.
If entities are related via a<span> </span><strong
style="font-weight: 600;">mandatory field</strong>, then<span> </span><strong
style="font-weight: 600;">delete</strong><span> </span>and<span> </span><strong
style="font-weight: 600;">unrelate</strong><span> </span>operations
are<span> </span><strong style="font-weight: 600;">blocked</strong>.
In the previous example, the<span> </span><strong
style="font-weight: 600;">Project</strong><span> </span>field
in<span> </span><strong style="font-weight: 600;">Project Task</strong><span> </span>entities
is mandatory, so deleting a<span> </span><strong
style="font-weight: 600;">Project</strong><span> </span>with
at least<span> </span><strong style="font-weight: 600;">one task</strong><span> </span>is
prevented.</p>
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">The
next step is to<span> </span><strong style="font-weight: 600;">enable
forced deletion</strong><span> </span>by adding a<span> </span><strong
style="font-weight: 600;">"delete on cascade"</strong><span> </span>checkbox.
However, we are concerned about potential<span> </span><strong
style="font-weight: 600;">circular dependencies</strong><span> </span>in
custom modules or complex entity configurations.</p>
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">All
of this<span> </span><strong style="font-weight: 600;">functionality</strong><span> </span>should
be added to<span> </span><strong style="font-weight: 600;">Vtiger's
core</strong><span> </span>and should<span> </span><strong
style="font-weight: 600;">at least</strong><span> </span>work
in<span> </span><strong style="font-weight: 600;">core modules</strong>.
Our current code is a<span> </span><strong
style="font-weight: 600;">"quick & dirty"</strong><span> </span>solution
that works for us, but it needs<span> </span><strong
style="font-weight: 600;">cleanup and generalization</strong><span> </span>before
being submitted as a<span> </span><strong
style="font-weight: 600;">Merge Request (MR)</strong>.</p>
<p class="ds-markdown-paragraph"
style="margin: 13.716px 0px; font-size: 16.002px; line-height: 28.575px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Moreover,
there is another issue with the<span> </span><strong
style="font-weight: 600;">Recycle Bin</strong><span> </span>when
activated:</p>
<ul
style="margin: 13.716px 0px; padding-left: 27.432px; color: rgb(64, 64, 64); font-family: quote-cjk-patch, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, "Helvetica Neue", Oxygen, "Open Sans", sans-serif; font-size: 16.002px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">
<li>
<p class="ds-markdown-paragraph"
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px !important; margin-left: 0px; font-size: 16.002px; line-height: 28.575px;">Deleting
a parent entity marks it as<span> </span><strong
style="font-weight: 600;">deleted</strong>, but<span> </span><strong
style="font-weight: 600;">related fields are not cleared</strong><span> </span>until
the Recycle Bin is emptied.</p>
</li>
<li style="margin-top: 4px;">
<p class="ds-markdown-paragraph"
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px !important; margin-left: 0px; font-size: 16.002px; line-height: 28.575px;">For
example, in<span> </span><strong style="font-weight: 600;">Projects</strong>,
you still see a<span> </span><strong
style="font-weight: 600;">link to the deleted Project</strong><span> </span>in
a<span> </span><strong style="font-weight: 600;">Task</strong>,
but clicking on it throws an error.</p>
</li>
</ul>
<br class="Apple-interchange-newline">
<br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Il 16/07/25 11:31, Alan Lord ha
scritto:<br>
</div>
<blockquote type="cite" cite="mid:1057rif$qj9$1@ciao.gmane.io">Anyone
got any thoughts on cleaning the crmentityrel table?
<br>
<br>
I think maybe this would be better to include in the delete code
in the recycle bin model, e.g.
<br>
<br>
"DELETE FROM vtiger_crmentityrel WHERE (module = ? AND crmid = ?)
OR (relmodule = ? AND relcrmid = ?)"
<br>
<br>
Are there any potential issues with removing rows from this table?
Otherwise it is just going to keep on growing as far as I can
tell...
<br>
<br>
But then we get into the others too: seactivityrel,
<br>
<br>
Cheers
<br>
<br>
Al
<br>
<br>
On 08/07/2025 09:29, Alan Lord wrote:
<br>
<blockquote type="cite">I've been working with the customer on
this and we have created a constraint for our custom table
linked to the crmentity(crmid).
<br>
<br>
But whilst we were discussing this I also thought about the
crmentityrel table. This is now really quite large and I suspect
a lot of rows in this are "orphan"... When I ran a query to list
any constraints for this table I found none. Perhaps some
performance improvement could be found it was cleaned up?
<br>
<br>
Question is: Should there be a "delete on cascade" constraint on
that table or not?
<br>
<br>
Thanks
<br>
<br>
Al
<br>
<br>
<br>
<br>
On 04/07/2025 09:59, Alan Lord wrote:
<br>
<blockquote type="cite">A customer just asked me about this...
<br>
<br>
When they remove some records from the Recycle bin for a
custom module, the entry in crmentity is removed, but the rows
in the module's own tables are not deleted.
<br>
<br>
Looking at the Module Model for the Recycle Bin I can see why:
<br>
<br>
<a class="moz-txt-link-freetext" href="https://code.vtiger.com/vtiger/vtigercrm/-/blob/master/pkg/vtiger/">https://code.vtiger.com/vtiger/vtigercrm/-/blob/master/pkg/vtiger/</a>
modules/RecycleBin/modules/RecycleBin/models/Module.php#L147
<br>
<br>
So my question is really about foreign key constraints.
<br>
<br>
When we create a new module, should the vtlib code be adding a
foreign key constraint and a on delete cascade?
<br>
<br>
<a class="moz-txt-link-freetext" href="https://code.vtiger.com/vtiger/vtigercrm/-/blob/master/vtlib/Vtiger/">https://code.vtiger.com/vtiger/vtigercrm/-/blob/master/vtlib/Vtiger/</a>
ModuleBasic.php?ref_type=heads#L294
<br>
<br>
Thanks
<br>
<br>
Al
<br>
<br>
_______________________________________________
<br>
<a class="moz-txt-link-freetext" href="http://www.vtiger.com/">http://www.vtiger.com/</a>
<br>
<br>
</blockquote>
<br>
<br>
_______________________________________________
<br>
<a class="moz-txt-link-freetext" href="http://www.vtiger.com/">http://www.vtiger.com/</a>
<br>
<br>
</blockquote>
<br>
<br>
_______________________________________________
<br>
<a class="moz-txt-link-freetext" href="http://www.vtiger.com/">http://www.vtiger.com/</a>
<br>
</blockquote>
<pre class="moz-signature" cols="72">--
Vincenzo Bruno
Coopyleft - <a class="moz-txt-link-abbreviated" href="http://www.coopyleft.it">www.coopyleft.it</a>
tel: 3287252923
Digital Polis (<a class="moz-txt-link-abbreviated" href="http://www.digitalpolis.it">www.digitalpolis.it</a>)
Hacklab Cosenza (<a class="moz-txt-link-abbreviated" href="http://www.hlcs.it">www.hlcs.it</a>)
</pre>
</body>
</html>