Add job by operation type.

@param OperationInterface $operation
@param \Closure $install
@param \Closure $update
@param \Closure $uninstall
771316
protected static function addJobByOperationType(
        OperationInterface $operation,
        \Closure $install,
        \Closure $uninstall,
        \Closure $update = null
    ) {
        switch ($operation->getJobType()) {
            case 'install':
                self::getContainer()->addJob($install($operation->getPackage()));
                break;
            case 'uninstall':
                self::getContainer()->addJob($uninstall($operation->getPackage()));
                break;
            case 'update':
                $update = $update ?: $install;
                self::getContainer()->addJob($update($operation->getTargetPackage()));
                break;
        }
    }
373231
private function runOperation(PromiseOperation $operation)
    {
        $promise = $operation->getPromise();

        return $promise->then(
            $this->onTerminate($operation, $this->fulfilledVoter, true, $promise),
            $this->onTerminate($operation, $this->rejectedVoter, false, $promise)
        );
    }
917611
public function buildOperationList()
    {
        $this->log('Building install/update operations list...');

        $previous = $this->openRepository($this->previousRepoFile);
        $current = $this->openRepository($this->installedRepoFile);
        $operations = [];

        /** @var PackageInterface $currentPackage */
        foreach ($current->getCanonicalPackages() as $currentPackage) {
            if (!($previousPackage = $previous->findPackage($currentPackage->getName(), '*'))) {
                $this->log("Installation of {$currentPackage->getName()} required");
                $operation = $this->buildOperation(Operation::INSTALL, $currentPackage);
                $operations[$operation->getBundleFqcn()] = $operation;
            } elseif ($currentPackage->getVersion() !== $previousPackage->getVersion()
                || $currentPackage->isDev()) {
                $this->log(sprintf(
                    'Update of %s from %s to %s required',
                    $previousPackage->getName(),
                    $previousPackage->getVersion(),
                    $currentPackage->getVersion()
                ));
                $operation = $this->buildOperation(Operation::UPDATE, $currentPackage);
                $operation->setFromVersion($previousPackage->getVersion());
                $operation->setToVersion($currentPackage->getVersion());
                $operations[$operation->getBundleFqcn()] = $operation;
            }
        }

        // TODO: we *should* do something in case a platform package is
        // removed (e.g. if the package is a plugin, at least unregister it)
        // but AFAIK we don't have anything now to support removal of a bundle
        // whose sources are already gone. Maybe the platform installer could
        // look after each update if there are records in the plugin table
        // that don't match any known bundle?

        $this->log('Sorting operations...');
        $bundles = $this->kernel->getBundles();
        $sortedOperations = [];

        foreach ($bundles as $bundle) {
            $bundleClass = $bundle->getNamespace() ?
                $bundle->getNamespace() . '\\' . $bundle->getName() :
                $bundle->getName();

            if (isset($operations[$bundleClass])) {
                $sortedOperations[] = $operations[$bundleClass];
            }
        }

        return $sortedOperations;
    }
836089
public void addOperations(final Map<MemcachedNode, Operation> ops) {
    for (Map.Entry<MemcachedNode, Operation> me : ops.entrySet()) {
      addOperation(me.getKey(), me.getValue());
    }
  }
828035
public function remove(OperationState $operation = NULL)
    {
        if (is_null($operation)) {
            array_pop($this->operationQueue);
            return TRUE;
        } else {
            if ($this->isInQueue($operation)) {
                unset($this->operationQueue[$operation->getKey()]);
                return TRUE;
            }
            return FALSE;
        }
    }
