Skip to content

Commit

Permalink
#3004 impliment transient clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Feb 20, 2019
1 parent d538bfe commit 8631ba8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
18 changes: 15 additions & 3 deletions classes/transient.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ public static function submission_complete(){
* Clear all schedule cron jobs
*/
public static function clear_wpcron(){

$transients = self::get_all();
if( ! empty($transients)){
foreach ($transients as $transient_id ){
wp_clear_scheduled_hook(self::CRON_ACTION, [$transient_id]);
}
}

}

Expand All @@ -154,9 +159,16 @@ public static function clear_wpcron(){
* @return array
*/
public static function get_all(){

global $wpdb;
$like = '%' . $wpdb->esc_like( 'cftransdata' ) . '%';
$query = $wpdb->prepare( "SELECT option_name FROM wp_options WHERE option_name LIKE %s ", $like );
$return = [];

$results = $wpdb->get_results($query,ARRAY_A);
if( ! empty( $results) ){
foreach ($results as $result ){
$return[] = $result[ 'option_name' ];
}
}
return $return;
}

Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
<testsuite name="integration-cf2" suffix=".php">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 2 additions & 6 deletions tests/Integration/Caldera_Forms_TransientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ public function testDelete_at_submission_complete()
*/
public function testGetAllWhenThereAreNone()
{
$id = 'r2345';
$value = [9,0, new \stdClass() ];
$this->assertSame( 0, count( Caldera_Forms_Transient::get_all() ) );
\Caldera_Forms_Transient::set_transient($id,$value,1500 );

$this->assertSame( 0, count( Caldera_Forms_Transient::get_all() ) );



}

/**
Expand All @@ -115,10 +113,8 @@ public function testGetAllWhenThereAreSomeToGet()
{
$id = 'r2345';
$value = [9,0, new \stdClass() ];
$this->assertSame( 0, count( Caldera_Forms_Transient::get_all() ) );
\Caldera_Forms_Transient::set_transient($id,$value,1500 );
$transients = Caldera_Forms_Transient::get_all();

$this->assertSame( 1, count( $transients ) );
$this->assertSame( $transients[0], 'cftransdata_' . $id );
\Caldera_Forms_Transient::set_transient('cf222',[87],1500 );
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -2768,16 +2768,16 @@
},
{
"name": "wpackagist-plugin/gutenberg",
"version": "5.0.0",
"version_normalized": "5.0.0.0",
"version": "5.1.0",
"version_normalized": "5.1.0.0",
"source": {
"type": "svn",
"url": "https://plugins.svn.wordpress.org/gutenberg/",
"reference": "tags/5.0.0"
"reference": "tags/5.1.0"
},
"dist": {
"type": "zip",
"url": "https://downloads.wordpress.org/plugin/gutenberg.5.0.0.zip",
"url": "https://downloads.wordpress.org/plugin/gutenberg.5.1.0.zip",
"reference": null,
"shasum": null
},
Expand Down

0 comments on commit 8631ba8

Please sign in to comment.