[Vtigercrm-developers] Cant restore records from custom modules

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Vtigercrm-developers] Cant restore records from custom modules

Ruben Estrada
Sending this message a second time, because it seems the first time failed:

Hi everyone

Has anybody noticed that restoring records from custom modules fails? It fails with modules I created as well as with modules from other 3rd parties. I spent some hours trying to fix it without success :(

I get the following error:

image.png

If you try to restore it a second time, it takes a while before the http response is back:
image.png

The error is the following:

Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::ADODB error Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::->Lock wait timeout exceeded; try restarting transaction

Thats because the first time the the restore function at CRMEntity.php  executes, it doesn't complete (an exception is thrown when triggering the afterrestore event):

image.png

So the second time you try to restore the record, the vtiger_crmentity table is locked because of the startTransaction() call at line 1388 (I think) and that's why it takes a while.

It is the following handler that throws the exception the first time you try to restore the record:   modules/Vtiger/handlers/EmailLookupHandler.php because it tries to instantiate the record that's being restored at line 84:

image.png

The strange thing is that it doesn't fail in the case of Vtiger native modules but only with custom modules, which is pretty strange.

Disabling the above event results in successfully being able to restore records.

Any help will be greatly appreciated.

Saludos

Rubén

Saludos

Rubén

_______________________________________________
http://www.vtiger.com/
Rubén Estrada
simplesistemas.com
Reply | Threaded
Open this post in threaded view
|

Re: Cant restore records from custom modules

lajeesh k-2
Hi

In restore function change $this->db->pquery to $adb->pquery
I had the same issue and fixed this way


Regards,
Lajeesh
Freelance developer / entrepreneur



On Fri, Oct 4, 2019 at 7:29 AM Rubén A. Estrada Orozco <[hidden email]> wrote:
Sending this message a second time, because it seems the first time failed:

Hi everyone

Has anybody noticed that restoring records from custom modules fails? It fails with modules I created as well as with modules from other 3rd parties. I spent some hours trying to fix it without success :(

I get the following error:

image.png

If you try to restore it a second time, it takes a while before the http response is back:
image.png

The error is the following:

Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::ADODB error Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::->Lock wait timeout exceeded; try restarting transaction

Thats because the first time the the restore function at CRMEntity.php  executes, it doesn't complete (an exception is thrown when triggering the afterrestore event):

image.png

So the second time you try to restore the record, the vtiger_crmentity table is locked because of the startTransaction() call at line 1388 (I think) and that's why it takes a while.

It is the following handler that throws the exception the first time you try to restore the record:   modules/Vtiger/handlers/EmailLookupHandler.php because it tries to instantiate the record that's being restored at line 84:

image.png

The strange thing is that it doesn't fail in the case of Vtiger native modules but only with custom modules, which is pretty strange.

Disabling the above event results in successfully being able to restore records.

Any help will be greatly appreciated.

Saludos

Rubén

Saludos

Rubén
_______________________________________________
http://www.vtiger.com/

_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|

Re: Cant restore records from custom modules

Ruben Estrada
Thanks Lajeesh,

Do you think that $this->db is not initialized or something when called in the case of custom modules? If thats the case, then that's a vtiger bug, I guess.

I would like to find a solution without changing vtiger's code. Because I cannot control that in many cases.

Saludos

Rubén


On Tue, Oct 8, 2019 at 9:11 AM lajeesh k <[hidden email]> wrote:
Hi

In restore function change $this->db->pquery to $adb->pquery
I had the same issue and fixed this way


Regards,
Lajeesh
Freelance developer / entrepreneur



On Fri, Oct 4, 2019 at 7:29 AM Rubén A. Estrada Orozco <[hidden email]> wrote:
Sending this message a second time, because it seems the first time failed:

Hi everyone

Has anybody noticed that restoring records from custom modules fails? It fails with modules I created as well as with modules from other 3rd parties. I spent some hours trying to fix it without success :(

I get the following error:

image.png

If you try to restore it a second time, it takes a while before the http response is back:
image.png

The error is the following:

Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::ADODB error Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::->Lock wait timeout exceeded; try restarting transaction

Thats because the first time the the restore function at CRMEntity.php  executes, it doesn't complete (an exception is thrown when triggering the afterrestore event):

image.png

So the second time you try to restore the record, the vtiger_crmentity table is locked because of the startTransaction() call at line 1388 (I think) and that's why it takes a while.

It is the following handler that throws the exception the first time you try to restore the record:   modules/Vtiger/handlers/EmailLookupHandler.php because it tries to instantiate the record that's being restored at line 84:

image.png

The strange thing is that it doesn't fail in the case of Vtiger native modules but only with custom modules, which is pretty strange.

Disabling the above event results in successfully being able to restore records.

Any help will be greatly appreciated.

Saludos

Rubén

Saludos

Rubén
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/

_______________________________________________
http://www.vtiger.com/
Rubén Estrada
simplesistemas.com
Reply | Threaded
Open this post in threaded view
|

Re: Cant restore records from custom modules

lajeesh k-2
Hi Roben,

Its a vtiger bug.

The problem is the restore process is a transaction.
you can see transaction starts with $this-db->startTransaction()

until the transaction completes other mysql process cannot see the db changes

the vtiger_record_model::getInstance method in handleEmailLookupRestoreEvent function uses $adb instance

$adb instance cannot see that db changes so vtiger_record_model::getInstance returns the error record deleted 

either $this->db or $adb should use for all queries inside a transaction




Regards,
Lajeesh
Freelance developer / entrepreneur



On Tue, Oct 8, 2019 at 11:07 PM Rubén A. Estrada Orozco <[hidden email]> wrote:
Thanks Lajeesh,

Do you think that $this->db is not initialized or something when called in the case of custom modules? If thats the case, then that's a vtiger bug, I guess.

I would like to find a solution without changing vtiger's code. Because I cannot control that in many cases.

Saludos

Rubén


On Tue, Oct 8, 2019 at 9:11 AM lajeesh k <[hidden email]> wrote:
Hi

In restore function change $this->db->pquery to $adb->pquery
I had the same issue and fixed this way


Regards,
Lajeesh
Freelance developer / entrepreneur



On Fri, Oct 4, 2019 at 7:29 AM Rubén A. Estrada Orozco <[hidden email]> wrote:
Sending this message a second time, because it seems the first time failed:

Hi everyone

Has anybody noticed that restoring records from custom modules fails? It fails with modules I created as well as with modules from other 3rd parties. I spent some hours trying to fix it without success :(

I get the following error:

image.png

If you try to restore it a second time, it takes a while before the http response is back:
image.png

The error is the following:

Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::ADODB error Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::->Lock wait timeout exceeded; try restarting transaction

Thats because the first time the the restore function at CRMEntity.php  executes, it doesn't complete (an exception is thrown when triggering the afterrestore event):

image.png

So the second time you try to restore the record, the vtiger_crmentity table is locked because of the startTransaction() call at line 1388 (I think) and that's why it takes a while.

It is the following handler that throws the exception the first time you try to restore the record:   modules/Vtiger/handlers/EmailLookupHandler.php because it tries to instantiate the record that's being restored at line 84:

image.png

The strange thing is that it doesn't fail in the case of Vtiger native modules but only with custom modules, which is pretty strange.

Disabling the above event results in successfully being able to restore records.

Any help will be greatly appreciated.

Saludos

Rubén

Saludos

Rubén
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/

_______________________________________________
http://www.vtiger.com/
Reply | Threaded
Open this post in threaded view
|

Re: Cant restore records from custom modules

Ruben Estrada
Thanks for your help Lajeesh, I could finally find spot the bug and fix it without changing vtiger's code.

In vtiger's modules you will find a class with the name of the module. For example, there is the class Accounts.php

Accounts has a constructor that looks like this:
image.png

Accounts also extends CRMEntity.php

So, the $this->db you see in the restore() function inside CRMEntity.php gets intitialized in the Accounts constructor using PearDatabase::getInstance()

In the case of custom modules, you usually extend Vtiger_CRMEntity and you don't create a constructor. You inherit the one provided by Vtiger_CRMEntity which is this one:

image.png

There you can see that you are creating an entirely new database object with "new PearDatabase()"  instead of getting it via PearDatabase::getInstance(), and that is the problem.

To fix it, just create a constructor like this one in your module's main class like this:

 
image.png

I think Vtiger should fix that by making PearDatabase constructor private (implement the singleton pattern correctly) and replacing all the new PearDatabase() occurrences.

Saludos

Rubén


On Wed, Oct 9, 2019 at 2:13 AM lajeesh k <[hidden email]> wrote:
Hi Roben,

Its a vtiger bug.

The problem is the restore process is a transaction.
you can see transaction starts with $this-db->startTransaction()

until the transaction completes other mysql process cannot see the db changes

the vtiger_record_model::getInstance method in handleEmailLookupRestoreEvent function uses $adb instance

$adb instance cannot see that db changes so vtiger_record_model::getInstance returns the error record deleted 

either $this->db or $adb should use for all queries inside a transaction




Regards,
Lajeesh
Freelance developer / entrepreneur



On Tue, Oct 8, 2019 at 11:07 PM Rubén A. Estrada Orozco <[hidden email]> wrote:
Thanks Lajeesh,

Do you think that $this->db is not initialized or something when called in the case of custom modules? If thats the case, then that's a vtiger bug, I guess.

I would like to find a solution without changing vtiger's code. Because I cannot control that in many cases.

Saludos

Rubén


On Tue, Oct 8, 2019 at 9:11 AM lajeesh k <[hidden email]> wrote:
Hi

In restore function change $this->db->pquery to $adb->pquery
I had the same issue and fixed this way


Regards,
Lajeesh
Freelance developer / entrepreneur



On Fri, Oct 4, 2019 at 7:29 AM Rubén A. Estrada Orozco <[hidden email]> wrote:
Sending this message a second time, because it seems the first time failed:

Hi everyone

Has anybody noticed that restoring records from custom modules fails? It fails with modules I created as well as with modules from other 3rd parties. I spent some hours trying to fix it without success :(

I get the following error:

image.png

If you try to restore it a second time, it takes a while before the http response is back:
image.png

The error is the following:

Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::ADODB error Error restoring records : Query Failed:UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?::->Lock wait timeout exceeded; try restarting transaction

Thats because the first time the the restore function at CRMEntity.php  executes, it doesn't complete (an exception is thrown when triggering the afterrestore event):

image.png

So the second time you try to restore the record, the vtiger_crmentity table is locked because of the startTransaction() call at line 1388 (I think) and that's why it takes a while.

It is the following handler that throws the exception the first time you try to restore the record:   modules/Vtiger/handlers/EmailLookupHandler.php because it tries to instantiate the record that's being restored at line 84:

image.png

The strange thing is that it doesn't fail in the case of Vtiger native modules but only with custom modules, which is pretty strange.

Disabling the above event results in successfully being able to restore records.

Any help will be greatly appreciated.

Saludos

Rubén

Saludos

Rubén
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/

_______________________________________________
http://www.vtiger.com/
Rubén Estrada
simplesistemas.com