80584
function applyOps(data, ops, className) {
  debugPrint('OPS', ops);
  _.forIn(ops, (value, key) => {
    const operator = value.__op;

    if (operator in UPDATE_OPERATORS) {
      UPDATE_OPERATORS[operator](data, key, value, className);
    } else {
      throw new Error(`Unknown update operator: ${key}`);
    }

    if (MASKED_UPDATE_OPS.has(operator)) {
      getMask(className).add(key);
    }
  });
}
599993
public function install(): OperationResult
    {
        $result = new OperationResult();

        $sourceFile = "{$this->packageInstallDir}/.installer/%s/.env";
        foreach ($this->projectType->getProjectDirs() as $projectDir) {
            $envFile = sprintf($sourceFile, $projectDir);
            if (is_file($envFile)) {
                $content = "\n";
                $content .= "###BEGIN-Rikudou-Installer-{$this->packageName}###\n";
                $content .= "# Do not remove the above line if you want the installer to be able to delete the content on uninstall\n";
                $content .= file_get_contents($envFile) . "\n";
                $content .= "###END-Rikudou-Installer-{$this->packageName}###";

                foreach (self::ENV_FILES as $file) {
                    $targetEnvFile = "{$this->projectRootDir}/${file}";
                    if (file_exists($targetEnvFile)) {
                        if (!file_put_contents($targetEnvFile, $content, FILE_APPEND | LOCK_EX)) {
                            $result->addErrorMessage("<error>Could not copy env variables from {$this->packageName}</error>");
                        }
                    }
                }
            }
        }

        if (!$result->isFailure()) {
            $result->addStatusMessage("Successfully copied env variables from {$this->packageName}");
        }

        return $result;
    }
435324
public function update(\Composer\Repository\InstalledRepositoryInterface $repo, \Composer\Package\PackageInterface $initial, 
			\Composer\Package\PackageInterface $target) {
		if (!$this->needsUpdate($initial)) {
			//add the new version of the module to the composer.lock
			$repo->removePackage($initial);
			if (!$repo->hasPackage($target)) {
				$repo->addPackage(clone $target);
			}
			return;
		}
				
    	$this->moveBackResources($initial);
				
		parent::update($repo, $initial, $target);
		
		$this->removeResources($target);
		$this->installResources($target);
	}
1030949
@Override
  protected void updateEntity(DbEntityOperation operation) {

    final DbEntity dbEntity = operation.getEntity();

    String updateStatement = dbSqlSessionFactory.getUpdateStatement(dbEntity);
    ensureNotNull("no update statement for " + dbEntity.getClass() + " in the ibatis mapping files", "updateStatement", updateStatement);

    LOG.executeDatabaseOperation("UPDATE", dbEntity);

    if (Context.getProcessEngineConfiguration().isJdbcBatchProcessing()) {
      // execute update
      executeUpdate(updateStatement, dbEntity);
    } else {
      // execute update
      int numOfRowsUpdated = executeUpdate(updateStatement, dbEntity);

      if (dbEntity instanceof HasDbRevision) {
        if (numOfRowsUpdated != 1) {
          // failed with optimistic locking
          operation.setFailed(true);
          return;
        } else {
          // increment revision of our copy
          HasDbRevision versionedObject = (HasDbRevision) dbEntity;
          versionedObject.setRevision(versionedObject.getRevisionNext());
        }
      }
    }

    // perform post update action
    entityUpdated(dbEntity);
  }
1021696
public static function add($operation = null, array $data = [])
    {
        \Mmi\App\FrontController::getInstance()->getLogger()->info('Legacy log: ' . $operation);
        \Mmi\App\FrontController::getInstance()->getLogger()->warning('\Cms\Log\Model deprecated, use MMi PSR logger instead');
    }
1013283
public function join(string $operation, $table, $on = null): Statement
    {
        if (count($this->joins) > count($this->ons)) {
            trigger_error('关联时,关联关系不足', E_USER_ERROR);
        }
        $this->joinOperations[] = $operation;
        $this->joins[] = $table;
        if ($on) {
            $this->on($on);
        }
        return $this;
    }
