Skip to content

Commit

Permalink
Merge pull request #19 from kagg-design/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.0
  • Loading branch information
kagg-design authored Dec 28, 2024
2 parents 01a5e8e + 057a939 commit 494bd80
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 88 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on: [ push, pull_request ]

jobs:
run:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest ]
php-version: [ '7.0' ]
php-version: [ '7.2' ]

runs-on: ${{ matrix.os }}

name: PHP ${{ matrix.php-version }} on ${{ matrix.os }}

Expand All @@ -24,7 +24,7 @@ jobs:
extensions: json, mysqli, mbstring, zip

- name: Install dependencies with caching
uses: kagg-design/composer-install@v2
uses: ramsey/composer-install@v3

- name: Run code sniffer
run: vendor/bin/phpcs --colors
run: composer phpcs
3 changes: 3 additions & 0 deletions .github/workflows/deploy-readme-assets-to-wp-org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install SVN
run: sudo apt-get update && sudo apt-get install -y subversion

- name: WordPress.org plugin asset/readme update
uses: 10up/action-wordpress-plugin-asset-update@stable
env:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/deploy-to-wp-org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Install SVN
run: sudo apt-get update && sudo apt-get install -y subversion

- name: Install dependencies with caching
uses: kagg-design/composer-install@v2
uses: ramsey/composer-install@v3
with:
composer-options: "--no-dev --optimize-autoloader --classmap-authoritative"

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.9.0",
"squizlabs/php_codesniffer": "^3.11.2",
"phpcompatibility/php-compatibility": "^9.3.5",
"phpcompatibility/phpcompatibility-wp": "^2.1.4",
"wp-coding-standards/wpcs": "^3.0.1"
"phpcompatibility/phpcompatibility-wp": "^2.1.5",
"wp-coding-standards/wpcs": "^3.1.0"
},
"autoload": {
"psr-4": {
"KAGG\\Generator\\": "src/php"
}
},
"scripts": {
"phpcs": "vendor/bin/phpcs --colors"
"phpcs": "vendor/bin/phpcs --colors --standard=phpcs.xml"
}
}
6 changes: 3 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<!-- What to scan -->
<file>.</file>
<!-- Exclude all dirs except needed -->
<exclude-pattern>^(?!.*/kagg-fast-post-generator).*</exclude-pattern>
<exclude-pattern>*/\.github/*</exclude-pattern>
<exclude-pattern>*/\.wordpress-org/*</exclude-pattern>
<exclude-pattern>*/assets/*</exclude-pattern>
Expand All @@ -14,11 +16,9 @@
<arg value="sp"/><!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="extensions" value="php"/>
<arg name="parallel" value="12"/><!-- Enables parallel processing when available for faster results. -->
<arg name="cache" value=".phpcs.cache"/>

<config name="installed_paths" value="vendor/phpcompatibility/php-compatibility,vendor/phpcompatibility/phpcompatibility-paragonie,vendor/phpcompatibility/phpcompatibility-wp,vendor/phpcsstandards/phpcsextra,vendor/phpcsstandards/phpcsutils,vendor/wp-coding-standards/wpcs"/>
<config name="testVersion" value="7.0-"/>
<config name="testVersion" value="7.2-"/>

<!-- Rules: Check PHP version compatibility -->
<rule ref="PHPCompatibility"/>
Expand Down
11 changes: 5 additions & 6 deletions plugin.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
<?php
/**
* Fast post generator.
* KAGG Generator.
*
* @package kagg/generator
* @author KAGG Design
* @license GPL-2.0-or-later
* @wordpress-plugin
*
* Plugin Name: KAGG Fast Post Generator
* Plugin Name: KAGG Generator
* Plugin URI: https://wordpress.org/plugins/kagg-fast-post-generator/
* Description: Generates posts/pages. Useful to generate millions of records in wp_posts table.
* Version: 1.11.0
* Version: 2.0.0
* Requires at least: 5.3
* Requires PHP: 7.0
* Requires PHP: 7.2
* Author: KAGG Design
* Author URI: https://profiles.wordpress.org/kaggdesign/
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: kagg-generator
* Domain Path: /languages/
*/

use KAGG\Generator\Main;
Expand All @@ -36,7 +35,7 @@
/**
* Plugin version.
*/
const KAGG_GENERATOR_VERSION = '1.11.0';
const KAGG_GENERATOR_VERSION = '2.0.0';

