src/Plugins/MissingOptionValuesPlugin.php
public function process()
    {

        // query whether or not, the debug mode has been enabled
        if (!$this->getConfiguration()->isDebugMode()) {
            $this->getSystemLogger()->info('Debug mode is not enabled, missing option values will not be exported');
            return;
        }

        // clear the filecache
        clearstatcache();

        // load the actual status
        $status = $this->getRegistryProcessor()->getAttribute($this->getSerial());

        // query whether or not the configured source directory is available
        if (!is_dir($sourceDir = $status[RegistryKeys::SOURCE_DIRECTORY])) {
            throw new \Exception(sprintf('Configured source directory %s is not available!', $sourceDir));
        }

        // load the array with the missing option values from the status
        $missingOptions = $status[RegistryKeys::MISSING_OPTION_VALUES];

        // if missing option values are found, return immediately
        if (sizeof($missingOptions) === 0) {
            $this->getSystemLogger()->info('Found no missing option values');
            return;
        }

        // initialize the array with the artefacts
        $artefacts = array();

        // prepare the artefacts
        foreach ($missingOptions as $attributeCode => $options) {
            foreach ($options as $value => $data) {
                list($counter, $skus) = $data;
                $artefacts[] = $this->newArtefact(
                    array(
                        ColumnKeys::STORE_VIEW_CODE   => null,
                        ColumnKeys::ATTRIBUTE_CODE    => $attributeCode,
                        ColumnKeys::ADMIN_STORE_VALUE => $value,
                        ColumnKeys::VALUE             => $value,
                        ColumnKeys::COUNTER           => $counter,
                        ColumnKeys::UNIQUE_IDENTIFIER => implode(',', array_keys($skus)),
                        ColumnKeys::SORT_ORDER        => null
                    )
                );
            }
        }

        // initialize a dummy last entity ID
        $this->setLastEntityId(0);

        // add the artefacts (missing option values) and export them as CSV file
        $this->addArtefacts(MissingOptionValuesPlugin::ARTEFACT_TYPE, $artefacts);
        $this->export(date('Ymd-His'), $counter = '01');

        // query whether or not a swift mailer has been registered
        if ($swiftMailer = $this->getSwiftMailer()) {
            // the swift mailer configuration
            $swiftMailerConfiguration = $this->getPluginConfiguration()->getSwiftMailer();

            // create the message with the CSV with the missing option values
            $message = $swiftMailer->createMessage()
                                   ->setSubject(sprintf('[%s] %s', $this->getSystemName(), $swiftMailerConfiguration->getParam(SwiftMailerKeys::SUBJECT)))
                                   ->setFrom($swiftMailerConfiguration->getParam(SwiftMailerKeys::FROM))
                                   ->setTo($to = $swiftMailerConfiguration->getParam(SwiftMailerKeys::TO))
                                   ->setBody('The attached CSV file(s) contains the missing attribute option values');

            // load the exported filenames
            $exportedFilenames = $this->getExportAdapter()->getExportedFilenames();

            // attach the CSV files with the missing option values
            foreach ($exportedFilenames as $filename) {
                $message->attach(\Swift_Attachment::fromPath($filename));
            }

            // initialize the array with the failed recipients
            $failedRecipients = array();
            $recipientsAccepted = 0;

            // send the mail
            $recipientsAccepted = $swiftMailer->send($message, $failedRecipients);

            // query whether or not all recipients have been accepted
            if (sizeof($failedRecipients) > 0) {
                $this->getSystemLogger()->error(sprintf('Can\'t send mail to %s', implode(', ', $failedRecipients)));
            }

            // if at least one recipient has been accepted
            if ($recipientsAccepted > 0) {
                // cast 'to' into an array if not already
                is_array($to) ? : $to = (array) $to;
                // remove the NOT accepted recipients
                $acceptedRecipients = array_diff($to, $failedRecipients);

                // log a message with the successfull receivers
                $this->getSystemLogger()->info(
                    sprintf(
                        'Mail successfully sent to %d recipient(s) (%s)',
                        $recipientsAccepted,
                        implode(', ', $acceptedRecipients)
                    )
                );
            }
        }

        // load the system loggers
        $systemLoggers = $this->getSystemLoggers();

        // and and log a message that the missing option values has been exported
        foreach ($systemLoggers as $systemLogger) {
            $systemLogger->error(
                sprintf(
                    'Exported missing option values to file %s!',
                    $filename
                )
            );
        }
    }
