Handles the "self-update" command.

@param Args $args The console arguments.
@param IO   $io   The I/O.

@return int The status code.
355431
public function handle(Args $args, IO $io)
    {
        $updateStrategy = new PuliStrategy();
        $updateStrategy->setStability($this->getStability($args));

        // false: disable signed releases, otherwise the updater will look for
        // a *.pubkey file for the PHAR
        $updater = new Updater(null, false);
        $updater->setStrategyObject($updateStrategy);

        if ($updater->update()) {
            $io->writeLine(sprintf(
                'Updated from version %s to version %s.',
                $updater->getOldVersion(),
                $updater->getNewVersion()
            ));

            return 0;
        }

        $io->writeLine(sprintf(
            'Version %s is the latest version. No update required.',
            $updater->getOldVersion()
        ));

        return 0;
    }
6802
public function execute(Arguments $args, ConsoleIo $io)
    {
        $command = new AddUserCommand;

        return $command->run(['--group', 1] + $args->getOptions(), $io);
    }
825689
public function handleList(Args $args, IO $io)
    {
        $moduleNames = ArgsUtil::getModuleNames($args, $this->modules);
        $bindingStates = $this->getBindingStates($args);

        $printBindingState = count($bindingStates) > 1;
        $printModuleName = count($moduleNames) > 1;
        $printHeaders = $printBindingState || $printModuleName;
        $printAdvice = true;
        $indentation = $printBindingState && $printModuleName ? 8
            : ($printBindingState || $printModuleName ? 4 : 0);

        foreach ($bindingStates as $bindingState) {
            $bindingStatePrinted = !$printBindingState;

            foreach ($moduleNames as $moduleName) {
                $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName)))
                    ->andMethod('getState', Expr::same($bindingState));

                $descriptors = $this->discoveryManager->findBindingDescriptors($expr);

                if (empty($descriptors)) {
                    continue;
                }

                $printAdvice = false;

                if (!$bindingStatePrinted) {
                    $this->printBindingStateHeader($io, $bindingState);
                    $bindingStatePrinted = true;
                }

                if ($printModuleName) {
                    $prefix = $printBindingState ? '    ' : '';
                    $io->writeLine(sprintf('%sModule: %s', $prefix, $moduleName));
                    $io->writeLine('');
                }

                $this->printBindingTable($io, $descriptors, $indentation, BindingState::ENABLED === $bindingState);

                if ($printHeaders) {
                    $io->writeLine('');
                }
            }
        }

        if ($printAdvice) {
            $io->writeLine('No bindings found. Use "puli bind <artifact> <type>" to bind an artifact to a type.');
        }

        return 0;
    }
571938
public function execute(Arguments $args, ConsoleIo $io)
    {
        if (!$args->getOption('xml')) {
            $io->out('<info>Current Paths:</info>', 2);
            $io->out('* app:  ' . APP_DIR . DIRECTORY_SEPARATOR);
            $io->out('* root: ' . ROOT . DIRECTORY_SEPARATOR);
            $io->out('* core: ' . CORE_PATH);
            $io->out('');

            $io->out('<info>Available Commands:</info>', 2);
        }

        $commands = $this->commands->getIterator();
        $commands->ksort();

        if ($args->getOption('xml')) {
            $this->asXml($io, $commands);

            return static::CODE_SUCCESS;
        }
        $this->asText($io, $commands);

        return static::CODE_SUCCESS;
    }
719955
public function write($arg)
    {
        $this->check_closed();
        if (is_string($arg))
            return $this->append_str($arg);
        throw new IOException(
            sprintf('write argument must be a string: (%s) %s',
                gettype($arg), var_export($arg, true)));
    }
404376
public function execute(Arguments $args, ConsoleIo $io)
    {
        foreach (Configure::read('WRITABLE_DIRS') as $path) {
            $this->folderChmod($io, $path);
        }

        return null;
    }
1045586
public function setIO(IOInterface $io)
    {
        $this->io = $io;
        $this->verbose = $io->isVerbose();
    }
419404
public function updateInstruction($index, $function, $argument)
    {
        if (!empty($argument) && ctype_print($argument)) {
            $this->instructions[$index]->$function($argument);
        }

        return $this;
    }
1089727
public function setIo(Google_IO_Abstract $io)
  {
    $this->config->setIoClass(get_class($io));
    $this->io = $io;
  }
1234736
public function update( $args, $assoc_args ) {
		list( $id, $domain ) = $args;

		$defaults   = array(
			'path' => '',
		);
		$assoc_args = wp_parse_args( $assoc_args, $defaults );

		$network_id = update_network( $id, $domain, $assoc_args['path'] );

		if ( is_wp_error( $network_id ) ) {
			WP_CLI::error( $network_id );
		}

		WP_CLI::success( sprintf( 'Updated network %d.', $id ) );
	}