1116675
public function buildOperationList()
    {
        $this->log('Building install/update operations list...');
        $current = $this->versionManager->openRepository($this->installedRepoFile);

        foreach ($current->getCanonicalPackages() as $currentPackage) {
            $extra = $currentPackage->getExtra();
            //this is a meta package if the bundles key exists
            if (array_key_exists('bundles', $extra)) {
                //this is only valid for installable bundles
                $bundles = array_filter($extra['bundles'], function ($var) {
                    try {
                        return in_array('Claroline\InstallationBundle\Bundle\InstallableInterface', class_implements($var)) ? true : false;
                    } catch (\Exception $e) {
                        $this->log($var.' not found.', LogLevel::ERROR);

                        return false;
                    }
                });

                foreach ($bundles as $bundle) {
                    //if the corebundle is already installed, we can do database checks to be sure a plugin is already installed
                    //and not simply set to false in bundles.ini in previous versions.
                    $foundBundle = $this->isBundleAlreadyInstalled($bundle);

                    $previousPackage = $this->findPreviousPackage($bundle);

                    if ($foundBundle && $previousPackage) {
                        $isDistribution = 'claroline/distribution' === $currentPackage->getName();
                        $fromVersionEntity = $this->versionManager->getLatestUpgraded($bundle);
                        $toVersion = $this->versionManager->getCurrent();

                        if ($isDistribution && $fromVersionEntity && $toVersion) {
                            if ($fromVersionEntity->getVersion() === $toVersion && $fromVersionEntity->isUpgraded()) {
                                $this->log('Package '.$bundle.'already upgraded to the '.$toVersion.'version. Skipping...');
                            } else {
                                $operations[$bundle] = new Operation(Operation::UPDATE, $currentPackage, $bundle);
                                $operations[$bundle]->setFromVersion($fromVersionEntity->getVersion());
                                $operations[$bundle]->setToVersion($toVersion);
                            }
                            //old update <= v10
                        } else {
                            $operations[$bundle] = new Operation(Operation::UPDATE, $currentPackage, $bundle);
                            $operations[$bundle]->setFromVersion($previousPackage->getVersion());
                            $operations[$bundle]->setToVersion($currentPackage->getVersion());
                        }
                    } else {
                        //if we found something in the database, it means it was removed from composer.json and not properly uninstalled
                        if ($foundBundle) {
                            $operations[$bundle] = new Operation(Operation::UPDATE, $currentPackage, $bundle);
                            //we don't know wich version it came from so we trigger everything, we only know it's already here
                            $operations[$bundle]->setFromVersion('0.0.0');
                            $operations[$bundle]->setToVersion($currentPackage->getVersion());
                        } else {
                            $operations[$bundle] = new Operation(Operation::INSTALL, $currentPackage, $bundle);
                        }
                    }
                }
            } else {
                $previous = $this->versionManager->openRepository($this->previousRepoFile, true);
                $previousPackage = $previous->findPackage($currentPackage->getName(), '*');
                //old <= v6 package detection
                if (!$previousPackage) {
                    $this->log("Installation of {$currentPackage->getName()} required");
                    $operation = $this->buildOperation(Operation::INSTALL, $currentPackage);
                    $operation->setToVersion($currentPackage->getVersion());
                    $operations[$operation->getBundleFqcn()] = $operation;
                } else {
                    $this->log(sprintf(
                        'Update of %s from %s to %s required',
                        $previousPackage->getName(),
                        $previousPackage->getVersion(),
                        $currentPackage->getVersion()
                    ));
                    $operation = $this->buildOperation(Operation::UPDATE, $currentPackage);
                    $operation->setFromVersion($previousPackage->getVersion());
                    $operation->setToVersion($currentPackage->getVersion());
                    $operations[$operation->getBundleFqcn()] = $operation;
                }
            }
        }

        // TODO: we *should* do something in case a platform package is
        // removed (e.g. if the package is a plugin, at least unregister it)
        // but AFAIK we don't have anything now to support removal of a bundle
        // whose sources are already gone. Maybe the platform installer could
        // look after each update if there are records in the plugin table
        // that don't match any known bundle?

        $this->log('Sorting operations...');
        $bundles = $this->kernel->getBundles();
        $sortedOperations = [];

        foreach ($bundles as $bundle) {
            $bundleClass = $bundle->getNamespace() ?
                $bundle->getNamespace().'\\'.$bundle->getName() :
                $bundle->getName();

            if (isset($operations[$bundleClass])) {
                $sortedOperations[] = $operations[$bundleClass];
            }
        }

        return $sortedOperations;
    }
607035
private function applyPatch($entity, array $operation)
    {
        if (false === $this->rightManager->authorized($entity, $operation['path'], $operation['op'])) {
            throw new UnauthorizedPatchOperationException($entity, $operation['path'], $operation['op']);
        }

        if (PatcherInterface::REPLACE_OPERATION === $operation['op']) {
            $method = $this->buildMethodName($operation['path'], 'set');
            $entity->$method($operation['value']);
        }
    }
