Skip to content

Commit

Permalink
Merge pull request #1440 from Quetzacoalt91/add-hook-registration
Browse files Browse the repository at this point in the history
Make fix of unregistered hooks easier via debug page
  • Loading branch information
Quetzacoalt91 authored Apr 20, 2023
2 parents 111f109 + 196acb2 commit 45eabab
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions _dev/apps/ui/src/store/modules/app/actions-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum ActionsTypes {
CHECK_FOR_AD_BLOCKER = 'CHECK_FOR_AD_BLOCKER',
GET_API_HEALTHCHECK = 'GET_API_HEALTHCHECK',
GET_MODULES_VERSIONS = 'GET_MODULES_VERSIONS',
TRIGGER_REGISTER_HOOK = 'TRIGGER_REGISTER_HOOK',
}

export {ActionsTypes as default};
4 changes: 4 additions & 0 deletions _dev/apps/ui/src/store/modules/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ export default {
return error;
}
},
// eslint-disable-next-line no-empty-pattern
async [ActionsTypes.TRIGGER_REGISTER_HOOK]({}, hookName: string) {
return fetchShop('registerHook', {hookName});
},
};
38 changes: 25 additions & 13 deletions _dev/apps/ui/src/views/debug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,19 @@
<strong>Hook list</strong>:
<ul>
<li
v-for="(type, hookName) in hooks"
v-for="(registered, hookName) in hooks"
:key="hookName"
>
{{ hookName }} - {{ type ? '':'' }}
{{ hookName }} - {{ registered ? '':'' }}
<b-button
v-if="!registered"
class="ml-3"
variant="primary"
size="sm"
@click="registerHook(hookName)"
>
🩹 Register hook
</b-button>
</li>
</ul>
</li>
Expand Down Expand Up @@ -263,13 +272,14 @@
</div>
</template>

<script>
<script lang="ts">
import {defineComponent} from 'vue';
import {mapGetters, mapState} from 'vuex';
import GettersTypes from '@/store/modules/campaigns/getters-types.ts';
import GettersTypesApp from '@/store/modules/app/getters-types.ts';
import GettersTypesProductFeed from '@/store/modules/product-feed/getters-types.ts';
import GettersTypes from '@/store/modules/campaigns/getters-types';
import GettersTypesApp from '@/store/modules/app/getters-types';
import GettersTypesProductFeed from '@/store/modules/product-feed/getters-types';
export default {
export default defineComponent({
name: 'Debug',
data() {
return {
Expand Down Expand Up @@ -362,11 +372,13 @@ export default {
this.getProductFeed();
}
},
getHooks() {
this.$store.dispatch('app/GET_MODULES_VERSIONS', 'psxmarketingwithgoogle')
.then((res) => {
this.hooks = res.hooks;
});
async getHooks() {
const res = await this.$store.dispatch('app/GET_MODULES_VERSIONS', 'psxmarketingwithgoogle');
this.hooks = res.hooks;
},
async registerHook(hookName: string) {
await this.$store.dispatch('app/TRIGGER_REGISTER_HOOK', hookName);
await this.getHooks();
},
async triggerGoogleSync() {
this.sync.loading = true;
Expand Down Expand Up @@ -398,5 +410,5 @@ export default {
this.$store.dispatch('app/REQUEST_DEBUG_DATA');
this.getHooks();
},
};
});
</script>
20 changes: 20 additions & 0 deletions controllers/admin/AdminAjaxPsxMktgWithGoogleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public function displayAjax()
case 'getModuleStatus':
$this->getModuleStatus($inputs);
break;
case 'registerHook':
$this->registerHook($inputs);
break;
default:
http_response_code(400);
$this->ajaxDie(json_encode(['success' => false, 'message' => $this->l('Action is missing or incorrect.')]));
Expand Down Expand Up @@ -512,6 +515,23 @@ private function getUserDocumentation()
return $baseUrl . '/user_guide_' . $isoCode . '.pdf';
}

private function registerHook(array $inputs)
{
if (!isset($inputs['hookName'])) {
http_response_code(400);
$this->ajaxDie(json_encode([
'success' => false,
'message' => 'Missing hookName key',
]));
}

$this->ajaxDie(
json_encode([
'success' => $this->module->registerHook($inputs['hookName']),
])
);
}

/**
* Use cUrl to get HTTP headers and detect any HTTP 404
*
Expand Down

0 comments on commit 45eabab

Please sign in to comment.