Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGS-6563: Add primary key if necessary #265

Merged
merged 93 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
0a0b5a5
BUGS-6563: Provides command to add a Primary Key table and notice to …
Sep 19, 2023
c11a633
BUGS-6563: Linting.
Sep 19, 2023
0efa954
BUGS-6563: Updates composer.lock.
Sep 19, 2023
6ead493
BUGS-6563: Testing addition of WP-CLI tests.
Sep 21, 2023
cea6bff
BUGS-6563: Tests STDOUT testing.
Sep 21, 2023
6c47e70
Revert "BUGS-6563: Tests STDOUT testing."
Sep 21, 2023
deb3cf4
Revert "BUGS-6563: Testing addition of WP-CLI tests."
Sep 21, 2023
85db732
BUGS-6563: Adds unit tests.
Sep 21, 2023
e59e8a6
BUGS-6563: Adds unit tests.
Sep 21, 2023
2d63ca9
BUGS-6563: Adds unit tests.
Sep 21, 2023
e05b096
BUGS-6563: Adds unit tests.
Sep 21, 2023
c951790
BUGS-6563: Adds unit tests.
Sep 21, 2023
a319cc2
BUGS-6563: Adds unit tests.
Sep 21, 2023
4dbfbc0
BUGS-6563: Adds unit tests.
Sep 21, 2023
535d9fd
BUGS-6563: Adds unit tests.
Sep 21, 2023
3b52166
BUGS-6563: Remove tests to check if they're causing other errors
Sep 21, 2023
94076eb
BUGS-6563: Add tests back somewhere else.
Sep 21, 2023
130c3a6
BUGS-6563: tweaks test parameters
Sep 25, 2023
13f40c4
BUGS-6563: debug info
Sep 25, 2023
6aaf554
BUGS-6563: debug info
Sep 25, 2023
a389725
BUGS-6563: adds finalize
Sep 25, 2023
07a3128
BUGS-6563: more debug
Sep 25, 2023
7972051
BUGS-6563: more debug
Sep 25, 2023
a8f2e09
BUGS-6563: more debug
Sep 25, 2023
0d7433e
BUGS-6563: more debug
Sep 25, 2023
9963c97
BUGS-6563: more debug
Sep 25, 2023
e8f8051
BUGS-6563: more debug
Sep 25, 2023
fd7e5d6
BUGS-6563: more debug
Sep 25, 2023
46d84e3
BUGS-6563: more debug
Sep 25, 2023
9382154
BUGS-6563: more debug
Sep 25, 2023
821d609
BUGS-6563: more debug
Sep 25, 2023
2d7a466
BUGS-6563: more debug
Sep 25, 2023
4fbd432
BUGS-6563: more debug
Sep 25, 2023
a36d720
BUGS-6563: Cleaning up debug
Sep 25, 2023
74e2965
BUGS-6563: Cleaning up debug
Sep 25, 2023
2c88a9d
BUGS-6563: debug again.
Sep 25, 2023
4c5f8a2
BUGS-6563: debug again.
Sep 25, 2023
d6e2a8c
BUGS-6563: debug again.
Sep 25, 2023
5da54c2
BUGS-6563: debug again.
Sep 25, 2023
8d219bb
BUGS-6563: change table name
Sep 25, 2023
2cf3bed
BUGS-6563: change table name
Sep 25, 2023
0c10e37
BUGS-6563: change table name
Sep 25, 2023
1f6b06d
BUGS-6563: adds back conditional fixing
Sep 26, 2023
6f3b9d3
BUGS-6563: let it fail.
Sep 26, 2023
57f8027
BUGS-6563: let it pass?
Sep 26, 2023
143d9ac
BUGS-6563: multisite only
Sep 26, 2023
c287d98
BUGS-6563: ALL THE THINGS
Sep 26, 2023
a9e3883
BUGS-6563: remove my test
Sep 26, 2023
4d99edc
BUGS-6563: remove my test
Sep 26, 2023
d07dd3d
BUGS-6563: only run one test
Sep 26, 2023
1865cdc
BUGS-6563: space is not equals
Sep 26, 2023
c9b3519
BUGS-6563: group > filter
Sep 26, 2023
3334530
BUGS-6563: manual > composer
Sep 26, 2023
918c636
BUGS-6563: deparallel?
Sep 26, 2023
18ba849
BUGS-6563: deparallel?
Sep 26, 2023
6654f96
BUGS-6563: ports changes to 7.x
Sep 26, 2023
2ffb777
BUGS-6563: uncomments second batch of tests
Sep 26, 2023
6b0b5b0
BUGS-6563: reinstall between tests
Sep 27, 2023
bec62fb
BUGS-6563: reinstall between tests
Sep 27, 2023
05b0961
BUGS-6563: comment out nightly build
Sep 27, 2023
f91af68
BUGS-6563: comment out nightly build
Sep 27, 2023
146f8ce
BUGS-6563: adds nightly, removes multisite
Sep 27, 2023
4482763
BUGS-6563: adds nightly, removes multisite
Sep 27, 2023
1b6e622
BUGS-6563: numbers.
Sep 27, 2023
9401532
BUGS-6563: remove multisite again
Sep 27, 2023
0254b9c
BUGS-6563: untruth
Sep 27, 2023
b577649
BUGS-6563: no more multisite
Sep 27, 2023
4945064
BUGS-6563: vanilla, with exclude
Sep 27, 2023
3029d28
BUGS-6563: unified test command
Sep 27, 2023
40d480e
BUGS-6563: updated version
Sep 27, 2023
d493601
BUGS-6563: revert to manual test running
Sep 27, 2023
57fd1de
BUGS-6563: revert revert
Sep 27, 2023
2bca7c3
BUGS-6563: revert version revert
Sep 27, 2023
6f16274
BUGS-6563: drop and create
Sep 27, 2023
014348e
BUGS-6563: drop and create
Sep 27, 2023
0eff919
BUGS-6563: -y
Sep 27, 2023
1f9fb9c
BUGS-6563: -y
Sep 27, 2023
9a154a6
BUGS-6563: syntax
Sep 27, 2023
f87cb9a
BUGS-6563: Cleanup
Sep 27, 2023
8e4ffe5
BUGS-6563: Updates readme and removes vestigial group.
Sep 28, 2023
f246d6b
BUGS-6563: Removes update to composer.json.
Sep 28, 2023
e57c627
BUGS-6563: Updates version numbers
Sep 28, 2023
ca67537
README markdown spacing
pwtyler Sep 28, 2023
aad97c0
BUGS-6563: Tweak to trigger build
Sep 29, 2023
15c9d0b
Update README.md
rwagner00 Sep 29, 2023
571a263
BUGS-6563: Updates README.md
Sep 29, 2023
396e5ae
Update pantheon-sessions.php
rwagner00 Oct 4, 2023
ac1b253
Update pantheon-sessions.php
rwagner00 Oct 4, 2023
d33983a
Update pantheon-sessions.php
rwagner00 Oct 4, 2023
018a352
[BUGS-6563]: Alters variable name
Oct 4, 2023
cad5438
[BUGS-6563]: Adds upgrade notice.
Oct 4, 2023
8e3b563
[BUGS-6563]: Adds specific version number.
Oct 4, 2023
7834961
Update tests/phpunit/test-init-plugin.php
rwagner00 Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 24 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 2
version: 2.1
workflows:
version: 2
version: 2.1
main:
jobs:
- test-behat
Expand All @@ -16,6 +16,25 @@ workflows:
- master
jobs:
- test-behat
commands:
run_test:
steps:
- run:
name: "Run Tests"
command: |
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
composer phpunit
WP_MULTISITE=1 composer phpunit
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 nightly true
composer phpunit
bash bin/full-teardown-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
vendor/bin/phpunit --group=cli_command
WP_MULTISITE=1 vendor/bin/phpunit --group=cli_command
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 nightly true
vendor/bin/phpunit --group=cli_command
jobs:
rwagner00 marked this conversation as resolved.
Show resolved Hide resolved
test-behat:
resource_class: small
Expand Down Expand Up @@ -94,15 +113,8 @@ jobs:
sudo docker-php-ext-enable imagick
sudo docker-php-ext-install mysqli
sudo apt-get install mariadb-client-10.5
- run:
name: "Run Tests"
command: |
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
composer phpunit
WP_MULTISITE=1 composer phpunit
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 nightly true
composer phpunit
- run_test