311646
protected <V> V executeUpdate (Operation<V> op)
        throws PersistenceException
    {
        return execute(op, true, false);
    }
961612
public function transfer(OperationInterface $operation)
    {
        try {
            $vendor = $this->getVendor($operation);

            if (!$vendor || $this->hipay->isAvailable($vendor->getEmail())) {
                throw new WalletNotFoundException($vendor);
            }

            if (!$this->checkOperationVendorEnabled($vendor, $operation)) {
                throw new VendorDisabledException($vendor->getMiraklId(), 'transfer');
            }
            if ($operation->getAmount() <= 0) {
                throw new InvalidAmountException($operation);
            }

            $this->hasSufficientFunds($operation->getAmount(), $this->technicalAccount, true);

            $operation->setHiPayId($vendor->getHiPayId());

            $transfer = new TransferModel(
                round($operation->getAmount(), self::SCALE),
                $vendor,
                $this->operationManager->generatePrivateLabel($operation),
                $this->operationManager->generatePublicLabel($operation)
            );

            //Transfer
            $transferId = $this->hipay->transfer($transfer, $vendor);

            $operation->setStatus(new Status(Status::TRANSFER_SUCCESS));
            $operation->setTransferId($transferId);
            $operation->setUpdatedAt(new DateTime());
            $this->operationManager->save($operation);

            $this->logOperation(
                $operation->getMiraklId(),
                $operation->getPaymentVoucher(),
                Status::TRANSFER_SUCCESS,
                ""
            );

            return $transferId;
        } catch (VendorDisabledException $e) {
            $operation->setStatus(new Status(Status::TRANSFER_VENDOR_DISABLED));
            $operation->setUpdatedAt(new DateTime());
            $this->operationManager->save($operation);

            $this->logOperation(
                $operation->getMiraklId(),
                $operation->getPaymentVoucher(),
                Status::TRANSFER_VENDOR_DISABLED,
                $e->getMessage()
            );

            throw $e;
        } catch (WrongWalletBalance $e) {
            $operation->setStatus(new Status(Status::TRANSFER_NEGATIVE));
            $operation->setUpdatedAt(new DateTime());
            $this->operationManager->save($operation);

            $this->logOperation(
                $operation->getMiraklId(),
                $operation->getPaymentVoucher(),
                Status::TRANSFER_NEGATIVE,
                $e->getMessage()
            );

            throw $e;
        } catch (InvalidAmountException $e) {
            $operation->setStatus(new Status(Status::INVALID_AMOUNT));
            $operation->setUpdatedAt(new DateTime());
            $this->operationManager->save($operation);

            $this->logOperation(
                $operation->getMiraklId(),
                $operation->getPaymentVoucher(),
                Status::INVALID_AMOUNT,
                $e->getMessage()
            );

            throw $e;
        } catch (Exception $e) {
            $operation->setStatus(new Status(Status::TRANSFER_FAILED));
            $operation->setUpdatedAt(new DateTime());
            $this->operationManager->save($operation);

            $this->logOperation(
                $operation->getMiraklId(),
                $operation->getPaymentVoucher(),
                Status::TRANSFER_FAILED,
                $e->getMessage()
            );

            throw $e;
        }
    }
631421
public function addHandler($operation, callable $callback)
    {
        $this->handlers[$operation] = $callback;
        $this->addOperation($operation);
    }
342740
protected function install(AbstractInstall $installScript, OutputInterface $output)
    {
        $dataPath = DATADIR;

        $output->writeln('  Installing App...');

        // Install the database structure
        $this->runSql(
            $dataPath.DIRECTORY_SEPARATOR.GenerateInstallCommand::STRUCTURE_FILE,
            '  Creating initial database schema',
            sprintf('  Database schema file %s not found', GenerateInstallCommand::STRUCTURE_FILE),
            $output
        );

        // Install the database data
        $this->runSql(
            $dataPath.DIRECTORY_SEPARATOR.GenerateInstallCommand::DATA_FILE,
            '  Inserting initial data',
            sprintf('  Database data file %s not found', GenerateInstallCommand::DATA_FILE),
            $output
        );

        $output->writeln('  Running install script');

        $installScript->execute($this->db);

        $output->write(['  Install completed!', ''], true);
    }