Add App.

@param AnCommandContext $context Context parameter
18739
protected function _actionAddapp(AnCommandContext $context)
    {
        $data = $context->data;
        $this->getItem()->components->insert($data->app);
        $this->commit();
    }
1337757
protected function _actionAdd($context)
    {
        $data = $context->data;
        $file = AnRequest::get('files.file', 'raw');
        $content = @file_get_contents($file['tmp_name']);
        $filesize = strlen($content);
        $uploadlimit = $this->_max_upload_limit * 1024 * 1024;

        $exif = (function_exists('exif_read_data')) ? @exif_read_data($file['tmp_name']) : array();

        if ($filesize == 0) {
            throw new LibBaseControllerExceptionBadRequest('File is missing');

            return;
        }

        if ($filesize > $uploadlimit) {
            throw new LibBaseControllerExceptionBadRequest('Exceed maximum size');

            return;
        }

        $orientation = 0;

        if (!empty($exif) && isset($exif['Orientation'])) {
            $orientation = $exif['Orientation'];
        }

        $data['portrait'] = array(
            'data' => $content,
            'rotation' => $orientation,
            'mimetype' => isset($file['type']) ? $file['type'] : null,
        );

        $photo = $this->actor->photos->addNew($data);
        $photo->setExifData($exif);
        $photo->save();
        $this->setItem($photo);
        $this->getResponse()->status = AnHttpResponse::CREATED;

        if ($photo->body && preg_match('/\S/', $photo->body)) {
            $context->append(array(
                'story' => array('body' => $photo->body),
            ));
        }

        return $photo;
    }
734354
protected function _actionBrowse(AnCommandContext $context)
    {
        $entities = parent::_actionBrowse($context);

        if(in_array($this->sort, array('top', 'trending')) && $this->q == '') {

            $package = $this->getIdentifier()->package;
            $name = $this->getIdentifier()->name;

            $entities->select('COUNT(*) AS count')
            ->join('RIGHT', 'edges AS edge', $name.'.id = edge.node_a_id')
            ->where('edge.type', 'LIKE', '%com:'.$package.'.domain.entity.tag')->group($name.'.id')
            ->order('count', 'DESC');

            if ($this->sort == 'trending') {
                $now = new AnDate();
                $entities->where('edge.created_on', '>', $now->addDays(-(int) $this->days)->getDate());
            }
        }

        return $entities;
    }
972075
public function register(Application $App) {
        $App->addCommand(new \YourApp\Command\Foo());
        $App->addCommand(new \YourApp\Command\Bar());
        $App->addCommand(new \YourApp\Command\Baz());
    }
73096
protected function _actionDispatch(AnCommandContext $context)
    {
        dispatch_plugin('system.onBeforeDispatch', array( $context ));
        
        $name = 'com_'.$this->getComponent()->getIdentifier()->package;

        define('ANPATH_COMPONENT', ANPATH_BASE.DS.'components'.DS.$name);

        if (! file_exists(ANPATH_COMPONENT)) {
            throw new LibBaseControllerExceptionNotFound(
                'Component '.$name.' not found',
                AnHttpResponse::INTERNAL_SERVER_ERROR
            );
        }

        $app = AnService::get('repos:settings.app')->find(array('package' => $name));

        if (isset($app) && $app->enabled != 1) {
            throw new LibBaseControllerExceptionForbidden(
                'Component '.$name.' is disabled',
                AnHttpResponse::INTERNAL_SERVER_ERROR
            );
        }

        $this->getComponent()->dispatch($context);

        dispatch_plugin('system.onAfterDispatch', array( $context ));

        $location = $context->response->getHeader('Location');
        $isHtml = $context->request->getFormat() == 'html';
        $isAjax = $context->request->isAjax();

        if (! $location && $isHtml && !$isAjax) {
            $this->_render($context);
        }

        $this->send($context);
    }
21493
protected function _actionEdit(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::RESET_CONTENT;

        return $this->getItem()->setData($context['data']);
    }
438297
public function redirect(AnCommandContext $context)
    {
        $url = null;

        if ($context->action == 'delete') {
            $url = 'option=com_'.$this->getIdentifier()->package.'&view='.AnInflector::pluralize($this->getIdentifier()->name);
        } elseif ($context->action == 'add') {
            $url = $context->result->getURL().'&get=settings';
        }

        if ($url) {
            $context->response->setRedirect(route($url));
        }
    }
1324871
public function addContext(array $context)
    {
        if ($context) {
            $this->context = array_merge($this->context, $context);
        }

        return $this;
    }
1250055
public function addContext(Context $context) {
    $contexts = $this->get('contextOut');
    $contexts[] = $context;
    $this->add('contextOut', $contexts);
  }
323463
protected function _actionAdd(AnCommandContext $context)
    {
        $context->response->status = AnHttpResponse::CREATED;
        $entity = $this->getRepository()->getEntity()->setData($context['data']);
        $this->setItem($entity);

        return $this->getItem();
    }
