Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(Merge): rework merge process to prevent it from stopping #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stonebuzz
Copy link

Check before insert if a glpi_plugin_jamf_devices already exist

To prevent this

[2024-07-12 16:06:42] glpisqllog.ERROR: DBmysql::doQuery() in /mnt/diskhome/home/htdocs/src/DBmysql.php line 403
  *** MySQL query error:
  SQL: INSERT INTO `glpi_plugin_jamf_devices` (`itemtype`, `items_id`, `udid`, `jamf_type`, `jamf_items_id`) VALUES ('Computer', '401', 'xxx-xxxx-xxxx-xxxx-xxx-', 'MobileDevice', '44')
  Error: Duplicate entry 'Computer-401' for key 'glpi_plugin_jamf_devices.unicity'
  Backtrace :
  src/DBmysql.php:1381                               DBmysql->doQuery()
  marketplace/jamf/ajax/merge.php:118                DBmysql->insert()

Move in global try/catch to prevent process from stopping during API fetch and to be able to 'list' all device irrecoverable

Client error: `GET https://xxxxxxx.jamfcloud.com/api//v2/mobile-devices/82/detail` resulted in a `404 Not Found` response:
{
  "httpStatus" : 404,
  "errors" : [ {
    "code" : "INVALID_ID",
    "description" : "Not Found",
    "id" : "0",
    (truncated...)

@stonebuzz stonebuzz requested a review from cconard96 July 12, 2024 14:27
@stonebuzz stonebuzz self-assigned this Jul 12, 2024
@stonebuzz stonebuzz added the bug Something isn't working label Jul 12, 2024
$jamf_item = PluginJamfAPI::getMobileDeviceByID($jamf_id, true);
if ($jamf_item === null) {
// API error or device no longer exists in Jamf
throw new RuntimeException('Jamf API error or item no longer exists!');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without throwing the exception here, you aren't able to catch the case where the API doesn't return the data in the try/catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants