Announcement

Collapse
No announcement yet.

Set a "flag" somewhere upon account record add, changed or deleted

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set a "flag" somewhere upon account record add, changed or deleted

    I'm looking for a way to know if any account record in the database has been modified today. I know there is a 'modified_at' field in the account record with time/date in it and that is working well via this kind of code:

    Code:
    curhr=$(date +%-H)
    
       if (( $curhr > 05  &&  $curhr <= 23 )); then
         #echo "---------it is between 6AM and 11 PM"
        mycount=$(/usr/local/bin/mysql --login-path=espocrm ancnet1_espo1  -e "SELECT COUNT(*)  FROM account WHERE date(CONVERT_TZ(modified_at,'+00:00','-07:00')) = CURRENT_DATE ORDER BY modified_at DESC")
    
       else
         #echo "---------it is not between 6AM and 10PM"
    
         mycount=$(/usr/local/bin/mysql --login-path=espocrm ancnet1_espo1  -e "SELECT COUNT(*)  FROM account WHERE date(CONVERT_TZ(modified_at,'+00:00','-08:00')) = DATE_SUB(CURRENT_DATE,INTERVAL 1 DAY) ORDER BY modified_at DESC")
       fi  
       tot1="${mycount//[!0-9]/}"
    
    if (( $tot1 <= 0 ))
    then  ​
    I was wondering if there was some way I could simply set a "flag" (like a 1 or 0 in a file) when a record is added, changed, or deleted because the above code above is more complex than the problem I'm trying to solve... which is knowing when to reload my backup database for my backup version of EspoCRM.

    I know there are some 'hooks' that 'fire" on an update/change/delete to an account record but I don't understand how to use one.

    I looked at the docs. Does anyone have a more complete explanation and example?
    Last edited by dev77; 03-14-2023, 11:49 PM.

  • #2
    UPDATE: I spent some time and figured out how 'hooks' work. See this thread if interested:

    Via a hook, I'm trying to 'touch' a file when I update an account record. This is my first attempt to use a hook. The hook does not work. Can anyone tell me why? Here is the code: &lt;?php namespace Espo\Custom\Hooks\Accounts; use Espo\ORM\Entity; class MyHook { // An optional parameter, defines in which order hooks will


    Comment

    Working...
    X