Skip to content

Commit

Permalink
Remove GP_Thing::set_memory_limit() and use `wp_raise_memory_limit(…
Browse files Browse the repository at this point in the history
…)` instead
  • Loading branch information
ocean90 committed Jun 16, 2021
1 parent abde809 commit 07e59bb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

**Breaking Changes**
* Developers: Removed `GP_Thing::set_memory_limit()` in favor of `wp_raise_memory_limit()`. ([#1246](https://github.com/GlotPress/GlotPress-WP/pull/1246))

## [3.0.0-alpha.3 (April 29, 2021)

**Bugfixes**
Expand Down
3 changes: 3 additions & 0 deletions gp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@
add_filter( 'gp_title', 'wptexturize' );
add_filter( 'gp_title', 'convert_chars' );
add_filter( 'gp_title', 'esc_html' );

// Memory limit
add_filter( 'gp_translations_import_memory_limit', 'gp_set_translations_import_max_memory_limit' );
11 changes: 11 additions & 0 deletions gp-includes/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,14 @@ function gp_get_sort_by_fields() {
*/
return apply_filters( 'gp_sort_by_fields', $sort_fields );
}

/**
* Sets the maximum memory limit available for translations imports.
*
* @since 3.0.0
*
* @return string The maximum memory limit.
*/
function gp_set_translations_import_max_memory_limit() {
return '256M';
}
28 changes: 0 additions & 28 deletions gp-includes/thing.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,32 +766,4 @@ public function apply_default_conditions( $conditions_str ) {
}
return implode( ' AND ', $conditions );
}


// set memory limits.
public function set_memory_limit( $new_limit ) {
$current_limit = ini_get( 'memory_limit' );

if ( '-1' == $current_limit ) {
return false;
}

$current_limit_int = intval( $current_limit );
if ( false !== strpos( $current_limit, 'G' ) ) {
$current_limit_int *= 1024;
}

$new_limit_int = intval( $new_limit );
if ( false !== strpos( $new_limit, 'G' ) ) {
$new_limit_int *= 1024;
}

if ( -1 != $current_limit && ( -1 == $new_limit || $current_limit_int < $new_limit_int ) ) {
ini_set( 'memory_limit', $new_limit );
return true;
}

return false;
}

}
2 changes: 1 addition & 1 deletion gp-includes/things/translation-set.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function by_project_id( $project_id ) {
* @return boolean or void
*/
public function import( $translations, $desired_status = 'current' ) {
$this->set_memory_limit( '256M' );
wp_raise_memory_limit( 'gp_translations_import' );

if ( ! isset( $this->project ) || ! $this->project ) {
$this->project = GP::$project->get( $this->project_id );
Expand Down

0 comments on commit 07e59bb

Please sign in to comment.