PHP code example of jcore / runner

1. Go to this page and download the library: Download jcore/runner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jcore / runner example snippets


add_filter('jcore_runner_functions', function($scripts) {
    $scripts['my_utility_script'] = [
        'title'    => 'Update Product Meta',
        'callback' => 'my_namespace\update_products_callback',
        'input'    => [
            'batch_size' => [
                'title'   => 'Items per batch',
                'type'    => 'number',
                'default' => 50,
            ],
        ],
    ];
    return $scripts;
});

namespace my_namespace;

use Jcore\Runner\Arguments;

function update_products_callback(Arguments $args) {
    // Access user input
    $batch_size = $args->input['batch_size'] ?? 10;

    // Access persistent data between pages
    $current_page = $args->page; // Starts at 1

    echo "Processing batch $current_page...\n";

    // Perform your logic here...

    // To continue to the next page (pagination):
    if ($current_page < 5) {
        $args->set_next_page();
        // Pass data to the next iteration
        $args->data['processed_count'] = ($args->data['processed_count'] ?? 0) + $batch_size;
    }

    return $args;
}

'input' => [
    'category' => [
        'title'   => 'Select Category',
        'type'    => 'select',
        'options' => [
            'news' => 'News',
            'tech' => 'Technology',
        ],
        'default' => 'news',
    ],
    'start_date' => [
        'title' => 'Start From',
        'type'  => 'date',
    ]
]

function my_export_script(Arguments $args) {
    $args->export->set_extension('csv');
    $args->export->add_row(['ID', 'Name', 'Status']);
    $args->export->add_row([1, 'Test Item', 'Complete']);

    return $args;
}

// 1. Register the status field
add_filter('jcore_runner_status', function($status) {
    $status['progress_bar'] = 'Current Progress';
    return $status;
});

// 2. Update it in your callback
function my_paginated_script(Arguments $args) {
    $total = 100;
    $current = $args->page * 10;

    // This will update the 'Current Progress' section in the UI
    $args->return['progress_bar'] = "$current / $total items processed";

    if ($current < $total) {
        $args->set_next_page();
    }
    return $args;
}