Handles the update step of object state migrations.

@throws \Exception
766207
protected function update($step)
    {
        $stateCollection = $this->matchObjectStates('update', $step);

        if (count($stateCollection) > 1 && array_key_exists('references', $step->dsl)) {
            throw new \Exception("Can not execute Object State update because multiple states match, and a references section is specified in the dsl. References can be set when only 1 state matches");
        }

        if (count($stateCollection) > 1 && isset($step->dsl['identifier'])) {
            throw new \Exception("Can not execute Object State update because multiple states match, and an identifier is specified in the dsl.");
        }

        $objectStateService = $this->repository->getObjectStateService();

        foreach ($stateCollection as $state) {
            $objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct();

            if (isset($step->dsl['identifier'])) {
                $objectStateUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']);
            }
            if (isset($step->dsl['names'])) {
                foreach ($step->dsl['names'] as $name) {
                    $objectStateUpdateStruct->names[$name['languageCode']] = $name['name'];
                }
            }
            if (isset($step->dsl['descriptions'])) {
                foreach ($step->dsl['descriptions'] as $languageCode => $description) {
                    $objectStateUpdateStruct->descriptions[$languageCode] = $description;
                }
            }
            $state = $objectStateService->updateObjectState($state, $objectStateUpdateStruct);

            $this->setReferences($state, $step);
        }

        return $stateCollection;
    }
654808
public function update()
    {
        $data = $this->client->get('http://dev.maxmind.com/static/csv/codes/country_continent.csv');

        // Verify server response
        if ($this->client->getErrors() !== null) {
            throw new Exception($this->client->getErrors());
        }

        $lines = explode("\n", $data[0]);

        array_shift($lines);

        $output = [];

        foreach ($lines as $line) {
            $arr = str_getcsv($line);

            if (count($arr) < 2) {
                continue;
            }

            $output[$arr[0]] = $arr[1];
        }

        // Get path
        $path = $this->config('continent_path');

        file_put_contents($path, json_encode($output));

        return "Continent file ({$path}) updated.";
    }
950953
public function actionUpdateAll(): int
    {
        $tables = $this->removeExcludedTables($this->db->schema->getTableNames());

        if (!$tables) {
            $this->stdout(' > Your database does not contain any tables yet.', Console::FG_YELLOW);

            return ExitCode::OK;
        }

        if ($this->confirm(' > Are you sure you want to potentially generate ' . count($tables) . ' migrations?')) {
            return $this->actionUpdate(implode(',', $tables));
        }

        $this->stdout(" Operation cancelled by user.\n\n", Console::FG_YELLOW);

        return ExitCode::OK;
    }
1365131
public function up()
    {
        $table = $this->table('users');
        $table->addColumn('activated_at', 'datetime', ['null' => true, 'default' => null, 'after' => 'active']);
        $table->update();

        $this->clearModelCache();
    }
346784
public function upgrade(): void
    {
        // This table was previously created by the favorites module in 1.7.9.
        // These migrations are now part of the core code.

        if (!DB::schema()->hasTable('news')) {
            DB::schema()->create('news', static function (Blueprint $table): void {
                $table->integer('news_id', true);
                $table->integer('user_id')->nullable();
                $table->integer('gedcom_id')->nullable();
                $table->string('subject', 255);
                $table->text('body');
                $table->timestamp('updated')->useCurrent();
                
                $table->index(['user_id', 'updated']);
                $table->index(['gedcom_id', 'updated']);

                $table->foreign('user_id')->references('user_id')->on('user')->onDelete('cascade');
                $table->foreign('gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade');
            });
        }
    }
485802
void migrate() throws RepositoryException
   {
      try
      {
         LOG.info("Migration started.");

         moveOldStructure();
         service.createStructure();

         //Migration order is important due to removal of nodes.
         migrateGroups();
         migrateMembershipTypes();
         migrateUsers();
         migrateProfiles();
         migrateMemberships();

         removeOldStructure();

         LOG.info("Migration completed.");
      }
      catch (Exception e)//NOSONAR
      {
         throw new RepositoryException("Migration failed", e);
      }
   }