/**
* Path to the plugin dir.
Expand Down
14 changes: 11 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: kaggdesign
Tags: generate posts, generate pages, development, bulk generate
Requires at least: 5.3
Tested up to: 6.5
Stable tag: 1.11.0
Requires PHP: 7.0
Tested up to: 6.7
Stable tag: 2.0.0
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -39,6 +39,14 @@ Yes, you can!

== Changelog ==

= 2.0.0 =
* Dropped support for PHP 7.0. The minimum required PHP version is now 7.2.
* Fixed kagg_generator_comment_max_nesting_level filter name.
* Fixed inability to create a temporary table when it exists after previous operations.
* Fixed deprecation errors with PHP 8.4.
* Tested with WordPress 6.7.
* Tested with PHP 8.4.

= 1.11.0 =
* Added admin notice about the unusable system temp directory.

Expand Down
4 changes: 2 additions & 2 deletions src/php/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct() {
* is-dismissible.
* @param array $options Notice options.
*/
public function add_notice( string $message, string $class_name = 'notice', array $options = [] ) {
public function add_notice( string $message, string $class_name = 'notice', array $options = [] ): void {
$this->notices[] = [
'message' => $message,
'class' => $class_name,
Expand All @@ -45,7 +45,7 @@ public function add_notice( string $message, string $class_name = 'notice', arra
/**
* Show all notices.
*/
public function show_notices() {
public function show_notices(): void {
foreach ( $this->notices as $notice ) {
if ( ! $this->is_screen_allowed( $notice ) ) {
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/php/Generator/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Comment extends Item {
*
* @return void
*/
protected function prepare_stub() {
protected function prepare_stub(): void {
$this->random_posts_count = max(
1,
(int) apply_filters( 'kagg_generator_comment_random_posts_count', 1000 )
Expand All @@ -144,7 +144,7 @@ protected function prepare_stub() {

$this->nesting_percentage = max(
0,
(int) apply_filters( 'kagg_generator_comment_max_nesting_level', 50 )
(int) apply_filters( 'kagg_generator_comment_nesting_percentage', 50 )
);
$this->nesting_percentage = min( 100, $this->nesting_percentage );

Expand Down Expand Up @@ -188,7 +188,7 @@ protected function prepare_stub() {
*
* @return void
*/
protected function prepare_generate() {
protected function prepare_generate(): void {
global $wpdb;

$this->post_id_randomizer = new Randomizer( $this->prepare_posts() );
Expand Down Expand Up @@ -275,7 +275,7 @@ public function generate(): array {
* @return int
* @noinspection RandomApiMigrationInspection
*/
private function add_comment_to_post( $post ): int {
private function add_comment_to_post( object $post ): int {
if ( ! isset( $post->comments ) ) {
$post->comments = $this->post_comments_stub;
}
Expand Down
27 changes: 14 additions & 13 deletions src/php/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Generator {
/**
* Name of the local_infile MySQL variable.
*/
const LOCAL_INFILE = 'local_infile';
private const LOCAL_INFILE = 'local_infile';

/**
* Value of the local_infile MySQL variable.
Expand Down Expand Up @@ -103,7 +103,7 @@ public function use_local_infile(): bool {
*
* @return void
*/
public function run() {
public function run(): void {
$this->run_checks( Settings::GENERATE_ACTION, true );

ob_start();
Expand Down Expand Up @@ -197,7 +197,7 @@ public function run() {
*
* @return void
*/
public function download_sql() {
public function download_sql(): void {
$this->run_checks( Settings::DOWNLOAD_SQL_ACTION );

// Nonce is checked by check_ajax_referer() in run_checks().
Expand Down Expand Up @@ -275,7 +275,7 @@ public function download_sql() {
*
* @return void
*/
public function run_checks( string $action, bool $check_data = false ) {
public function run_checks( string $action, bool $check_data = false ): void {
// Run a security check.
if ( ! check_ajax_referer( $action, 'nonce', false ) ) {
wp_send_json_error( esc_html__( 'Your session has expired. Please reload the page.', 'kagg-generator' ) );
Expand Down Expand Up @@ -305,7 +305,7 @@ public function run_checks( string $action, bool $check_data = false ) {
* @return void
* @throws RuntimeException With error message.
*/
private function generate_items( int $count, string $temp_filename ) {
private function generate_items( int $count, string $temp_filename ): void {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
$f = fopen( 'php://temp', 'wb+' );

Expand Down Expand Up @@ -339,14 +339,15 @@ private function generate_items( int $count, string $temp_filename ) {
* @param bool $last_item Whether we process the last item in the file.
*
* @return false|int
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpUnusedParameterInspection.
* @noinspection PhpRedundantOptionalArgumentInspection
*/
private function write_item_csv( $f, bool $last_item ) {
return fputcsv( $f, $this->item_handler->generate(), '|' );
return fputcsv( $f, $this->item_handler->generate(), '|', '"', '\\' );
}

/**
* Write item in sql format.
* Write item in SQL format.
*
* @param resource $f File.
* @param bool $last_item Whether we process the last item in the file.
Expand Down Expand Up @@ -383,7 +384,7 @@ private function write_item_sql( $f, bool $last_item ) {
* @noinspection SqlInsertValues
* @noinspection SqlResolve
*/
private function write_file( string $temp_filename, $f ) {
private function write_file( string $temp_filename, $f ): void {
if ( $this->download_sql ) {
$table = $this->item_handler->get_table();
$fields = implode( ', ', $this->item_handler->get_fields() );
Expand Down Expand Up @@ -416,7 +417,7 @@ private function write_file( string $temp_filename, $f ) {
* @return void
* @throws RuntimeException With error message.
*/
private function store_items( string $temp_filename ) {
private function store_items( string $temp_filename ): void {
global $wpdb;

if ( $this->download_sql ) {
Expand Down Expand Up @@ -457,7 +458,7 @@ private function store_items( string $temp_filename ) {
* @return void
* @throws RuntimeException With error message.
*/
private function set_local_infile() {
private function set_local_infile(): void {
global $wpdb;

if ( ! $this->use_local_infile ) {
Expand Down Expand Up @@ -492,7 +493,7 @@ private function set_local_infile() {
* @return void
* @throws RuntimeException With error message.
*/
private function revert_local_infile() {
private function revert_local_infile(): void {
global $wpdb;

if ( ! $this->use_local_infile ) {
Expand Down Expand Up @@ -557,7 +558,7 @@ private function get_settings( array $data ): array {
/**
* Send HTTP headers for .sql file download.
*/
private function http_headers() {
private function http_headers(): void {

$file_name = 'kagg-generator.sql';

Expand Down
11 changes: 5 additions & 6 deletions src/php/Generator/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ abstract class Item {
/**
* Zero time in MySQL format.
*/
const ZERO_MYSQL_TIME = '0000-00-00 00:00:00';
protected const ZERO_MYSQL_TIME = '0000-00-00 00:00:00';

/**
* MySQL time format.
*/
const MYSQL_TIME_FORMAT = 'Y-m-d H:i:s';
protected const MYSQL_TIME_FORMAT = 'Y-m-d H:i:s';

/**
* Maximum users count. Newly generated comments will have a random author from this user set.
Expand Down Expand Up @@ -174,10 +174,9 @@ public function get_fields(): array {
* @param int $max_time_shift Time shift.
*
* @return void
* @noinspection CallableParameterUseCaseInTypeContextInspection
* @noinspection RandomApiMigrationInspection
*/
protected function add_time_shift_to_post( $post, int $max_time_shift = 0 ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
protected function add_time_shift_to_post( object $post, int $max_time_shift = 0 ): void { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$max_time_shift = 0 === $max_time_shift ? $this->max_time_shift : $max_time_shift;

// phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand
Expand Down Expand Up @@ -280,14 +279,14 @@ protected function gmt_date( string $format, int $time ) {
*
* @return void
*/
abstract protected function prepare_stub();
abstract protected function prepare_stub(): void;

/**
* Prepare the generation process.
*
* @return void
*/
protected function prepare_generate() {}
protected function prepare_generate(): void {}

/**
* Generate item.
Expand Down
4 changes: 2 additions & 2 deletions src/php/Generator/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Post extends Item {
*
* @return void
*/
protected function prepare_stub() {
protected function prepare_stub(): void {
$this->paragraphs_in_post = max(
1,
(int) apply_filters( 'kagg_generator_paragraphs_in_post', 12 )
Expand Down Expand Up @@ -100,7 +100,7 @@ protected function prepare_stub() {
*
* @return void
*/
protected function prepare_generate() {
protected function prepare_generate(): void {
$this->user_randomizer = new Randomizer( $this->prepare_users() );

$initial_timestamp = time() - $this->initial_time_shift;
Expand Down
Loading

0 comments on commit 494bd80

Please sign in to comment.