After adding a subscriptions add the person as a follower to all the package actors.

AnCommandContext $context Context
512103
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $actorIds = $this->package->getActorIds();

        if (count($actorIds)) {
            $actors = $this->getService('repos:actors.actor')
                           ->getQuery(true)
                           ->where('id', 'IN', $actorIds)
                           ->fetchSet();

            foreach ($actors as $actor) {
                $actor->addFollower($this->person);
            }
        }
    }
1048867
public function addListCommands()
    {
        //the context actor
        $actor1 = $this->getController()->actor;

        //the actor entity that the actions are being evaluated against
        $actor2 = $this->getController()->getItem();

        //if actor is not available, then all the against are with respect to the viewer
        $actor1 = pick($actor1, get_viewer());

        //if context actor is administrable (i.e. groups) then actions are administaration actions
        if ($actor1->isAdministrable()) {
            //if adding new followers is allowed
            if ($actor1->authorize('lead')) {
                if ($command = $this->getLeadCommand($actor1, $actor2)) {
                    $labels = array();
                    $labels[] = 'COM-'.strtoupper($this->getIdentifier()->package).'-SOCIALGRAPH-'.strtoupper($command->action);
                    $labels[] = 'COM-ACTORS-SOCIALGRAPH-'.strtoupper($command->action);
                    $command->label = translate($labels);
                    $this->addCommand($command);
                }
            }

            $graphType = AnRequest::get('get.type', 'cmd', 'followers');

            if ($actor1->authorize('administration') && $graphType != 'leadables') {
                $this->_update = false;
                if ($command = $this->getBlockCommand($actor1, $actor2)) {
                    $labels = array();
                    $labels[] = 'COM-'.strtoupper($this->getIdentifier()->package).'-SOCIALGRAPH-'.strtoupper($command->action);
                    $labels[] = 'COM-ACTORS-SOCIALGRAPH-'.strtoupper($command->action);
                    $command->label = translate($labels);
                    $this->addCommand($command);
                }
            }
        } else {
            $this->_update = true;

            if ($command = $this->getFollowCommand($actor1, $actor2)) {
                $label = pick($command->label, $command->name);
                $labels = array();
                $labels[] = 'COM-'.strtoupper($this->getIdentifier()->package).'-SOCIALGRAPH-'.strtoupper($label);
                $labels[] = 'COM-ACTORS-SOCIALGRAPH-'.strtoupper($label);
                $command->label = translate($labels);
                $this->addCommand($command);
            }

            $this->_update = false;

            if ($command = $this->getBlockCommand($actor1, $actor2)) {
                $labels = array();
                $labels[] = 'COM-'.strtoupper($this->getIdentifier()->package).'-SOCIALGRAPH-'.strtoupper($command->name);
                $labels[] = 'COM-ACTORS-SOCIALGRAPH-'.strtoupper($command->name);
                $command->label = translate($labels);
                $this->addCommand($command);
            }
        }
    }
1068216
protected function _actionAdd(AnCommandContext  $context)
     {
         $data = $context->data;

         dispatch_plugin('user.onBeforeAddPerson', array('data' => $context->data));

         $person = parent::_actionAdd($context);

         $this->getRepository()
         ->getValidator()
         ->addValidation('givenName', 'required')
         ->addValidation('familyName', 'required')
         ->addValidation('usertype', 'required')
         ->addValidation('username', 'uniqueness')
         ->addValidation('email', 'uniqueness');

         if ($person->validate() === false) {
             throw new AnErrorException($person->getErrors(), AnHttpResponse::BAD_REQUEST);
         }

         $viewer = get_viewer();

         if (in_array($data->usertype, $this->_allowed_user_types)) {
             $person->usertype = $data->usertype;
         } else {
             $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_REGISTERED;
         }

         dispatch_plugin('user.onAfterAddPerson', array('person' => $person));

         if ($person->admin()) {
             $this->registerCallback('after.add', array($this, 'mailAdminsNewAdmin'));
         }
         
         $context->response->setRedirect(route('option=com_people&view=people'));
         
         return $person;
     }
