public function saveVisitorAffiliate(Pap_Common_VisitorAffiliateCacheCompoundContext $cacheCompoundContext) {
        $cacheCompoundContext->setVisitorAffiliateAlreadySaved(true);

        $context = $cacheCompoundContext->getContext();
        $cache = $cacheCompoundContext->getVisitorAffilliateCache();
        $context->debug('Saving VisitorAffiliate by SplitCommissions started');

        Pap_Features_SplitCommissions_VisitorAffiliateCheckCompatibility::getHandlerInstance()->checkCompatibility($context->getVisitorId(), $cache);

        $rows = $cache->getVisitorAffiliateAllRows($context->getVisitorId());
        $oldVisitorAffiliate = null;

        $lastClickVisitorAffiliate = null;
        $firstClickVisitorAffiliate = null;

        foreach ($rows as $row) {
            if (!$row->isValid()) {
                continue;
            }
            if ($firstClickVisitorAffiliate == null ||
            $firstClickVisitorAffiliate->getDateVisit() > $row->getDateVisit()) {
                $firstClickVisitorAffiliate = $row;
            }

            if ($lastClickVisitorAffiliate == null ||
            $lastClickVisitorAffiliate->getDateVisit() < $row->getDateVisit()) {
                $lastClickVisitorAffiliate = $row;
            }

            if ($row->isActual()) {
                $row->setActual(false);
            }
        }

        $oldVisitorAffiliate = $this->findAlreadyStoredVisitorAffiliate($rows, $firstClickVisitorAffiliate, $context);

        if ($firstClickVisitorAffiliate == null) {
            $firstVisitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId());
            Pap_Tracking_Click_SaveVisitorAffiliate::prepareVisitorAffiliate($firstVisitorAffiliate, $context);
            $rows->add($firstVisitorAffiliate);

            $visitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId());
        } else {
            $visitorAffiliate = $this->getVisitorAffiliate($firstClickVisitorAffiliate,
            $oldVisitorAffiliate, $cache, $context);

            if ($oldVisitorAffiliate == null && 
            $visitorAffiliate === $firstClickVisitorAffiliate) {
                Pap_Tracking_Click_SaveVisitorAffiliate::prepareVisitorAffiliate($visitorAffiliate, $context);
                $visitorAffiliate = $cache->createVisitorAffiliate($context->getVisitorId()); 
            }
        }

        if ($visitorAffiliate == null) {
            $context->debug('SplitCommission VisitorAffiliate no updated - not actual data');
            return;
        }

        Pap_Tracking_Click_SaveVisitorAffiliate::prepareVisitorAffiliate($visitorAffiliate, $context);

        if ($oldVisitorAffiliate == null && $firstClickVisitorAffiliate !== $visitorAffiliate) {
            $rows->add($visitorAffiliate);
        }

        $context->debug('New visitorAffiliate added/saved by SplitCommissions');
    }
 private function setVisitorAffiliateValidity(Pap_Db_VisitorAffiliate $visitorAffiliate) {
     $this->context->setVisitorAffiliate($visitorAffiliate);
     $this->recognizeAffiliate->recognize($this->context);
     $this->recognizeCampaign->recognize($this->context);
     $this->recognizeCommGroup->recognize($this->context);
     $visitorAffiliate->setValidTo(Pap_Tracking_Click_SaveVisitorAffiliate::getVisitorAffiliateValidity($this->context, $visitorAffiliate));
 }