753760
protected function _actionPrepclienv(AnCommandContext $context)
    {
        if (! empty($_SERVER['argv']) && count($_SERVER['argv']) > 1) {
            $args = array_slice($_SERVER['argv'], 1);

            if (is_readable(realpath($args[0]))) {
                $file = array_shift($args);
            }

            $args = explode('&-data&', implode($args, '&'));
            $args = array_filter($args, 'trim');

            foreach ($args as $i => $arg) {
                $arg = trim($arg);

                if ($i == 0) {
                    if (strpos($arg, '/') !== false) {
                        $arg = substr_replace($arg, '?', strpos($arg, '&'), 1);
                        $url = AnService::get('anahita:http.url', array('url' => $arg));
                        AnRequest::url()->path = AnRequest::base().$url->path;
                        $_GET = $url->query;
                    } else {
                        AnRequest::url()->path = AnRequest::base();
                        parse_str($arg, $_GET);
                    }
                } else {
                    parse_str($arg, $_POST);
                }
            }
        }

        $_GET['format'] = 'json';
        AnRequest::url()->format = 'json';
        AnRequest::url()->setQuery($_GET);

        AnService::get('com:plugins.helper')->import('cli');
        dispatch_plugin('cli.onCli');

        //if there's a file then just load the file and exit
        if (! empty($file)) {
            AnService::get('anahita:loader')->loadFile($file);
            exit(0);
        }
    }
481709
public function notifyMentioned(AnCommandContext $context)
    {
        $entity = $this->getItem();
        $subscribers = array();

        foreach ($this->_newly_mentioned as $username) {
            $person = $this->getService('repos:people.person')->find(array('username' => $username));

            if ($person && $person->authorize('mention')) {
                $subscribers[] = $person->id;
            }
        }

        if (count($subscribers) == 0) {
            return;
        }

        if ($entity instanceof ComBaseDomainEntityComment) {
            $parentIdentifier = $entity->parent->getIdentifier()->name;
            $parentController = $this->getService('com:'.AnInflector::pluralize($parentIdentifier).'.controller.'.$parentIdentifier);

            if ($parentController->isNotifier() && $entity->parent->isSubscribable()) {
                $data = array(
                    'name' => 'actor_mention_comment',
                    'object' => $entity,
                    'comment' => $entity,
                    'component' => $entity->parent->component,
                    'subscribers' => $subscribers,
                );

                $parentController->createNotification($data);
            }
        } else {
            $data = array(
                'name' => 'actor_mention',
                'object' => $entity,
                'component' => $entity->component,
                'subscribers' => $subscribers,
            );

            $notification = $this->_mixer->createNotification($data);
        }
    }
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;
    }
1053322
protected function _actionProcess(AnCommandContext $context)
    {
        // run this no more than 1 minute
        //set_time_limit(60);

        $query = $this->getService('repos:notifications.notification')
                      ->getQuery(true)
                      ->status(ComNotificationsDomainEntityNotification::STATUS_NOT_SENT);

        if ($this->id) {
            $ids = (array) AnConfig::unbox($this->id);
            $query->id($ids);
        }

        $notifications = $query->fetchSet();

        $this->sendNotifications($notifications);
    }
238662
protected function _afterEntityUpdate(AnCommandContext $context)
    {
        if (isset($this->_pending_files[$this->_mixer])) {
            $files = $this->_pending_files[$this->_mixer];

            foreach ($files as $filename => $data) {
                $this->_mixer->writeData($filename, $data);
            }

            unset($this->_pending_files[$this->_mixer]);
        }
    }
644375
protected function _actionBrowse(AnCommandContext $context)
    {
        $context->append(array(
            'query' => $this->getRepository()->getQuery(),
        ));

        $query = $context->query;

        if ($this->q) {
            $query->keyword($this->getService('anahita:filter.term')
                                 ->sanitize($this->q));
        }

        if ($this->ids) {
            $ids = AnConfig::unbox($this->ids);
            $query->id($ids);
        } else {
            $query->limit($this->limit, $this->start);
        }

        $entities = $query->toEntitySet();

        if ($this->isOwnable() && $this->actor) {
            $this->_state->append(array(
                'filter' => 'following',
            ));

            if (
                $this->filter == 'administering' &&
                $this->getRepository()->hasBehavior('administrable')
                ) {
                $entities->where('administrators.id', 'IN', array($this->actor->id));
            } elseif ($this->actor->isFollowable()) {
                $entities->where('followers.id', 'IN', array($this->actor->id));
            }
        }

        $entities->order('created_on', 'desc');

        return $this->setList($entities)->getList();
    }
335962
public function addCover(AnCommandContext $context)
    {
        $entity = $this->getItem();
        
        if ($entity->isCoverable() && AnRequest::has('files.cover')) {
            $file = AnRequest::get('files.cover', 'raw');

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

        return $entity;
    }