Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX/737: deleted queries still visible via SOAP api with Status=Inactive #738

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ class Automation extends MetadataType {
// the delete endpoint returns a general exception if the automation does not exist; handle it gracefully instead by adding a retrieve first
const objectId = customerKey ? await this._getObjectIdForSingleRetrieve(customerKey) : null;
if (!objectId) {
Util.logger.error(`- automation not found`);
Util.logger.error(` - automation not found`);
return false;
}
return super.deleteByKeySOAP(customerKey, 'CustomerKey');
Expand Down
31 changes: 27 additions & 4 deletions lib/metadataTypes/Query.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const TYPE = require('../../types/mcdev.d');
const Util = require('../util/util');
const MetadataType = require('./MetadataType');
const File = require('../util/file');
const cache = require('../util/cache');
Expand Down Expand Up @@ -32,7 +33,16 @@ class Query extends MetadataType {
*/
static async retrieve(retrieveDir, _, __, key) {
await File.initPrettier('sql');
const objectId = key ? await this._getObjectIdForSingleRetrieve(key) : null;
let objectId = null;
if (key) {
objectId = await this._getObjectIdForSingleRetrieve(key);
if (!objectId) {
// avoid running the rest request below by returning early
Util.logger.info(`Downloaded: ${this.definition.type} (0) - Key: ${key}`);
return { metadata: {}, type: this.definition.type };
}
}

return super.retrieveREST(
retrieveDir,
'/automation/v1/queries/' + (objectId || ''),
Expand All @@ -51,9 +61,17 @@ class Query extends MetadataType {
static async _getObjectIdForSingleRetrieve(key) {
const response = await this.client.soap.retrieve('QueryDefinition', ['ObjectID'], {
filter: {
leftOperand: 'CustomerKey',
operator: 'equals',
rightOperand: key,
leftOperand: {
leftOperand: 'CustomerKey',
operator: 'equals',
rightOperand: key,
},
operator: 'AND',
rightOperand: {
leftOperand: 'Status',
operator: 'equals',
rightOperand: 'Active',
},
},
});
return response?.Results?.length ? response.Results[0].ObjectID : null;
Expand Down Expand Up @@ -351,7 +369,12 @@ class Query extends MetadataType {
* @returns {boolean} deletion success status
*/
static async deleteByKey(customerKey) {
// delete only works with the query's object id
const objectId = customerKey ? await this._getObjectIdForSingleRetrieve(customerKey) : null;
if (!objectId) {
Util.logger.error(` - query not found`);
return false;
}
return super.deleteByKeyREST('/automation/v1/queries/' + objectId, customerKey);
}
/**
Expand Down