public function run()
    {
        $cluster = ClusterTool::clusterIdentifier();

        if ( !$cluster )
        {
            $this->debug( 'MMLyrisUserImportHandler : Used siteaccess is not a cluster, run the cronjob with a cluster siteaccess', 'Lyris' );
            return;
        }

        $db = eZDB::instance();
        /* @type $clusterMapping array */
        $clusterMapping = eZINI::instance( 'merck.ini' )->variable( 'ClusterSettings', 'CountryMapping' );

        try
        {
            $this->debug( 'MMLyrisUserImportHandler : BEGIN', 'Lyris' );

            $countries = array_keys( $clusterMapping, $cluster );

            foreach ( $countries as $currentCountryLanguage )
            {
                list( $currentCountry, $currentLanguage ) = explode( '|', $currentCountryLanguage );

                $this->debug( "MMLyrisUserImportHandler : Now treating country '$currentCountry' with language '$currentLanguage' (could be empty)", 'Lyris' );

                $userImportList = MMLyrisUserImport::fetchUnprocessedListByCountryLanguage( $currentCountry, $currentLanguage, null, false );

                foreach ( $userImportList as &$item )
                {
                    $username = trim( $item['username'] );
                    $country = trim( $item['country_registration'] );

                    $this->debug( 'Importing <' . $username . ' -- ' . $country . '>... ', 'Lyris' );
                    $db->begin();

                    $mainSpecialty = trim( $item['specialty'] );

                    $mmUser = MMUsers::fetchByIdAndCountry( $username, $country );
                    if ( empty( $mmUser ) )
                    {
                        $m = array();
                        if ( preg_match('#^216\.#', $mainSpecialty, $m) )
                        {
                            $contentSpecialty = UserSpecialityContentSpeciality::getContentSpeciality ( $mainSpecialty );
                            $specialties = MMUserLogin::getAddSpecialties( $contentSpecialty );
                        }
                        else
                            $specialties = MMUserLogin::getAddSpecialties( $mainSpecialty );

                        $applications = CountryAppsBar::fetchAppsBarApplicationIds( $item['customer_type'], $mainSpecialty, $country );
                        $customerType = $item['customer_type'];
                    }
                    else
                    {
                        $applications = $mmUser->getApplicationList();
                        $country = trim( $mmUser->attribute( 'country' ) );
                        $mainSpecialty = trim( $mmUser->userSpecialityId() );
                        $mSpe = trim( $mmUser->mainSpecialityId() );
                        $specialties = $mmUser->getSpecialities();

                        if ( ($i = array_search($mSpe, $specialties)) !== false )
                        {
                            unset($specialties[$i]);
                        }

                        $customerType = $mmUser->customerTypeId();
                    }

                    $mmUserExport = MMLyrisUserExport::fetchByUsernameAndCountry( $username, $country );

                    // Remove old entry to be sure NULL values will be set :
                    if ( !empty( $mmUserExport ) )
                    {
                        $mmUserExport->remove();
                    }
                    $mmUserExport = new MMLyrisUserExport( array(
                        'username' => $username
                    ) );
                    $mmUserExport->setAttribute( 'processed', 0 );
                    $mmUserExport->setAttribute( 'country_registration', empty( $country ) ? null : $country );
                    $mmUserExport->setAttribute( 'user_specialty', empty( $mainSpecialty ) ? null : $mainSpecialty );
                    $additionalSpecialties = trim( implode( ',', $specialties ) );
                    $mmUserExport->setAttribute( 'additional_specialties', empty( $additionalSpecialties ) ? null : $additionalSpecialties );
                    $mmUserExport->setAttribute( 'apps', $this->createXML( $applications ) );
                    $mmUserExport->setAttribute( 'customer_type', $customerType );

                    $mmUserExport->store();

                    $mmUserImport = MMLyrisUserImport::fetchByUsernameAndCountry( $username, $country );

                    if ( $mmUserImport instanceof MMLyrisUserImport )
                    {
                        $mmUserImport->setAttribute( 'processed', 1 );
                        $mmUserImport->store();
                    }
                    else
                    {
                        $this->debug( "User '$username' does not exist in '$country' !!!", 'LYRIS IMPORT ERROR', eZDebug::LEVEL_ERROR );
                    }

                    $db->commit();
                    $this->debug( '... DONE.', 'Lyris' );

                }
                $this->debug( count( $userImportList ) . ' items treated', 'MMLyrisUserImportHandler : END' );
            }
        }
        catch ( Exception $e )
        {
            $this->debug( $e, 'LYRIS IMPORT ERROR', eZDebug::LEVEL_ERROR );
            $db->rollback();
        }
    }
 public function tagLyrisToProcess()
 {
     $mmUserImport = MMLyrisUserImport::fetchByUsernameAndCountry( $this->attribute( 'uuid' ), $this->attribute( 'country' ) );
     if ( ! empty( $mmUserImport ) )
     {
         $mmUserImport->setAttribute( 'processed', 0 );
         $mmUserImport->store();
     }
 }