Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Disable all Assets imports with script

Eugeny Chernyavsky
Contributor
May 3, 2024

Hi Community,
We have a lot of configured scheduled Assets imports running everyday several times due day
If we need to disable them temporarily - we would like to avoid going through dozen of ObjectSchemas and disable manually more then hundred of imports
question is: is there a possibility to disable them all at once

I tried to use class com.riadalabs.jira.plugins.insight.channel.external.api.facade.ImportSourceConfigurationFacade:

import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.db.DatabaseUtil
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ImportSourceConfigurationFacade
@WithPlugin('com.riadalabs.jira.plugins.insight')
@PluginModule ImportSourceConfigurationFacade importSourceConfigurationFacade

//getting list of all imports from database directly
DatabaseUtil.withSql('Imports') { sql ->
// going through each row of defined SQL query

sql.eachRow("""SELECT SRC.NAME, SRC.ID FROM JiraDB.jiraschema.AO_8542F1_IFJ_IMPORT_SRC AS SRC ORDER BY SRC.ID ASC""") {
def importID = it.getAt('ID') as Integer //Import ID
def importSource = importSourceConfigurationFacade.loadImportSource(importID)

def disabledImportStatus = importSource.importSourceStatus.createDisabled()
importSource.setImportSourceStatus(disabledImportStatus)
//log.warn(importSource.importSourceStatus)

log.warn("Import Name: "+importSource.getName()+"; Import ID: $importID; Enabled: "+importSource.isEnabled())

}

}

 Script is running and giving goal result for ImportSourceStatus = false
but imports remains enabled in UI and in DB 

4 answers

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 6, 2024

The importSource only exists in memory within the script context

You have to store it back after setting the status.

importSourceConfigurationFacade.storeImportSource(importSource)

 

Eugeny Chernyavsky
Contributor
May 7, 2024

Thanks,
I missed that somehow. It works now
Added this command and condition for importSource.isEnabled() not to update every import objects

Like Peter-Dave Sheehan likes this
0 votes
Eugeny Chernyavsky
Contributor
May 7, 2024

Just to add for future references:
We found out that there is hidden PUT API request can be used to disable imports:
https://{JIRA-URL}/rest/insight/1.0/importsource/{import_ID}/disable

0 votes
Eugeny Chernyavsky
Contributor
May 7, 2024

deleted

0 votes
RobertRipple May 3, 2024

It seems like the script is correctly updating the import status in the database, but it's not reflecting in the UI. Ensure that you're committing the changes to the database after updating the import source status to ensure they take effect.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events