Skip to content

Commit

Permalink
Merge pull request #335 from threadi/feature/optimizedCleanupAfterImport
Browse files Browse the repository at this point in the history
Feature/optimized cleanup after import
  • Loading branch information
threadi authored Jan 31, 2025
2 parents d78ea53 + d2ab5af commit 878f6ab
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
37 changes: 36 additions & 1 deletion app/PersonioIntegration/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Exception;
use PersonioIntegrationLight\Plugin\Languages;
use SimpleXMLElement;
use WP_Post;

/**
* Import-handling for positions from Personio.
Expand Down Expand Up @@ -365,6 +366,40 @@ public function run(): void {
/* translators: %1$s will be replaced by the Personio account URL, %2$s by the language title. */
$this->log->add_log( sprintf( __( 'Import of positions from Personio account %1$s for language %2$s ended.', 'personio-integration-light' ), wp_kses_post( $this->get_link() ), esc_html( $language_title ) ), 'success', 'import' );
}
else {
$true = true;
/**
* Do not delete positions if Personio sends 0 positions.
*
* @since 4.2.0 Available since 4.2.0
* @param bool $true Must be false to prevent deletion in this case.
* @noinspection PhpConditionAlreadyCheckedInspection
**/
if( apply_filters( 'personio_integration_import_delete_if_no_positions_returned', $true ) ) {
// remove all positions as we got none from Personio.
foreach ( $positions_obj->get_positions() as $position_obj ) {
if ( ! $position_obj instanceof Position ) {
continue;
}

// get Personio ID for logging.
$personio_id = $position_obj->get_personio_id();

// delete this position from database without using trash.
$result = wp_delete_post( $position_obj->get_id(), true );

if ( $result instanceof WP_Post ) {
// log this event.
/* translators: %1$s will be replaced by the PersonioID. */
$this->log->add_log( sprintf( __( 'Position %1$s has been deleted as it was not updated during the last import run.', 'personio-integration-light' ), esc_html( $personio_id ) ), 'success', 'import' );
} else {
// log event.
/* translators: %1$s will be replaced by the PersonioID. */
$this->log->add_log( sprintf( __( 'Removing of not updated position %1$s failed.', 'personio-integration-light' ), esc_html( $personio_id ) ), 'error', 'import' );
}
}
}
}

// log ok.
/* translators: %1$d will be replaced by a number, %2$s by the Personio account URL and %3$s by the language title. */
Expand Down Expand Up @@ -450,7 +485,7 @@ public function set_xml_positions( SimpleXMLElement $xml_positions ): void {
* @return bool
*/
private function has_xml_positions(): bool {
return ! empty( $this->get_xml_positions() );
return count( $this->get_xml_positions() ) > 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Plugin/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function init_setup(): void {
'txt_error_2' => sprintf( __( '<strong>If reason is unclear</strong> please contact our <a href="%1$s" target="_blank">support-forum (opens new window)</a> with as much detail as possible.', 'personio-integration-light' ), esc_url( Helper::get_plugin_support_url() ) ),
)
);
$setup_obj->set_display_hook( 'stellen_page_personioPositions' );
$setup_obj->set_display_hook( Helper::get_archive_slug() . '_page_personioPositions' );

// set configuration for setup.
$setup_obj->set_config( $this->get_config() );
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changed

- Optimized import if no position is returned from Personio (and no other errors occur)
- Optimized loading of JS in backend to in order not to influence the loading times there too much
- Optimized output of positions in WordPress dashboard
- Changed dialog and handling of extension state changes
Expand Down

0 comments on commit 878f6ab

Please sign in to comment.