mirror of
https://github.com/xtr-dev/payload-automation.git
synced 2025-12-10 00:43:23 +00:00
Rename 'collection' field to 'collectionSlug' to avoid PayloadCMS reserved field conflicts
- Updated Workflow collection trigger field from 'collection' to 'collectionSlug' - Updated all document operation steps (create, read, update, delete) to use 'collectionSlug' - Updated corresponding handlers to destructure 'collectionSlug' instead of 'collection' - Removed debug console.log statements from logger configLogger methods - Fixed collection hook debug logs to use 'slug' instead of reserved 'collection' field 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,9 @@ const applyCollectionsConfig = <T extends string>(pluginOptions: WorkflowsPlugin
|
||||
)
|
||||
}
|
||||
|
||||
// Track if hooks have been initialized to prevent double registration
|
||||
let hooksInitialized = false
|
||||
|
||||
export const workflowsPlugin =
|
||||
<TSlug extends string>(pluginOptions: WorkflowsPluginConfig<TSlug>) =>
|
||||
(config: Config): Config => {
|
||||
@@ -42,6 +45,7 @@ export const workflowsPlugin =
|
||||
}
|
||||
|
||||
const configLogger = getConfigLogger()
|
||||
configLogger.info(`Configuring workflow plugin with ${Object.keys(pluginOptions.collectionTriggers || {}).length} collection triggers`)
|
||||
|
||||
// Generate cron tasks for workflows with cron triggers
|
||||
generateCronTasks(config)
|
||||
@@ -61,27 +65,49 @@ export const workflowsPlugin =
|
||||
// Set up onInit to register collection hooks and initialize features
|
||||
const incomingOnInit = config.onInit
|
||||
config.onInit = async (payload) => {
|
||||
configLogger.info(`onInit called - hooks already initialized: ${hooksInitialized}, collections: ${Object.keys(payload.collections).length}`)
|
||||
|
||||
// Prevent double initialization in dev mode
|
||||
if (hooksInitialized) {
|
||||
configLogger.warn('Hooks already initialized, skipping to prevent duplicate registration')
|
||||
return
|
||||
}
|
||||
|
||||
// Execute any existing onInit functions first
|
||||
if (incomingOnInit) {
|
||||
configLogger.debug('Executing existing onInit function')
|
||||
await incomingOnInit(payload)
|
||||
}
|
||||
|
||||
// Initialize the logger with the payload instance
|
||||
const logger = initializeLogger(payload)
|
||||
logger.info('Logger initialized with payload instance')
|
||||
|
||||
// Log collection trigger configuration
|
||||
logger.info(`Plugin configuration: ${Object.keys(pluginOptions.collectionTriggers || {}).length} collection triggers, ${pluginOptions.steps?.length || 0} steps`)
|
||||
|
||||
// Create workflow executor instance
|
||||
const executor = new WorkflowExecutor(payload, logger)
|
||||
|
||||
// Initialize hooks
|
||||
logger.info('Initializing collection hooks...')
|
||||
initCollectionHooks(pluginOptions, payload, logger, executor)
|
||||
|
||||
logger.info('Initializing global hooks...')
|
||||
initGlobalHooks(payload, logger, executor)
|
||||
|
||||
logger.info('Initializing workflow hooks...')
|
||||
initWorkflowHooks(payload, logger)
|
||||
|
||||
logger.info('Initializing step tasks...')
|
||||
initStepTasks(pluginOptions, payload, logger)
|
||||
|
||||
// Register cron jobs for workflows with cron triggers
|
||||
logger.info('Registering cron jobs...')
|
||||
await registerCronJobs(payload, logger)
|
||||
|
||||
logger.info('Plugin initialized successfully')
|
||||
logger.info('Plugin initialized successfully - all hooks registered')
|
||||
hooksInitialized = true
|
||||
}
|
||||
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user