946392
protected function update($step)
    {
        $locationService = $this->repository->getLocationService();

        $locationCollection = $this->matchLocations('update', $step);

        if (count($locationCollection) > 1 && isset($step->dsl['references'])) {
            throw new \Exception("Can not execute Location update because multiple locations match, and a references section is specified in the dsl. References can be set when only 1 location matches");
        }

        if (count($locationCollection) > 1 && isset($step->dsl['swap_with_location'])) {
            throw new \Exception("Can not execute Location update because multiple locations match, and a swap_with_location is specified in the dsl.");
        }

        // support legacy tag: parent_location_id
        if (isset($step->dsl['swap_with_location']) && (isset($step->dsl['parent_location']) || isset($step->dsl['parent_location_id']))) {
            throw new \Exception('Cannot move location to a new parent and swap location with another location at the same time.');
        }

        foreach ($locationCollection as $key => $location) {

            if (isset($step->dsl['priority'])
                || isset($step->dsl['sort_field'])
                || isset($step->dsl['sort_order'])
                || isset($step->dsl['remote_id'])
            ) {
                $locationUpdateStruct = $locationService->newLocationUpdateStruct();

                if (isset($step->dsl['priority'])) {
                    $locationUpdateStruct->priority = $this->referenceResolver->resolveReference($step->dsl['priority']);
                }

                if (isset($step->dsl['sort_field'])) {
                    $locationUpdateStruct->sortField = $this->getSortField($this->referenceResolver->resolveReference($step->dsl['sort_field']), $location->sortField);
                }

                if (isset($step->dsl['sort_order'])) {
                    $locationUpdateStruct->sortOrder = $this->getSortOrder($this->referenceResolver->resolveReference($step->dsl['sort_order']), $location->sortOrder);
                }

                if (isset($step->dsl['remote_id'])) {
                    $locationUpdateStruct->remoteId = $this->referenceResolver->resolveReference($step->dsl['remote_id']);
                }

                $location = $locationService->updateLocation($location, $locationUpdateStruct);
            }

            // Check if visibility needs to be updated
            if (isset($step->dsl['is_hidden'])) {
                if ($step->dsl['is_hidden']) {
                    $location = $locationService->hideLocation($location);
                } else {
                    $location = $locationService->unhideLocation($location);
                }
            }

            // Move or swap location
            if (isset($step->dsl['parent_location']) || isset($step->dsl['parent_location_id'])) {
                // Move the location and all its children to a new parent
                $parentLocationId = isset($step->dsl['parent_location']) ? $step->dsl['parent_location'] : $step->dsl['parent_location_id'];
                $parentLocationId = $this->referenceResolver->resolveReference($parentLocationId);

                $newParentLocation = $locationService->loadLocation($parentLocationId);

                $locationService->moveSubtree($location, $newParentLocation);

                // we have to reload the location to be able to set references to the modified data
                $location = $locationService->loadLocation($location->id);
            } elseif (isset($step->dsl['swap_with_location'])) {
                // Swap locations
                $swapLocationId = $step->dsl['swap_with_location'];
                $swapLocationId = $this->referenceResolver->resolveReference($swapLocationId);

                $locationToSwap = $this->matchLocationByKey($swapLocationId);

                $locationService->swapLocation($location, $locationToSwap);

                // we have to reload the location to be able to set references to the modified data
                $location = $locationService->loadLocation($location->id);
            }

            // make the location the main one
            if (isset($step->dsl['is_main'])) {
                $this->setMainLocation($location);

                //have to reload the location so that correct data can be set as reference
                $location = $locationService->loadLocation($location->id);
            }

            $locationCollection[$key] = $location;
        }

        $this->setReferences($locationCollection, $step);

        return $locationCollection;
    }
1296622
public function create() {
        $migration = $this->getMessages();
        if (!$migration) {
            $this->db()->insert($this->table, array('migration' => get_class($this), 'state' => false));
        } else {
            throw new \Exception('Migration ' .  get_class($this) . ' already created');
        }
    }
1082532
public function commit()
    {
        if (!$this->getIsActive()) {
            throw new Exception('Failed to commit transaction: transaction was inactive.');
        }

        $this->_level--;
        if ($this->_level === 0) {
            Log::debug('Commit transaction' . __METHOD__);
            $this->db->pdo->commit();
            $this->db->trigger(Connection::EVENT_COMMIT_TRANSACTION);
            return;
        }

        $schema = $this->db->getSchema();
        if ($schema->supportsSavepoint()) {
            Log::debug('Release savepoint ' . $this->_level . __METHOD__);
            $schema->releaseSavepoint('LEVEL' . $this->_level);
        } else {
            Log::info('Transaction not committed: nested transaction not supported' . __METHOD__);
        }
    }
454617
public function migrateUp()
    {
        $this->builder->table('tracker_sessions', function ($table) {
            $table->foreign('language_id')
                    ->references('id')
                    ->on('tracker_languages')
                    ->onUpdate('cascade')
                    ->onDelete('cascade');
        });
    }
1178062
public function execute()
	{
		$query  = $this->factory->builder($this->update)->process();
		$result = $this->pdo->query($query);
		if(!$result)
		{
			throw new \Exception('An error while updating is occurred');
		}
	}
