<?xml version="1.0" encoding="UTF-8"?>
<documents xmlns="http://www.sophoracms.com/import/4.2">
  <document nodeType="sophora-nt:script" externalID="972497bd-49a0-485c-ae4c-942bde8327ec" exportedUuid="972497bd-49a0-485c-ae4c-942bde8327ec">
    <properties>
      <property name="sophora:firstPublicationDate">
        <value>2023-06-22T15:09:28.424+02:00</value>
      </property>
      <property name="sophora:name">
        <value>Image AI Trigger Generate Variants</value>
      </property>
      <property name="sophora:script">
        <value>import com.subshell.sophora.server.application.manager.impl.AccessManager

class ImageAITriggerGenerateVariants implements IScriptDocumentChangeListener {
    private static final List USERNAMES = ['importer']
    private static final String IMAGE_NODETYPE = 'subshell-content-nt:imageObject'
    
    public void init(IScriptContext context) {
    }
    
    public void destroy() {
    }
    
    public void documentChanging(IScriptDocumentChangeEvent event) {
        def username = AccessManager.getCurrentUsername()
        if (!USERNAMES.contains(username)) {
            return
        }
        
        if (event.document.primaryType != IMAGE_NODETYPE) {
            return
        }

        if (event.stateChange != DocumentChangedEvent.StateChange.NONE) {
            return
        }
        
        event.document.setString('sophora-extension:imageAIAction', 'generate-variants')
    }
}

return new ImageAITriggerGenerateVariants()
</value>
      </property>
      <property name="sophora:scriptLanguage">
        <value>groovy</value>
      </property>
      <property name="sophora:scriptType">
        <value>documentChangingScript</value>
      </property>
    </properties>
    <childNodes>
      <childNode nodeType="sophora-nt:yellowData" name="sophora:yellowData">
        <properties />
        <childNodes />
        <resourceList />
      </childNode>
    </childNodes>
    <resourceList />
    <fields>
      <site>system</site>
      <structureNode>/</structureNode>
      <categories />
      <idstem>image-ai-trigger-generate-variants-script</idstem>
      <forceLock>true</forceLock>
      <forceCreate>false</forceCreate>
      <channels>
        <enabledChannels />
        <disabledChannels />
      </channels>
    </fields>
    <instructions>
      <lifecycleActivities>
        <lifecycleActivity type="publish" />
      </lifecycleActivities>
      <proposals />
      <stickyNotes />
    </instructions>
  </document>
</documents>
