From 5af14fdb0a936a043aaa91084d9b3ad49b495127 Mon Sep 17 00:00:00 2001 From: Wesley Stessens Date: Sun, 17 Mar 2024 14:52:28 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=99=88=20Add=20composer.lock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- composer.lock | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 5e5b895..b5b127d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ /vendor/ -composer.lock .idea *.tar.gz *.zip *.code-workspace # Ignore *.sql except on the src/create_catalog_sql directory *.sql -!src/create_catalog_sql/*.sql \ No newline at end of file +!src/create_catalog_sql/*.sql diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..ef0179a --- /dev/null +++ b/composer.lock @@ -0,0 +1,105 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "f2bcc0c8df7874cef2496a4ed39d348f", + "packages": [], + "packages-dev": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.9.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-02-16T15:06:51+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=8.0", + "ext-pdo": "*" + }, + "platform-dev": [], + "platform-overrides": { + "php": "8.0" + }, + "plugin-api-version": "2.2.0" +} From 9f4a7f8eeff40203eb8eb00ba6f5d806169fe978 Mon Sep 17 00:00:00 2001 From: Wesley Stessens Date: Sun, 17 Mar 2024 14:55:17 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=B7=20Add=20CI=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/github-actions.yml | 0 .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) delete mode 100644 .github/workflows/github-actions.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fb46884 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: test + +on: [push] + +concurrency: production_environment + +jobs: + test: + runs-on: ubuntu-latest + + name: Check code style and run tests + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Install PHP dependencies (composer) + run: composer install + + - name: Check code style + run: composer phpcs From 32d94035dbc2798c7131256fc7758ab453a0df05 Mon Sep 17 00:00:00 2001 From: Jan-Willem Oostendorp Date: Sun, 17 Mar 2024 14:58:58 +0100 Subject: [PATCH 3/3] Fixed code styles --- README.md | 11 +++++++++-- composer.lock | 2 +- src/Catalog.php | 41 +++++++++++++++++++++++++---------------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 9129868..a095fa8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,17 @@ # catalogs-php A PHP framework to talk to Catalogs. Part of the [CloudFest 2024 Hackathon](https://hackathon.cloudfest.com/project/integrating-mariadb-catalogs-with-php-platforms/). -# Useage +# Installation Include the catalog-php with composer: - composer require mariadb/catalogs-php + ```bash + composer require mariadb/catalogs-php:dev-main + ``` +Include autoloader in your project. + + ```php + connection->query("SELECT * FROM mysql.global_priv WHERE User='{$this->dbUser}' AND Host='%';"); + $rootPrivileges = $this->connection->query("SELECT * FROM mysql.global_priv WHERE User='{$this->dbUser}' AND Host='%';"); $scripts = [ 'src/create_catalog_sql/mysql_system_tables.sql', @@ -96,8 +97,8 @@ public function create(string $catName): int 'src/create_catalog_sql/maria_add_gis_sp.sql', 'src/create_catalog_sql/mysql_sys_schema.sql', ]; - $this->connection->exec('CREATE CATALOG IF NOT EXISTS ' .$catName); - $this->connection->exec('USE CATALOG ' . $catName); + $this->connection->exec('CREATE CATALOG IF NOT EXISTS '.$catName); + $this->connection->exec('USE CATALOG '.$catName); $this->connection->exec('CREATE DATABASE IF NOT EXISTS mysql'); $this->connection->exec('USE mysql'); @@ -120,13 +121,17 @@ public function create(string $catName): int $this->connection->exec($content); } - if ($root_privileges->rowCount() > 0) { - foreach ($root_privileges as $privilege) { - $this->connection->exec("INSERT INTO mysql.global_priv VALUES ('{$privilege['Host']}', '{$privilege['User']}', '{$privilege['Priv']}');"); + if ($rootPrivileges->rowCount() > 0) { + foreach ($rootPrivileges as $privilege) { + $host = $privilege['Host']; + $user = $privilege['User']; + $priv = $privilege['Priv']; + $this->connection->exec("INSERT INTO mysql.global_priv VALUES ('{$host}', '{$user}', '{$priv}');"); } } return $this->getPort($catName); + } @@ -181,10 +186,10 @@ public function drop(string $catName): bool ); try { - // enter the catalog - $this->connection->exec('USE CATALOG ' . $catName); + // Enter the catalog. + $this->connection->exec('USE CATALOG '.$catName); - // check if there are any tables besides mysql, sys, performance_schema and information_schema + // Check if there are any tables besides mysql, sys, performance_schema and information_schema. $tables = $this->connection->query('SHOW DATABASES'); foreach ($tables as $table) { if (!in_array($table['Database'], ['mysql', 'sys', 'performance_schema', 'information_schema'])) { @@ -192,15 +197,15 @@ public function drop(string $catName): bool } } - // drop mysql, sys and performance_schema + // Drop mysql, sys and performance_schema. $this->connection->exec('DROP DATABASE IF EXISTS mysql'); $this->connection->exec('DROP DATABASE IF EXISTS sys'); $this->connection->exec('DROP DATABASE IF EXISTS performance_schema'); - // drop the catalog - $this->connection->exec('DROP CATALOG ' . $catName); + // Drop the catalog. + $this->connection->exec('DROP CATALOG '.$catName); } catch (\PDOException $e) { - throw new \Exception('Error dropping catalog: ' . $e->getMessage()); + throw new \Exception('Error dropping catalog: '.$e->getMessage()); } return true; @@ -221,10 +226,11 @@ private function alter() } + /** * @return void */ - public function createAdminUserForCatalog(string $catalog, string $userName, string $password, string $authHost = 'localhost'): void + public function createAdminUserForCatalog(string $catalog, string $userName, string $password, string $authHost='localhost'): void { $this->connection->exec("USE CATALOG {$catalog}"); $this->connection->exec("USE mysql"); @@ -232,6 +238,9 @@ public function createAdminUserForCatalog(string $catalog, string $userName, str $this->connection = new \PDO("mysql:host={$this->dbHost};port={$this->dbPort};dbname={$catalog}.mysql", $this->dbUser, $this->dbPass, $this->dbOptions); $this->connection->prepare("CREATE USER ?@? IDENTIFIED BY ?;")->execute([$userName, $authHost, $password]); - $this->connection->prepare("GRANT ALL PRIVILEGES ON `%`.* TO ?@? IDENTIFIED BY ? WITH GRANT OPTION;")->execute([$userName, $authHost,$password]); + $this->connection->prepare("GRANT ALL PRIVILEGES ON `%`.* TO ?@? IDENTIFIED BY ? WITH GRANT OPTION;")->execute([$userName, $authHost, $password]); + } + + }