577748
public function commit()
    {
        if ($this->rollbackAgain) {
            throw new \wf\db\Exception('Please throw exception after rollback in last catch block');
        }

        --$this->transactions;
    
        if($this->transactions == 0 && false === $this->dbh->commit()) {
            throw new \wf\db\Exception('transaction commit error: ' . $this->getLastErr());
        }

        if ($this->transactions < 0) {
            $this->transactions = 0;
        }
    }
836664
private function migrate()
    {
        $action = $this->arg->getParameter('action');

        if (!is_null($action)) {
            $this->throwFailsCommand('This action is not allow!', 'help migration');
        }

        $this->command->call(
            'migrate',
            'migration',
            null
        );
    }
356664
public function upgrade(): void
    {
        // This table was previously created by the googlemap module in 1.7.9.
        // These migrations are now part of the core code.

        if (!DB::schema()->hasTable('placelocation')) {
            DB::schema()->create('placelocation', static function (Blueprint $table): void {
                $table->integer('pl_id')->primary();
                $table->integer('pl_parent_id');
                $table->integer('pl_level');
                $table->string('pl_place', 255);
                $table->string('pl_long', 30)->nullable();
                $table->string('pl_lati', 30)->nullable();
                $table->integer('pl_zoom')->nullable();
                $table->string('pl_icon', 255)->nullable();

                $table->index('pl_place');
                $table->unique(['pl_parent_id', 'pl_place']);
            });
        }

        if (DB::schema()->hasColumn('placelocation', 'pl_media')) {
            DB::schema()->table('placelocation', static function (Blueprint $table): void {
                $table->dropColumn('pl_media');
                $table->dropColumn('sv_long');
                $table->dropColumn('sv_lati');
                $table->dropColumn('sv_bearing');
                $table->dropColumn('sv_elevation');
                $table->dropColumn('sv_zoom');
            });
        }
    }
1187239
public function runMigrations()
	{
		$migrations = Model::where('status', 'pending');

		if ($migrations->get()->size() > 0) {
			foreach($migrations->get()->all() as $migration) {
				$this->runSingleMigration($migration);
			}
		}
	}
1106985
public function up() {
		$user = Config::get('auth.table');

		// Action
		Schema::create(self::TABLE_ACTION, function(Blueprint $table) {
			$table->increments('id');
			$table->string('name')->unique();
		});

		DB::transaction(function() {
			$actions = array('insert', 'update', 'delete');
			foreach ($actions as $action) :
				$obj = new Model\Action;
				$obj->name = $action;
				$obj->save();
			endforeach;
		});
		// -- Action
		// Log
		Schema::create(self::TABLE, function(Blueprint $table) use($user) {
			$table->increments('id');
			$table->integer('user_id')->unsigned()->nullable();
			$table->integer('action_id')->unsigned();
			$table->string('model');
			$table->string('model_id');
			$table->timestamp('timestamp')->default(DB::raw('CURRENT_TIMESTAMP'));

			$table->foreign('user_id')
				->references('id')->on($user)
				->onUpdate('cascade')->onDelete('cascade');

			$table->foreign('action_id')
				->references('id')->on(self::TABLE_ACTION)
				->onUpdate('cascade')->onDelete('cascade');
		});
		// -- Log
		// Data
		Schema::create(self::TABLE_DATA, function(Blueprint $table) {
			$table->increments('id');
			$table->integer('model_log_id')->unsigned();
			$table->string('key');
			$table->string('old');
			$table->string('new');
			$table->unique(array('model_log_id', 'key'));

			$table->foreign('model_log_id')
				->references('id')->on(self::TABLE)
				->onUpdate('cascade')->onDelete('cascade');
		});
		// -- Data
	}
1232171
public function update()
    {
        $firstUp = !Schema::hasTable($this->getMigrationTableName());
        if ($firstUp) {
            $this->repository->createRepository();
            $this->note('Migration table created');
        }

        /*
         * Update modules
         */
        $modules = Config::get('cms.loadModules', []);
        foreach ($modules as $module) {
            $this->migrateModule($module);
        }

        /*
         * Update plugins
         */
        $plugins = $this->pluginManager->sortByDependencies();
        foreach ($plugins as $plugin) {
            $this->updatePlugin($plugin);
        }

        Parameter::set('system::update.count', 0);
        CacheHelper::clear();

        /*
         * Seed modules
         */
        if ($firstUp) {
            $modules = Config::get('cms.loadModules', []);
            foreach ($modules as $module) {
                $this->seedModule($module);
            }
        }

        return $this;
    }