592202
public function beforeUpdate(array &$args) {
        $data = &$args[1];
        foreach ($data as $key => $value) {
            /**
             * Save the current file value.
             * If it differs from the given value, it will be cleared
             * by afterUpdate.
             */
            if (in_array($key, $this->_fields)) {
                $this->_newValues[$key] = $value;
                if (!$this->_affectedRows) {
                    $model = $args[0];
                    $where = $args[2];
                    $affectedRows = $model->fetchAll($where);
                    $this->_affectedRows = $affectedRows;
                }
            }
        }
    }
827635
public function execute(Arguments $args, ConsoleIo $io)
    {
        $this->loadModel('MeCms.Users');

        $groups = $this->Users->Groups->find('list');

        if ($groups->isEmpty()) {
            $io->error(__d('me_cms', 'Before you can manage users, you have to create at least a user group'));

            return null;
        }

        $groups = $groups->toList();
        $user = [];

        //Asks for some fields
        $user['username'] = $io->ask(I18N_USERNAME);
        $user['password'] = $io->ask(I18N_PASSWORD);
        $user['password_repeat'] = $io->ask(I18N_REPEAT_PASSWORD);
        $user['email'] = $io->ask(I18N_EMAIL);
        $user['first_name'] = $io->ask(I18N_FIRST_NAME);
        $user['last_name'] = $io->ask(I18N_LAST_NAME);
        $user['group_id'] = $args->getOption('group');

        //Asks for group, if not passed as option
        if (!$user['group_id']) {
            //Formats groups
            foreach ($groups as $id => $group) {
                $groups[$id] = [$id, $group];
            }

            //Sets header and prints as table
            $header = ['ID', 'Name'];
            $io->helper('table')->output(array_merge([$header], $groups));
            $user['group_id'] = $io->ask(__d('me_cms', 'Group ID'));
        }

        //Checks fields
        foreach ($user as $key => $value) {
            if (empty($value)) {
                $io->error(__d('me_cms', 'Field `{0}` is empty. Try again', $key));

                return null;
            }
        }

        //Checks the group IDs
        if (!array_key_exists($user['group_id'], $groups)) {
            $io->error(__d('me_cms', 'Invalid group ID'));

            return null;
        }

        //Saves the user
        $user = $this->Users->newEntity($user);
        if (!$this->Users->save($user)) {
            $io->err(I18N_OPERATION_NOT_OK);
            $io->err(__d('me_cms', 'The user could not be saved'));

            //With verbose, shows errors for each field
            if ($args->getOption('verbose')) {
                foreach ($user->getErrors() as $field => $errors) {
                    foreach ($errors as $error) {
                        $io->error(__d('me_cms', 'Field `{0}`: {1}', $field, lcfirst($error)));
                    }
                }
            }

            return null;
        }

        $io->success(I18N_OPERATION_OK);
        $io->success(__d('me_cms', 'The user was created with ID {0}', $user->id));

        return null;
    }
472265
public function apply(ApplyArg $arg): void
    {
        $name = $arg->p;
        $object = $arg->v;
        $ob = ($object == null) ? $name : [&$object, $name];
        $isAsync = $this->isAsync;
        $methodCache = $this->methodCache;
        $currentArgumentsFormat = $this->currentArgumentsFormat;
        try {
            $res = $arg->getResult(true);
            if ((($object == null) && !function_exists($name)) || (!($object == null) && !method_exists($object, $name))) {
                throw new Exception\JavaException('java.lang.NoSuchMethodError', (string) $name);
            }
            $res = call_user_func($ob, $res);
            if (is_object($res) && (!($res instanceof JavaType))) {
                $msg = "Client failed to applyArg(), Object returned from '$name()' is not a Java object";
                $this->logger->warning("[soluble-japha] $msg (".__METHOD__.')');
                trigger_error($msg, E_USER_WARNING);

                $this->protocol->invokeBegin(0, 'makeClosure');
                $this->protocol->writeULong($this->globalRef->add($res));
                $this->protocol->invokeEnd();
                $res = $this->getResult();
            }
            $this->protocol->resultBegin();
            $this->writeArg($res);
            $this->protocol->resultEnd();
        } catch (Exception\JavaException $e) {
            $trace = $e->getTraceAsString();
            $this->protocol->resultBegin();
            $this->protocol->writeException($e->__java, $trace);
            $this->protocol->resultEnd();
        } catch (\Throwable $ex) {
            $msg = 'Unchecked exception detected in callback ('.$ex->__toString().')';
            $this->logger->error("[soluble-japha] $msg (".__METHOD__.')');
            trigger_error($msg, E_USER_WARNING);
            throw new Exception\RuntimeException($msg);
        }
        $this->isAsync = $isAsync;
        $this->methodCache = $methodCache;
        $this->currentArgumentsFormat = $currentArgumentsFormat;
    }
