src/Plugins/MissingOptionValuesPlugin.php
/**
     * Process the plugin functionality.
     *
     * @return void
     * @throws \Exception Is thrown, if the plugin can not be processed
     */
Process the plugin functionality.
@return void
@throws \Exception Is thrown, if the plugin can not be processed
Process the plugin functionality . @return void @throws \ Exception Is thrown if the plugin can not be processed
public function process()
    {
        if (!$this->getConfiguration()->isDebugMode()) {
            $this->getSystemLogger()->info('Debug mode is not enabled, missing option values will not be exported');
            return;
        }
        clearstatcache();
        $status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS);
        if (!is_dir($sourceDir = $status[RegistryKeys::SOURCE_DIRECTORY])) {
            throw new \Exception(sprintf('Configured source directory %s is not available!', $sourceDir));
        }
        $missingOptions = $status[RegistryKeys::MISSING_OPTION_VALUES];
        if (sizeof($missingOptions) === 0) {
            $this->getSystemLogger()->info('Found no missing option values');
            return;
        }
        $artefacts = array();
        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
                    )
                );
            }
        }
        $this->setLastEntityId(0);
        $this->addArtefacts(MissingOptionValuesPlugin::ARTEFACT_TYPE, $artefacts);
        $this->export(date('Ymd-His'), $counter = '01');
        if ($swiftMailer = $this->getSwiftMailer()) {
            $swiftMailerConfiguration = $this->getPluginConfiguration()->getSwiftMailer();
            $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');
            $exportedFilenames = $this->getExportAdapter()->getExportedFilenames();
            foreach ($exportedFilenames as $filename) {
                $message->attach(\Swift_Attachment::fromPath($filename));
            }
            $failedRecipients = array();
            $recipientsAccepted = 0;
            $recipientsAccepted = $swiftMailer->send($message, $failedRecipients);
            if (sizeof($failedRecipients) > 0) {
                $this->getSystemLogger()->error(sprintf('Can\'t send mail to %s', implode(', ', $failedRecipients)));
            }
            if ($recipientsAccepted > 0) {
                is_array($to) ? : $to = (array) $to;
                $acceptedRecipients = array_diff($to, $failedRecipients);
                $this->getSystemLogger()->info(
                    sprintf(
                        'Mail successfully sent to %d recipient(s) (%s)',
                        $recipientsAccepted,
                        implode(', ', $acceptedRecipients)
                    )
                );
            }
        }
        $systemLoggers = $this->getSystemLoggers();
        foreach ($systemLoggers as $systemLogger) {
            $systemLogger->error(
                sprintf(
                    'Exported missing option values to file %s!',
                    $filename
                )
            );
        }
    }
public function process ( ) { if ( ! $ this -> getConfiguration ( ) -> isDebugMode ( ) ) { $ this -> getSystemLogger ( ) -> info ( 'Debug mode is not enabled, missing option values will not be exported' ) ; return ; } clearstatcache ( ) ; $ status = $ this -> getRegistryProcessor ( ) -> getAttribute ( RegistryKeys :: STATUS ) ; if ( ! is_dir ( $ sourceDir = $ status [ RegistryKeys :: SOURCE_DIRECTORY ] ) ) { throw new \ Exception ( sprintf ( 'Configured source directory %s is not available!' , $ sourceDir ) ) ; } $ missingOptions = $ status [ RegistryKeys :: MISSING_OPTION_VALUES ] ; if ( sizeof ( $ missingOptions ) === 0 ) { $ this -> getSystemLogger ( ) -> info ( 'Found no missing option values' ) ; return ; } $ artefacts = array ( ) ; 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 ) ) ; } } $ this -> setLastEntityId ( 0 ) ; $ this -> addArtefacts ( MissingOptionValuesPlugin :: ARTEFACT_TYPE , $ artefacts ) ; $ this -> export ( date ( 'Ymd-His' ) , $ counter = '01' ) ; if ( $ swiftMailer = $ this -> getSwiftMailer ( ) ) { $ swiftMailerConfiguration = $ this -> getPluginConfiguration ( ) -> getSwiftMailer ( ) ; $ 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' ) ; $ exportedFilenames = $ this -> getExportAdapter ( ) -> getExportedFilenames ( ) ; foreach ( $ exportedFilenames as $ filename ) { $ message -> attach ( \ Swift_Attachment :: fromPath ( $ filename ) ) ; } $ failedRecipients = array ( ) ; $ recipientsAccepted = 0 ; $ recipientsAccepted = $ swiftMailer -> send ( $ message , $ failedRecipients ) ; if ( sizeof ( $ failedRecipients ) > 0 ) { $ this -> getSystemLogger ( ) -> error ( sprintf ( 'Can\'t send mail to %s' , implode ( ', ' , $ failedRecipients ) ) ) ; } if ( $ recipientsAccepted > 0 ) { is_array ( $ to ) ? : $ to = ( array ) $ to ; $ acceptedRecipients = array_diff ( $ to , $ failedRecipients ) ; $ this -> getSystemLogger ( ) -> info ( sprintf ( 'Mail successfully sent to %d recipient(s) (%s)' , $ recipientsAccepted , implode ( ', ' , $ acceptedRecipients ) ) ) ; } } $ systemLoggers = $ this -> getSystemLoggers ( ) ; foreach ( $ systemLoggers as $ systemLogger ) { $ systemLogger -> error ( sprintf ( 'Exported missing option values to file %s!' , $ filename ) ) ; } }
Process the plugin functionality.
Process the plugin functionality .
// query whether or not, the debug mode has been enabled // clear the filecache // load the actual status // query whether or not the configured source directory is available // load the array with the missing option values from the status // if missing option values are found, return immediately // initialize the array with the artefacts // prepare the artefacts // initialize a dummy last entity ID // add the artefacts (missing option values) and export them as CSV file // query whether or not a swift mailer has been registered // the swift mailer configuration // create the message with the CSV with the missing option values // load the exported filenames // attach the CSV files with the missing option values // initialize the array with the failed recipients // send the mail // query whether or not all recipients have been accepted // if at least one recipient has been accepted // cast 'to' into an array if not already // remove the NOT accepted recipients // log a message with the successfull receivers // load the system loggers // and and log a message that the missing option values has been exported