Before Update.

@param AnCommandContext $context
330870
protected function _beforeEntityUpdate(AnCommandContext $context)
    {
        if ($this->getModifiedData()->ordering) {
            $store = $this->getRepository()->getStore();
            $query = $this->getScopedQuery($context->entity);
            $change = $this->getModifiedData()->ordering;

            if ($change->new - $change->old < 0) {
                $query->update('@col(ordering) = @col(ordering) + 1');
                $query->where('ordering', '>=',  $change->new)->where('ordering', '<',   $change->old);
            } else {
                $query->update('@col(ordering) = @col(ordering) - 1');
                $query->where('ordering', '>',   $change->old)->where('ordering', '<=',  $change->new);
            }

            $store->execute($query);
        }
    }
1072997
protected function _beforeUpdate(DatabaseContextInterface $context)
    {
        if(isset($this->order) && $this->hasProperty('ordering')) {
            $this->order($this->order);
        }
    }
434384
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        if (AnService::has('viewer')) {
            $query = $context->query;
            $repository = $query->getRepository();
            $viewer = get_viewer();

            if ($viewer->id) {
                $query->where("IF( FIND_IN_SET({$viewer->id}, @col(blockedIds)), 0, 1)");
            }
        }
    }
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]);
        }
    }
413513
public function updateHashtagsFromBody(AnCommandContext $context)
    {
        $entity = $this->getItem();
        $terms = $this->extractHashtagTerms($entity->body);
        
        if (is_array($terms)) {
            foreach ($entity->hashtags as $hashtag) {
                if (!in_array($hashtag->name, array_map('strtolower', $terms))) {
                    $entity->removeHashtag($hashtag->name);
                }
            }
        }

        foreach ($terms as $term) {
            $entity->addHashtag(trim($term));
        }
    }
557849
protected function _actionRemoveapp(AnCommandContext $context)
    {
        $data = $context->data;
        $this->getItem()->components->extract($data->app);
        $this->commit();
    }
516992
protected function _afterEntityInsert(AnCommandContext $context)
    {
        $this->parent->getRepository()
                     ->getBehavior('commentable')
                     ->resetStats(array($this->parent));
        $this->parent->execute('after.comment', array('comment' => $this));
    }
418694
protected function _afterEntityDelete(AnCommandContext $context)
    {
        $this->getSpace()->setEntityState($context->entity, AnDomain::STATE_DESTROYED);
    }
44523
protected function _beforeInsert(KDatabaseContextInterface $context)
    {
        if($this->hasProperty('ordering'))
        {
            if($this->ordering <= 0) {
                $this->ordering = $this->getMaxOrdering() + 1;
            } else {
                $this->reorder($this->ordering);
            }
        }
    }
1061866
public function execute($name, AnCommandContext $context)
    {
        $parts = explode('.', $name);

        if ($parts[0] == 'before') {
            $this->_fetchOwner($context);
        }

        parent::execute($name, $context);
    }
1155657
protected function _beforeUpdate(DatabaseContext $context)
    {
        //Get the modified columns
        $modified  = $this->getTable()->filter($this->getProperties(true));

        if(!empty($modified)) {
            $this->_beforeInsert($context);
        }
    }
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);
        }
    }
405563
protected function _beforeRepositoryFetch(AnCommandContext $context)
    {
        //check if the query is retrieving a unique entity
        //if yes check if we already have the entity in the
        //repository or not
        $key = $context->query->getKey();
        if ($key) {
            $context->data = $this->find($key, false);
            if ($context->data) {
                return false;
            }
        }
    }
934408
protected function _afterEntityDelete(AnCommandContext $context)
    {
        $this->subscribee->getRepository()
                         ->getBehavior('subscribable')
                         ->resetStats(array($this->subscribee));
    }
1349055
protected function _beforeInsert(KDatabaseContext $context)
    {
        $method = 'get'.ucfirst($this->_column);
        if($context->data->$method() instanceof KObjectConfigInterface) {
            $context->data->setProperty($this->_column, $context->data->$method()->toString());
        }
    }
26290
protected function _beforeEdit(KControllerContextInterface $context)
    {
        if ($this->getMixer()->getIdentifier()->name === $this->_category_entity)
        {
            $collection = $this->getModel()->fetch();

            foreach ($collection as $entity)
            {
                $entity->old_enabled = $entity->enabled;
                $entity->old_access  = $entity->access;
            }
        }
    }
18739
protected function _actionAddapp(AnCommandContext $context)
    {
        $data = $context->data;
        $this->getItem()->components->insert($data->app);
        $this->commit();
    }