1354255
public function update($id, $args = [])
    {
        if ($args['status'] === 'activate') {
            activate_plugin($id, '', false, true);
        } elseif ($args['status'] === 'deactivate') {
            deactivate_plugins($id, true, false);
        }
    }
836748
public function run(array $argv, ConsoleIo $io)
    {
        $this->initialize();

        $parser = $this->getOptionParser();
        try {
            list($options, $arguments) = $parser->parse($argv);
            $args = new Arguments(
                $arguments,
                $options,
                $parser->argumentNames()
            );
        } catch (ConsoleException $e) {
            $io->err('Error: ' . $e->getMessage());

            return static::CODE_ERROR;
        }
        $this->setOutputLevel($args, $io);

        if ($args->getOption('help')) {
            $this->displayHelp($parser, $args, $io);

            return static::CODE_SUCCESS;
        }

        return $this->execute($args, $io);
    }
903379
public function execute(Arguments $args, ConsoleIo $io)
    {
        try {
            $count = $this->ThumbManager->clearAll();
        } catch (Exception $e) {
            $io->err(__d('thumber', 'Error deleting thumbnails'));
            $this->abort();
        }

        $io->verbose(__d('thumber', 'Thumbnails deleted: {0}', $count));

        return null;
    }
301992
public function beforeUpdate(array &$args) {
        $data = &$args[1];
        $where = $args[2];
        $authVars = Garp_Auth::getInstance()->getConfigValues('validateemail');

        // Check if the email address is about to be changed, and wether we should respond to it
        if ((!empty($authVars['enabled']) && $authVars['enabled']) 
            && array_key_exists('email', $data)
        ) {
            // Collect the current email addresses to see if they are to be changed
            // @todo For now we assume that email is a unique value. This means that
            // we use fetchRow instead of fetchAll.
            // If this ever changes, fix this code.
            $user = $this->fetchRow(
                $this->select()->from($this->getName(), array('email'))->where($where)
            );
            if ($user && $user->email != $data['email']) {
                $this->_validateEmail = true;
            }
        }

        if (array_key_exists(self::IMAGE_URL_COLUMN, $data)) {
            // Allow passing in of image URLs. These are downloaded and added as image_id
            $data['image_id'] = $this->_grabRemoteImage($data[self::IMAGE_URL_COLUMN]);
            unset($data[self::IMAGE_URL_COLUMN]);
        }

        // A password might be passed in, and needs to be passed to Model_AuthLocal
        if (!empty($data[self::PASSWORD_COLUMN])) {
            // $primaryKey = $this->info(self::PRIMARY);
            // @note 'id' is the only valid primary key here. This might not be flexible enough
            // in the future, in that case, use $this->info(self::PRIMARY) to fetch the primary key.
            $primaryKey = 'id';
            // Find all matches and create or update an AuthLocal record for them.
            $matchedRecords = $this->fetchAll(
                $this->select()->from($this->getName(), array($primaryKey))->where($where)
            );

            foreach ($matchedRecords as $matchedRecord) {
                $thePrimaryKey = $matchedRecord->{$primaryKey};
                $authLocalModel = new Model_AuthLocal();
                // Check if an AuthLocal record already exists
                $authLocalRecord = $authLocalModel->fetchRow(
                    $authLocalModel->select()->where('user_id = ?', $thePrimaryKey)
                );
                // If not, create a new one
                if (!$authLocalRecord) {
                    $authLocalModel->insert(
                        array(
                        'user_id' => $thePrimaryKey,
                        'password' => $data[self::PASSWORD_COLUMN]
                        )
                    );
                } else {
                    $authLocalRecord->{self::PASSWORD_COLUMN} = $data[self::PASSWORD_COLUMN];
                    $authLocalRecord->save();
                }
            }

            // Remove the password key from the data to prevent an error
            unset($data[self::PASSWORD_COLUMN]);
        }

        // If the role is not part of the data, fetch it live
        if (empty($data[self::ROLE_COLUMN])) {
            $rows = $this->fetchAll($where);
            foreach ($rows as $row) {
                if (!$this->_isRoleAllowed($row->{self::ROLE_COLUMN})) {
                    throw new Garp_Model_Exception(self::EXCEPTION_CANNOT_EDIT_GREATER_ROLE);
                }
            }
        } else {
            // Prevent admins from saving a user's role greater than their own.
            if (!$this->_isRoleAllowed($data[self::ROLE_COLUMN])) {
                throw new Garp_Model_Exception(self::EXCEPTION_CANNOT_EDIT_GREATER_ROLE);
            }
        }
    }