test-phpunit-82:
resource_class: small
working_directory: ~/pantheon-systems/wp-native-php-sessions
Expand Down Expand Up @@ -133,12 +145,4 @@ jobs:
sudo docker-php-ext-enable imagick
sudo docker-php-ext-install mysqli
sudo apt-get install mariadb-client-10.6
- run:
name: "Run Tests"
command: |
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
composer phpunit
WP_MULTISITE=1 composer phpunit
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 nightly true
composer phpunit
- run_test
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Tags:** comments, sessions
**Requires at least:** 4.7
**Tested up to:** 6.3
**Stable tag:** 1.3.7-dev
**Stable tag:** 1.4.0-dev
pwtyler marked this conversation as resolved.
Show resolved Hide resolved
**Requires PHP:** 5.4
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -42,6 +42,20 @@ To override this use the `pantheon_session_expiration` filter before the WordPre
}
add_filter( 'pantheon_session_expiration', 'my_session_expiration_override' );

## CLI Commands ##
rwagner00 marked this conversation as resolved.
Show resolved Hide resolved

### `add-index` ###

This command should be run if your installation of the plugin occurred before the addition of the primary ID key to the session table. You will be automatically notified when you visit any admin page if this is the case. If there's no message, your version is good to go. Note that this command is non-destructive, a new table will be created and the existing one preserved in a backup state until you have verified that the upgrade is functioning as expected.
rwagner00 marked this conversation as resolved.
Show resolved Hide resolved

