- Modernized authentication with the introduction of TenantProject

- Created a base mail template
- Adapt and improve document API to usage of catalogs and processors
- Adapt eveai_sync to new authentication mechanism and usage of catalogs and processors
This commit is contained in:
Josako
2024-11-21 17:24:33 +01:00
parent 4c009949b3
commit 7702a6dfcc
72 changed files with 2338 additions and 503 deletions

View File

@@ -100,19 +100,20 @@ class EveAI_Post_Handler {
$post = get_post($post_id);
return array(
'name' => $post->post_title,
'system_metadata' => json_encode([
'user_metadata' => json_encode([
'post_id' => $post_id,
'type' => $post->post_type,
'author' => get_the_author_meta('display_name', $post->post_author),
'categories' => $post->post_type === 'post' ? wp_get_post_categories($post_id, array('fields' => 'names')) : [],
'tags' => $post->post_type === 'post' ? wp_get_post_tags($post_id, array('fields' => 'names')) : [],
]),
])
);
}
private function has_metadata_changed($old_data, $new_data) {
return $old_data['name'] !== $new_data['name'] ||
$old_data['user_metadata'] !== $new_data['user_metadata'];
(isset($old_data['user_metadata']) && isset($new_data['user_metadata']) &&
$old_data['user_metadata'] !== $new_data['user_metadata']);
}
private function refresh_document_with_info($evie_id, $data) {
@@ -139,17 +140,27 @@ class EveAI_Post_Handler {
}
public function handle_post_delete($post_id) {
// First check if we have an EveAI document ID for this post
$evie_id = get_post_meta($post_id, '_eveai_document_id', true);
if ($evie_id) {
try {
$this->api->invalidate_document($evie_id);
error_log("EveAI: Attempting to invalidate document {$evie_id} for post {$post_id}");
$result = $this->api->invalidate_document($evie_id);
error_log("EveAI: Successfully invalidated document {$evie_id}");
// Clean up post meta
delete_post_meta($post_id, '_eveai_document_id');
delete_post_meta($post_id, '_eveai_document_version_id');
return true;
} catch (Exception $e) {
error_log('EveAI invalidate error: ' . $e->getMessage());
add_action('admin_notices', function() use ($e) {
echo '<div class="notice notice-error is-dismissible">';
echo '<p>EveAI Sync Error: ' . esc_html($e->getMessage()) . '</p>';
echo '</div>';
});
error_log("EveAI: Error invalidating document {$evie_id}: " . $e->getMessage());
return false;
}
} else {
error_log("EveAI: No document ID found for post {$post_id}, skipping invalidation");
return false;
}
}
@@ -195,8 +206,10 @@ class EveAI_Post_Handler {
private function prepare_post_data($post_id) {
$post = get_post($post_id);
// Get the permalink but replace localhost with the FQDN, keeping the port
$url = get_permalink($post_id);
$data = array(
'url' => get_permalink($post_id),
'url' => $url,
'name' => $post->post_title,
'language' => get_option('eveai_default_language', 'en'),
'valid_from' => get_gmt_from_date($post->post_date, 'Y-m-d\TH:i:s\Z'),