In this article, we’ll see how to fix the issue in the sync\_app application (default name) without having to recreate the security module.

![Info](https://static.zohocdn.com/zoho-desk-editor/static/images/info.png/)
This fix applies to a security module **created in a version prior to 9.12.021** and using the following **types**:

- **Group**
- **Application**
- **Ldap/Application**

## The issue

When deleting an application from the system in the application list and using the synchronize applications option to update the database, some tables were not being updated and the deleted applications continued to appear.

## How to fix

To fix the synchronization issue in the security module, it is necessary to edit the code in the *onValidate* and *onValidateSuccess* events of the *sync\_apps* application (default name).

## Step-by-step

Follow the steps below. If you have any questions, contact our support team through the official channels.

### 1. Locating the application

No matter what prefix was used during the creation of the security module, the default name of the application is **sync\_apps**. On the home screen of your project, search for **sync\_apps**.

![](https://help.scriptcase.net/galleryDocuments/edbsn3d8fd1cddac986eeab1acd0694285670e1686e82d8d5b8c8b3bbafc5d1907f8ec409fc8bd2291b0372d4a3b425f286e2?inline=true)

### 2. Code for onValidate

Comment out the existing code and add the new version below inside the onValidate event.

Below is a summary of the SQL commands used in this section. This list is meant to help developers quickly identify the database operations involved:

1. *sc\_select(rs, "SELECT app\_name FROM sec\_apps");*
2. *sc\_exec\_sql("DELETE FROM sec\_groups\_apps WHERE app\_name = " . sc\_sql\_injection($app));*
3. *sc\_exec\_sql("DELETE FROM sec\_apps WHERE app\_name = " . sc\_sql\_injection($app));*
4. *sc\_select(rs, "SELECT group\_id FROM sec\_groups");*
5. *"SELECT count(\*) FROM sec\_apps WHERE app\_name = '". $app ."' ";*
6. *"INSERT INTO sec\_apps(app\_name, app\_type, description) VALUES ('". $app ."', '".$app\_type."', '".$app\_desc."')";*
7. *"INSERT INTO sec\_groups\_apps(app\_name, group\_id) VALUES ('". $app ."', '". $grp ."')";*

**onValidare**

1. *$arr\_apps  = array();*
2. *$arr\_app\_desc = array(); // >>> New <<<*
3. *$\_arr\_apps = array\_diff(scandir($this->Ini->path\_aplicacao . "../\_lib/\_app\_data/"), array('.','..', 'index.php', 'index.html'));*
5. *foreach($\_arr\_apps as $k => $v)*
6. *{*
7. *if(substr($v, -12) != "\_mob\_ini.php")*
8. *{*
9. *$arr\_apps[] = substr($v, 0, -8);*
10. *}*
11. *}*
13. *sc\_select(rs, "SELECT app\_name FROM sec\_apps");*
15. *$arr\_apps\_deleted = array(); // >>>**New**<<<*
16. *$arr\_apps\_db = array();*
18. *while(!$rs->EOF)*
19. *{*
20. *$arr\_apps\_db[] = $rs->fields[0];*
21. *$rs->MoveNext();*
22. *}*
23. *$rs->Close();*
25. *if({check\_deleted} == 'Y')*
26. *{*
27. *$arr\_apps\_deleted\_dir = array\_diff($arr\_apps\_db, $arr\_apps); // >>>**New**<<<*
28. *foreach($arr\_apps\_deleted\_dir as $k => $app){ // >>>**New**<<<*
29. *if(substr($app, 0, 8) == 'https://' || substr($app, 0, 7) == 'http://'){ // >>>**New**<<<*
30. *continue; // >>>**New**<<<*
31. *}*
32. *$arr\_apps\_deleted[] = $app; // >>>**New**<<<*
33. *sc\_exec\_sql("DELETE FROM sec\_groups\_apps WHERE app\_name = " . sc\_sql\_injection($app)); // >>>**New**<<<*
34. *sc\_exec\_sql("DELETE FROM sec\_apps WHERE app\_name = " . sc\_sql\_injection($app)); // >>>**New**<<<*
35. *}*
37. *foreach($arr\_apps as $k => $app)*
38. *{*
39. *require($this->Ini->path\_aplicacao . "../\_lib/\_app\_data/". $app . '\_ini.php');*
41. *$app = (isset($arr\_data['friendly\_url']) && !empty($arr\_data['friendly\_url']))?$arr\_data['friendly\_url']:$app;*
43. *if( !is\_dir($this->Ini->path\_aplicacao . "../" . $app) )*
44. *{*
45. *unset($arr\_apps[$k]);*
46. *}*
47. *}*
48. *}*
50. *$arr\_apps = array\_diff($arr\_apps, $arr\_apps\_db);*
52. *//========= Groups =========*
53. *$arr\_grp = array();*
54. *sc\_select(rs, "SELECT group\_id FROM sec\_groups");*
55. *while(!$rs->EOF)*
56. *{*
57. *$arr\_grp[] = $rs->fields[0];*
58. *$rs->MoveNext();*
59. *}*
60. *$rs->Close();*
62. *foreach($arr\_apps as $k => $app)*
63. *{*
64. *require($this->Ini->path\_aplicacao . "../\_lib/\_app\_data/". $app . '\_ini.php');*
65. *$app\_type = isset($arr\_data['type'])? $arr\_data['type'] : '';*
66. *$app\_desc = isset($arr\_data['description']) ? $arr\_data['description'] : '';*
67. *$arr\_app\_desc[ $app ] = $app\_desc; // >>>**New**<<<*
69. *$sql = "SELECT count(\*) FROM sec\_apps WHERE app\_name = '". $app ."' ";*
70. *sc\_lookup(rs, $sql);*
71. *if({rs[0][0]} == 0)*
72. *{*
73. *$sql = "INSERT INTO sec\_apps(app\_name, app\_type, description) VALUES ('". $app ."', '".$app\_type."', '".$app\_desc."')";*
74. *sc\_exec\_sql( $sql );*
75. *foreach($arr\_grp as $grp)*
76. *{*
77. *$sql = "INSERT INTO sec\_groups\_apps(app\_name, group\_id) VALUES ('". $app ."', '". $grp ."')";*
78. *sc\_exec\_sql( $sql );*
79. *}*
80. *}*
81. *}*

### 3. Code for onValidateSuccess

After applying the necessary changes in the *onValidate* event, access the ***onValidateSuccess*** event.

This event includes only visual improvements, aimed at providing clearer feedback when using the synchronize applications option.

Comment out the current code and add the code below.

***onValidateSuccess***

1. $html = '

   '; // >>> New <<<
2. $html .= '| '.{lang\_sec\_app\_name}.' | '.{lang\_sec\_description}.' |
   | --- | --- |
   '; // >>> New <<<
4. if(is\_array($arr\_apps))
5. {
6. $total\_apps = count($arr\_apps);
7. foreach($arr\_apps as $app)
8. {
9. $html .= "|"; // >>> New <<<
   |  |
10. $html .=     " ". $app .' |'; // >>> New <<<
11. $html .=     ' '. ( isset($arr\_app\_desc[ $app ]) ? $arr\_app\_desc[$app] : '') . " |"; // >>> New <<<
12. $html .= ""; // >>> New <<<
13. }
14. }
16. if(is\_array($arr\_apps\_deleted)) // >>> New <<<
17. {
18. $total\_apps\_deleted = count($arr\_apps\_deleted); // >>> New <<<
19. foreach($arr\_apps\_deleted as $app) // >>> New <<<
20. {
21. $html .= "|"; // >>> New <<<
    |  |
22. $html .=     " ". $app .' |'; // >>> New  <<<
23. $html .=     ' '. ( isset($arr\_app\_desc[ $app ]) ? $arr\_app\_desc[$app] : '') . "  **".{lang\_sec\_deleted}."** |"; // >>> New <<<
24. $html .= ""; // >>> New <<<
25. }
26. }
28. $html .= ""; // >>> New <<<
30. {sync}  = "  
    **". $total\_apps. " ". {lang\_syncronized\_apps} . "**"; // >>> New <<<
31. {sync} .= "  
    **". $total\_apps\_deleted. " ". {lang\_sec\_deleted\_apps} . "**"; // >>> New <<<
32. if($total\_apps > 0 || $total\_apps\_deleted > 0){ // >>> New  <<<
33. {sync} .= "

    ---

    " . $html; // >>> New <<<
34. }

### **4. Testing and Deployment**

After making the changes, compile the application source code and perform tests to ensure that the changes have been applied correctly.

If everything works as expected in the tests, simply deploy the application so that the fix is applied to your production system.

**If you have any questions or issues with the update, please contact our support team through official channels.**