96856
protected function _actionSignup(AnCommandContext  $context)
    {
        $data = $context->data;

        dispatch_plugin('user.onBeforeAddPerson', array('data' => $context->data));

        $isFirstUser = !(bool) $this->getService('repos:people.person')
                                    ->getQuery(true)
                                    ->fetchValue('id');

        $person = parent::_actionAdd($context);

        $this->getRepository()
        ->getValidator()
        ->addValidation('givenName', 'required')
        ->addValidation('familyName', 'required')
        ->addValidation('username', 'uniqueness')
        ->addValidation('email', 'uniqueness');

        if ($person->validate() === false) {
            throw new AnErrorException($person->getErrors(), AnHttpResponse::BAD_REQUEST);
        }

        $viewer = get_viewer();

        if ($isFirstUser) {
            $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_SUPER_ADMINISTRATOR;
        } else {
            $person->usertype = ComPeopleDomainEntityPerson::USERTYPE_REGISTERED;
        }

        dispatch_plugin('user.onAfterAddPerson', array('person' => $person));

        if ($isFirstUser) {
            $this->registerCallback('after.signup', array($this, 'activateFirstAdmin'));
        } else {
            $context->response->setHeader('X-User-Activation-Required', true);
            $this->setMessage(AnTranslator::sprintf('COM-PEOPLE-PROMPT-ACTIVATION-LINK-SENT', $person->name), 'success');
        }
        
        $this->getResponse()->status = AnHttpResponse::OK;

        return $person;
    }
191092
protected function _actionPost(AnCommandContext $context)
    {
        $data = $context->data;

        $viewer = get_viewer();

        $setting = $this->getService('repos:notifications.setting')->findOrAddNew(array(
            'person' => $viewer,
            'actor' => $this->actor,
        ));

        $setting->setValue('posts', null, $data->email);

        $setting->save();
    }
497527
def push_subscription_update(self, follow_events=None, 
                              favourite_events=None, reblog_events=None, 
                              mention_events=None):
        
        params = {}
        
        if follow_events != None:
            params['data[alerts][follow]'] = follow_events
        
        if favourite_events != None:
            params['data[alerts][favourite]'] = favourite_events
            
        if reblog_events != None:
            params['data[alerts][reblog]'] = reblog_events
            
        if mention_events != None:
            params['data[alerts][mention]'] = mention_events
            
        return self.__api_request('PUT', '/api/v1/push/subscription', params)
1287011
protected function _actionInvite($context)
    {
        $data = $context->data;
        $viewer = get_viewer();
        $emails = $data->email;

        foreach ($emails as $email) {

            if ($this->getService('anahita:filter.email')->validate($email)) {

                $person = $this->getService('repos:people.person')->find(array('email' => $email));

                if (!$person) {

                    $token = $this->getService('repos:invites.token')->getEntity(array(
                        'data' => array(
                            'inviter' => $viewer,
                            'serviceName' => 'email',
                        ),
                    ));

                    $token->save();

                    $settings = $this->getService('com:settings.setting');

                    $mails[] = array(
                        'subject' => AnTranslator::sprintf('COM-INVITES-MESSAGE-SUBJECT', $settings->sitename),
                        'to' => $email,
                        'layout' => false,
                        'template' => 'invite',
                        'data' => array(
                            'invite_url' => $token->getURL(),
                            'site_name' => $settings->sitename,
                            'sender' => $viewer,
                        ),
                    );

                    $this->mail($mails);
                }
            }
        }
    }
1105781
protected void addAnnotationSuspendedUser(NotificationContext context, SubSystem subSystem) {
        Alert alert = context.getAlert();
        PrincipalUser wardenUser = getWardenUser(alert.getName());
        Metric metric = null;

        Map<Long, Double> datapoints = new HashMap<>();

        metric = new Metric(Counter.WARDEN_TRIGGERS.getScope(), Counter.WARDEN_TRIGGERS.getMetric());
        metric.setTag("user", wardenUser.getUserName());
        datapoints.put(context.getTriggerFiredTime(), 1.0);
        metric.setDatapoints(datapoints);
        _tsdbService.putMetrics(Arrays.asList(new Metric[] { metric }));

        Annotation annotation = new Annotation(ANNOTATION_SOURCE, wardenUser.getUserName(), ANNOTATION_TYPE, Counter.WARDEN_TRIGGERS.getScope(),
            Counter.WARDEN_TRIGGERS.getMetric(), context.getTriggerFiredTime());
        Map<String, String> fields = new TreeMap<>();

        fields.put("Suspended from subsystem", subSystem.toString());
        fields.put("Alert Name", alert.getName());
        fields.put("Notification Name", context.getNotification().getName());
        fields.put("Trigger Name", context.getTrigger().getName());
        annotation.setFields(fields);
        _annotationService.updateAnnotation(alert.getOwner(), annotation);
    }
427147
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->administrable->getRepository()
                            ->getBehavior('administrable')
                            ->resetStats(array(
                              $this->administrable,
                              $this->administrator, ));
    }
