Files
pathfinder/app/Db/Sql/Mysql/TableModifier.php
Sam 98bd07e904 Merge Development Branch v2.1.2 (#21)
* Fixes environment default

* Bump clue/ndjson-react from 1.1.0 to 1.2.0

Bumps [clue/ndjson-react](https://github.com/clue/reactphp-ndjson) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/clue/reactphp-ndjson/releases)
- [Changelog](https://github.com/clue/reactphp-ndjson/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clue/reactphp-ndjson/compare/v1.1.0...v1.2.0)

---
updated-dependencies:
- dependency-name: clue/ndjson-react
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump cache/array-adapter from 1.0.1 to 1.1.0

Bumps [cache/array-adapter](https://github.com/php-cache/array-adapter) from 1.0.1 to 1.1.0.
- [Release notes](https://github.com/php-cache/array-adapter/releases)
- [Changelog](https://github.com/php-cache/array-adapter/blob/master/Changelog.md)
- [Commits](https://github.com/php-cache/array-adapter/compare/1.0.1...1.1.0)

---
updated-dependencies:
- dependency-name: cache/array-adapter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump monolog/monolog from 2.3.2 to 2.3.4

Bumps [monolog/monolog](https://github.com/Seldaek/monolog) from 2.3.2 to 2.3.4.
- [Release notes](https://github.com/Seldaek/monolog/releases)
- [Changelog](https://github.com/Seldaek/monolog/blob/main/CHANGELOG.md)
- [Commits](https://github.com/Seldaek/monolog/compare/2.3.2...2.3.4)

---
updated-dependencies:
- dependency-name: monolog/monolog
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump cache/namespaced-cache from 1.0.0 to 1.1.0

Bumps [cache/namespaced-cache](https://github.com/php-cache/namespaced-cache) from 1.0.0 to 1.1.0.
- [Release notes](https://github.com/php-cache/namespaced-cache/releases)
- [Changelog](https://github.com/php-cache/namespaced-cache/blob/master/Changelog.md)
- [Commits](https://github.com/php-cache/namespaced-cache/compare/1.0.0...1.1.0)

---
updated-dependencies:
- dependency-name: cache/namespaced-cache
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump gulp-sass from 4.1.1 to 5.0.0

Bumps [gulp-sass](https://github.com/dlmanning/gulp-sass) from 4.1.1 to 5.0.0.
- [Release notes](https://github.com/dlmanning/gulp-sass/releases)
- [Changelog](https://github.com/dlmanning/gulp-sass/blob/master/CHANGELOG.md)
- [Commits](https://github.com/dlmanning/gulp-sass/compare/v4.1.1...v5.0.0)

---
updated-dependencies:
- dependency-name: gulp-sass
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump node-sass from 4.14.1 to 6.0.1

Bumps [node-sass](https://github.com/sass/node-sass) from 4.14.1 to 6.0.1.
- [Release notes](https://github.com/sass/node-sass/releases)
- [Changelog](https://github.com/sass/node-sass/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sass/node-sass/compare/v4.14.1...v6.0.1)

---
updated-dependencies:
- dependency-name: node-sass
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump gulp-brotli from 2.0.2 to 3.0.0

Bumps [gulp-brotli](https://github.com/seznam/gulp-brotli) from 2.0.2 to 3.0.0.
- [Release notes](https://github.com/seznam/gulp-brotli/releases)
- [Commits](https://github.com/seznam/gulp-brotli/compare/v2.0.2...v3.0.0)

---
updated-dependencies:
- dependency-name: gulp-brotli
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump imagemin-webp from 5.1.0 to 6.0.0

Bumps [imagemin-webp](https://github.com/imagemin/imagemin-webp) from 5.1.0 to 6.0.0.
- [Release notes](https://github.com/imagemin/imagemin-webp/releases)
- [Commits](https://github.com/imagemin/imagemin-webp/compare/v5.1.0...v6.0.0)

---
updated-dependencies:
- dependency-name: imagemin-webp
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: make pathfinder composer 2.x compliant

extract mixed class into dedicated file and address filename typo in order to make the project PSR-4 compliant and work with Composer 2

* Bump league/html-to-markdown from 4.9.1 to 5.0.1

Bumps [league/html-to-markdown](https://github.com/thephpleague/html-to-markdown) from 4.9.1 to 5.0.1.
- [Release notes](https://github.com/thephpleague/html-to-markdown/releases)
- [Changelog](https://github.com/thephpleague/html-to-markdown/blob/master/CHANGELOG.md)
- [Commits](https://github.com/thephpleague/html-to-markdown/compare/4.9.1...5.0.1)

---
updated-dependencies:
- dependency-name: league/html-to-markdown
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* composer.json: bumps monolog to 2.3.4

* composer.lock: Updates after dependabot merges

* Adds package-lock.json

* .gitignore: removes package-lock.json from ignore

* Removes "slash" js dev dependency

* pathfinder.ini: bumps version

* Bumps version on public files

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Loïc LEUILLIOT <loic.leuilliot@gmail.com>
2021-09-18 18:39:37 +12:00

110 lines
3.6 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Exodus
* Date: 19.12.2015
* Time: 12:47
*
* This is an "on top" extension for "Schema Builder"
* see: https://github.com/ikkez/f3-schema-builder
*
* Features:
* - FOREIGN KEY CONSTRAINTS (single column key)
*/
namespace Exodus4D\Pathfinder\Db\Sql\Mysql;
use DB\SQL;
class TableModifier extends SQL\TableModifier {
const TEXT_ConstraintNotValid = 'Constraint `%s` is not valid';
/**
* return table foreign key constraints as assoc array
* -> if §constraint is passed, constraints are limited to that column
* @param null| Constraint $constraint
* @return Constraint[]
*/
public function listConstraint($constraint = null){
$constraintName = '%';
$keys = [];
if($constraint instanceof Constraint){
// list constraints for given column in this table
$constraintName = $constraint->getConstraintName() . '%';
$keys = $constraint->getKeys();
}
$this->db->exec("USE information_schema");
$constraintsData = $this->db->exec("
SELECT
*
FROM
referential_constraints
WHERE
constraint_schema = :db AND
table_name = :table AND
constraint_name LIKE :constraint_name
", [
':db' => $this->db->name(),
':table' => $this->name,
':constraint_name' => $constraintName
]);
// switch back to current DB
$this->db->exec("USE " . $this->db->quotekey($this->db->name()));
$constraints = [];
foreach($constraintsData as $data){
$constraints[$data['CONSTRAINT_NAME']] = new Constraint($this, $keys, $data['REFERENCED_TABLE_NAME'] );
}
return $constraints;
}
/**
* checks whether a constraint name exists or not
* -> does not check constraint params
* @param Constraint $constraint
* @return bool
*/
public function constraintExists($constraint){
$constraints = $this->listConstraint();
return array_key_exists($constraint->getConstraintName(), $constraints);
}
/**
* drop foreign key constraint
* @param Constraint $constraint
*/
public function dropConstraint($constraint){
if($constraint->isValid()){
$this->queries[] = "ALTER TABLE " . $this->db->quotekey($this->name) . "
DROP FOREIGN KEY " . $this->db->quotekey($constraint->getConstraintName()) . ";";
}else{
trigger_error(sprintf(self::TEXT_ConstraintNotValid, 'table: ' . $this->name . ' constraintName: ' . $constraint->getConstraintName()));
}
}
/**
* Add/Update foreign key constraint
* @param Constraint $constraint
*/
public function addConstraint($constraint){
if($constraint->isValid()){
$this->queries[] = "
ALTER TABLE " . $this->db->quotekey($this->name) . "
ADD CONSTRAINT " . $this->db->quotekey($constraint->getConstraintName()) . "
FOREIGN KEY (" . implode(', ', $constraint->getKeys()) . ")
REFERENCES " . $this->db->quotekey($constraint->getReferencedTable()) . " (" . implode(', ', $constraint->getReferencedCols()) . ")
ON DELETE " . $constraint->getOnDelete() . "
ON UPDATE " . $constraint->getOnUpdate() . ";";
}else{
trigger_error(sprintf(self::TEXT_ConstraintNotValid, 'table: ' . $this->name . ' constraintName: ' . $constraint->getConstraintName()));
}
}
}