Which hook to use for OAI-PMH Harvester

We have a situation in which we want to insert data into a custom table each time an item is inserted. I used the after_save_item hook and it is successful when I click on Save after editing an item in the Admin view of Omeka. However, if I use the OAI-PMH Harvester, it does not trigger the hook. I’ve also tried using the after_insert_item hook and after_update_item hook but neither worked. I traced the code for the importer and it is calling the afterSave callback so I’m not sure what I am doing wrong. Does anyone know which hook I should be using so that each item being harvested triggers it?

Is it possible you're doing some check for the "post" data in your hook?

Those hooks should fire just the same way when items are added by the harvester, but there won't be any post data.

No post data at all. I'm only grabbing the record to get the identifiers and the omeka_id. Here is the exact method:

public function hookAfterSaveItem($args)
$record = $args['record'];
//Parse out the Oasis ID from the Identifier link
$oasisid = NULL;

$identifier = metadata($record, array('Dublin Core', 'Identifier'), array('all' => true, 'no_filter' => true));
$identifierarray = !is_array($identifier) ? array($identifier) : $identifier;

$instance = 'dev';
$collection = 'dev';
foreach($identifierarray as $i)
//Get rid of the initial /
$uri = substr($_SERVER['REQUEST_URI'], 1);
//Get the instance which will be the 1st element in the array
$uriAsArray = explode("/", $uri);
$instance = $uriAsArray[0];

if (preg_match("/^http:\/\/$_SERVER[HTTP_HOST]\/$instance\/[a-zA-Z]+\/[0-9a-zA-Z]+$/",$i)) {
$parsedidentifier = explode("/", $i);
$oasisid = end($parsedidentifier);
$collection = prev($parsedidentifier);

if (!is_null($oasisid)){
// insert/update
$sql = "INSERT INTO {$this->_db->prefix}oasis_ids (omeka_id, oasis_id, collection) VALUES ($record->id, '$oasisid', '$collection') ON DUPLICATE KEY UPDATE oasis_id = '$oasisid', collection='$collection';";

The code works fine when I save an item after updating a single record but not when harvesting. I've also tried hookAfterSaveRecord to make sure that it wasn't using something other than an item but that didn't work either.

Not 100% sure, but my guess is that just before inserting, $oasisid is still NULL. The harvester uses a process from php-cli, so that might leave your check on the http $_SERVER empty?

Bingo. Thank you for pointing that out.