public function process()
    {

        // query whether or not, the debug mode has been enabled
        if (!$this->getConfiguration()->isDebugMode()) {
            $this->getSystemLogger()->info('Debug mode is not enabled, missing option values will not be exported');
            return;
        }

        // clear the filecache
        clearstatcache();

        // load the actual status
        $status = $this->getRegistryProcessor()->getAttribute($this->getSerial());

        // query whether or not the configured source directory is available
        if (!is_dir($sourceDir = $status[RegistryKeys::SOURCE_DIRECTORY])) {
            throw new \Exception(sprintf('Configured source directory %s is not available!', $sourceDir));
        }

        // load the array with the missing option values from the status
        $missingOptions = $status[RegistryKeys::MISSING_OPTION_VALUES];

        // if missing option values are found, return immediately
        if (sizeof($missingOptions) === 0) {
            $this->getSystemLogger()->info('Found no missing option values');
            return;
        }

        // initialize the array with the artefacts
        $artefacts = array();

        // prepare the artefacts
        foreach ($missingOptions as $attributeCode => $options) {
            foreach ($options as $value => $data) {
                list($counter, $skus) = $data;
                $artefacts[] = $this->newArtefact(
                    array(
                        ColumnKeys::STORE_VIEW_CODE   => null,
                        ColumnKeys::ATTRIBUTE_CODE    => $attributeCode,
                        ColumnKeys::ADMIN_STORE_VALUE => $value,
                        ColumnKeys::VALUE             => $value,
                        ColumnKeys::COUNTER           => $counter,
                        ColumnKeys::UNIQUE_IDENTIFIER => implode(',', array_keys($skus)),
                        ColumnKeys::SORT_ORDER        => null
                    )
                );
            }
        }

        // initialize a dummy last entity ID
        $this->setLastEntityId(0);

        // add the artefacts (missing option values) and export them as CSV file
        $this->addArtefacts(MissingOptionValuesPlugin::ARTEFACT_TYPE, $artefacts);
        $this->export(date('Ymd-His'), $counter = '01');

        // query whether or not a swift mailer has been registered
        if ($swiftMailer = $this->getSwiftMailer()) {
            // the swift mailer configuration
            $swiftMailerConfiguration = $this->getPluginConfiguration()->getSwiftMailer();

            // create the message with the CSV with the missing option values
            $message = $swiftMailer->createMessage()
                                   ->setSubject(sprintf('[%s] %s', $this->getSystemName(), $swiftMailerConfiguration->getParam(SwiftMailerKeys::SUBJECT)))
                                   ->setFrom($swiftMailerConfiguration->getParam(SwiftMailerKeys::FROM))
                                   ->setTo($to = $swiftMailerConfiguration->getParam(SwiftMailerKeys::TO))
                                   ->setBody('The attached CSV file(s) contains the missing attribute option values');

            // load the exported filenames
            $exportedFilenames = $this->getExportAdapter()->getExportedFilenames();

            // attach the CSV files with the missing option values
            foreach ($exportedFilenames as $filename) {
                $message->attach(\Swift_Attachment::fromPath($filename));
            }

            // initialize the array with the failed recipients
            $failedRecipients = array();
            $recipientsAccepted = 0;

            // send the mail
            $recipientsAccepted = $swiftMailer->send($message, $failedRecipients);

            // query whether or not all recipients have been accepted
            if (sizeof($failedRecipients) > 0) {
                $this->getSystemLogger()->error(sprintf('Can\'t send mail to %s', implode(', ', $failedRecipients)));
            }

            // if at least one recipient has been accepted
            if ($recipientsAccepted > 0) {
                // cast 'to' into an array if not already
                is_array($to) ? : $to = (array) $to;
                // remove the NOT accepted recipients
                $acceptedRecipients = array_diff($to, $failedRecipients);

                // log a message with the successfull receivers
                $this->getSystemLogger()->info(
                    sprintf(
                        'Mail successfully sent to %d recipient(s) (%s)',
                        $recipientsAccepted,
                        implode(', ', $acceptedRecipients)
                    )
                );
            }
        }

        // load the system loggers
        $systemLoggers = $this->getSystemLoggers();

        // and and log a message that the missing option values has been exported
        foreach ($systemLoggers as $systemLogger) {
            $systemLogger->error(
                sprintf(
                    'Exported missing option values to file %s!',
                    $filename
                )
            );
        }
    }
Process the plugin functionality.

@return void
@throws \Exception Is thrown, if the plugin can not be processed