177401
public function validateUser(AnCommandContext $context)
    {
        $package = $this->getItem();

        //validate user
        if (get_viewer()->guest() && !$this->person->validateEntity()) {
            $url = route('option=com_subscriptions&view=signup&layout=login&id='.$package->id);
            $context->response->setRedirect($url);
            return false;
        }

        return true;
    }
1035154
def add_to_watched(self, watched):
        
        assert isinstance(watched, github.Repository.Repository), watched
        headers, data = self._requester.requestJsonAndCheck(
            "PUT",
            "/repos/" + watched._identity + "/subscription",
            input={"subscribed": True}
        )
152106
protected function _beforeControllerAdd(AnCommandContext $context)
    {
        if (!$context->data['owner'] instanceof ComActorsDomainEntityActor) {
            if ($this->getRepository()->hasBehavior('ownable')) {
                $context->data['owner'] = $this->actor;
            }
        }
    }
747823
protected function _actionAdd(AnCommandContext $context)
    {
        $entity = parent::_actionAdd($context);

        if ($entity->isPortraitable() && AnRequest::has('files.portrait')) {
            $file = AnRequest::get('files.portrait', 'raw');

            if ($this->bellowSizeLimit($file) && $file['error'] == 0) {
                $entity->setPortrait(array(
                   'url' => $file['tmp_name'],
                   'mimetype' => $file['type'],
                   )
               );
            }
        }

        return $entity;
    }
1090253
protected function _actionGetgraph(AnCommandContext $context)
    {
        $this->getState()->insert('type', 'followers');

        $filters = array();
        $entities = array();
        $entity = $this->getItem();
        $viewer = get_viewer();

        if ($this->getItem()->isFollowable()) {
            if ($this->type == 'followers') {
                $entities = $this->getItem()->followers;
            } elseif ($this->type == 'blockeds' && $entity->authorize('administration')) {
                $entities = $this->getItem()->blockeds;
            } elseif ($this->type == 'leadables') {
                if (!$entity->authorize('leadable')) {
                    throw new LibBaseControllerExceptionForbidden('Forbidden');
                }

                $excludeIds = AnConfig::unbox($entity->followers->id);

                $excludeIds = array_merge($excludeIds, AnConfig::unbox($entity->blockeds->id));

                if ($viewer->admin()) {
                    $entities = $this->_mixer->getService('com:people.domain.entity.person')
                                ->getRepository()->getQuery()
                                ->where('person.id', 'NOT IN', $excludeIds);
                } else {
                    $entities = $viewer->followers->where('actor.id', 'NOT IN', $excludeIds);
                }
            }
        }

        if ($this->getItem()->isLeadable()) {
            if ($this->type == 'leaders') {
                $entities = $this->getItem()->leaders;
            } elseif ($this->type == 'mutuals') {
                $entities = $this->getItem()->getMutuals();
            } elseif ($this->type == 'commonleaders') {
                $entities = $this->getItem()->getCommonLeaders(get_viewer());
            }
        }

        if (!$entities) {
            return false;
        }

        $xid = (array) AnConfig::unbox($this->getState()->xid);

        if (!empty($xid)) {
            $entities->where('id', 'NOT IN', $xid);
        }

        $entities->limit($this->limit, $this->start);

        if ($this->q) {
            $entities->keyword($this->q);
        }

        $this->setList($entities->fetchSet())->actor($this->getItem());

        return $entities;
    }
1289423
public function fetchSubscriber(AnCommandContext $context)
    {
        if (!$this->_subscriber) {

            $actor_id = $context->data->actor_id;
            $this->_subscriber = $this->getService('repos:actors.actor')->fetch($actor_id);

            if (!$this->_subscriber) {
                throw new LibBaseControllerExceptionNotFound('Subscriber Not Found');
            }
        }

        return $this->_subscriber;
    }
24200
protected function _afterControllerAdd(AnCommandContext $context)
    {
        $data = $context->data;

        if ($data->composed && $data->story) {
            if ($context->response->isRedirect()) {
                $context->response->setStatus(AnHttpResponse::OK);
                $context->response->removeHeader('Location');
            }

            $content = $this->_renderComposedStory($data->story);
            $context->response->setContent($content);
        }
    }
525442
protected function _afterEntityInsert(AnCommandContext $context)
    {
        parent::_afterEntityInsert($context);

        if ($this->_send_after_insert) {
            //run no more than 30 seconds
            $command = sprintf('php -d max_execution_time=30 %s/index.php %s id=%d >/dev/null 2>&1', ANPATH_BASE, PROCESSOR_PATH, $context->entity->id);
            //error_log($command);
            $result = exec_in_background($command);
        }
    }