### `primary-key-finalize` ###

If you have run the `add-index` command and have verified that the new table is functioning correctly, running the `primary-key-finalize` command will perform a database cleanup and remove the backup table.

### `primary-key-revert` ###

If you have run the `add-index` command and something unexpected has occurred, just run the `primary-key-revert` command and the backup table will immediately be returned to being the active table.

## Contributing ##

See [CONTRIBUTING.md](https://github.com/pantheon-systems/wp-native-php-sessions/blob/main/CONTRIBUTING.md) for information on contributing.
Expand Down Expand Up @@ -71,6 +85,10 @@ This mu-plugin will load WP Native PHP Sessions before all other plugins, while

## Changelog ##

### 1.4.0 ###
* Adds new CLI command to add a Primary Column (id) to the `pantheon_sessions` table for users who do not have one. [[#265](https://github.com/pantheon-systems/wp-native-php-sessions/pull/265)]
* Adds alert to dashboard for users who need to run the command.

### 1.3.7-dev ###
rwagner00 marked this conversation as resolved.
Show resolved Hide resolved
* Updates Pantheon WP Coding Standards to 2.0 [[#264](https://github.com/pantheon-systems/wp-native-php-sessions/pull/264)]

Expand Down
44 changes: 44 additions & 0 deletions bin/full-teardown-wp-tests.sh
pwtyler marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host]"
exit 1
fi

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}

TMPDIR=${TMPDIR-/tmp}
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}

file_delete() {
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
}

drop_db() {

# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
echo Y | mysqladmin drop $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}

file_delete
drop_db
30 changes: 30 additions & 0 deletions inc/class-cli-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,36 @@ public function delete( $args, $assoc_args ) {
}
}
}

/**
* Set id as primary key in the Native PHP Sessions plugin table.
*
* @subcommand add-index
*/
public function add_index( $args, $assoc_arc ) {
$pan_session = new \Pantheon_Sessions();
rwagner00 marked this conversation as resolved.
Show resolved Hide resolved
$pan_session->add_index();
}

/**
* Finalizes the creation of a primary key by deleting the old data.
*
* @subcommand primary-key-finalize
*/
public function primary_key_finalize() {
$pan_session = new \Pantheon_Sessions();
$pan_session->primary_key_finalize();
}

/**
* Reverts addition of primary key.
*
* @subcommand primary-key-revert
*/
public function primary_key_revert() {
$pan_session = new \Pantheon_Sessions();
$pan_session->primary_key_revert();
}
}

\WP_CLI::add_command( 'pantheon session', '\Pantheon_Sessions\CLI_Command' );