mirror of https://github.com/MISP/MISP
fix: [sync] Fix pull not working caused by the refactor
parent
413728919f
commit
7166b227eb
|
@ -1812,8 +1812,6 @@ class Server extends AppModel
|
|||
$eventIds = array_intersect($eventIds, $local_event_ids);
|
||||
} elseif (is_numeric($technique)) {
|
||||
$eventIds[] = intval($technique);
|
||||
// if we are downloading a single event, don't fetch all proposals
|
||||
$conditions = array('Event.id' => $technique);
|
||||
} else {
|
||||
return array('error' => array(4, null));
|
||||
}
|
||||
|
@ -1832,7 +1830,7 @@ class Server extends AppModel
|
|||
return false;
|
||||
}
|
||||
|
||||
private function __updatePulledEventBeforeInsert($event, $server, $user)
|
||||
private function __updatePulledEventBeforeInsert(&$event, $server, $user)
|
||||
{
|
||||
// we have an Event array
|
||||
// The event came from a pull, so it should be locked.
|
||||
|
@ -1870,10 +1868,9 @@ class Server extends AppModel
|
|||
return $event;
|
||||
}
|
||||
|
||||
private function __checkIfPulledEventExistsAndAddOrUpdate($event, &$successes, &$fails, $eventModel, $server, $user, $passAlong, $job, $jobId)
|
||||
private function __checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, &$successes, &$fails, $eventModel, $server, $user, $jobId)
|
||||
{
|
||||
// check if the event already exist (using the uuid)
|
||||
$existingEvent = null;
|
||||
$existingEvent = $eventModel->find('first', array('conditions' => array('Event.uuid' => $event['Event']['uuid'])));
|
||||
if (!$existingEvent) {
|
||||
// add data for newly imported events
|
||||
|
@ -1898,7 +1895,7 @@ class Server extends AppModel
|
|||
}
|
||||
}
|
||||
|
||||
private function __pullEvents($eventId, $successes, $fails, $eventModel, $server, $user, $passAlong, $job, $jobId)
|
||||
private function __pullEvent($eventId, &$successes, &$fails, $eventModel, $server, $user, $jobId)
|
||||
{
|
||||
$event = $eventModel->downloadEventFromServer(
|
||||
$eventId,
|
||||
|
@ -1909,7 +1906,7 @@ class Server extends AppModel
|
|||
return false;
|
||||
}
|
||||
$this->__updatePulledEventBeforeInsert($event, $server, $user);
|
||||
$this->__checkIfPulledEventExistsAndAddOrUpdate($event, $successes, $fails, $eventModel, $server, $user, $passAlong, $job, $jobId);
|
||||
$this->__checkIfPulledEventExistsAndAddOrUpdate($event, $eventId, $successes, $fails, $eventModel, $server, $user, $jobId);
|
||||
} else {
|
||||
// error
|
||||
$fails[$eventId] = 'failed downloading the event';
|
||||
|
@ -1917,7 +1914,7 @@ class Server extends AppModel
|
|||
return true;
|
||||
}
|
||||
|
||||
private function __handlePulledProposals($proposals, $events, $job, $jobId)
|
||||
private function __handlePulledProposals($proposals, $events, $job, $jobId, $eventModel, $user)
|
||||
{
|
||||
$pulledProposals = array();
|
||||
if (!empty($proposals)) {
|
||||
|
@ -1965,7 +1962,7 @@ class Server extends AppModel
|
|||
if ($jobId) {
|
||||
if ($k % 50 == 0) {
|
||||
$job->id = $jobId;
|
||||
$job->saveField('progress', 50 * (($k + 1) / count($proposals)));
|
||||
$job->saveField('progress', 50 * (($k + 1) / count($proposals)) + 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1973,7 +1970,7 @@ class Server extends AppModel
|
|||
return $pulledProposals;
|
||||
}
|
||||
|
||||
public function pull($user, $id = null, $technique=false, $server, $jobId = false, $percent = 100, $current = 0)
|
||||
public function pull($user, $id = null, $technique=false, $server, $jobId = false)
|
||||
{
|
||||
if ($jobId) {
|
||||
$job = ClassRegistry::init('Job');
|
||||
|
@ -1984,9 +1981,9 @@ class Server extends AppModel
|
|||
$email = $user['email'];
|
||||
}
|
||||
$eventModel = ClassRegistry::init('Event');
|
||||
App::uses('HttpSocket', 'Network/Http');
|
||||
$eventIds = array();
|
||||
$conditions = array();
|
||||
// if we are downloading a single event, don't fetch all proposals
|
||||
$conditions = is_numeric($technique) ? array('Event.id' => $technique) : array();
|
||||
$eventIds = $this->__getEventIdListBasedOnPullTechnique($technique, $server);
|
||||
if (!empty($eventIds['error'])) {
|
||||
$errors = array(
|
||||
|
@ -2014,9 +2011,8 @@ class Server extends AppModel
|
|||
// now process the $eventIds to pull each of the events sequentially
|
||||
if (!empty($eventIds)) {
|
||||
// download each event
|
||||
$HttpSocket = $this->setupHttpSocket($server);
|
||||
foreach ($eventIds as $k => $eventId) {
|
||||
$this->__pullEvents($eventId, $successes, $fails, $eventModel, $server, $user, $passAlong, $job, $jobId);
|
||||
$this->__pullEvent($eventId, $successes, $fails, $eventModel, $server, $user, $jobId);
|
||||
if ($jobId) {
|
||||
if ($k % 10 == 0) {
|
||||
$job->saveField('progress', 50 * (($k + 1) / count($eventIds)));
|
||||
|
@ -2034,7 +2030,7 @@ class Server extends AppModel
|
|||
));
|
||||
if (!empty($events)) {
|
||||
$proposals = $eventModel->downloadProposalsFromServer($events, $server);
|
||||
$pulledProposals = $this->__handlePulledProposals($proposals, $events, $job, $jobId);
|
||||
$pulledProposals = $this->__handlePulledProposals($proposals, $events, $job, $jobId, $eventModel, $user);
|
||||
}
|
||||
if ($jobId) {
|
||||
$job->saveField('progress', 100);
|
||||
|
|
Loading…
Reference in New Issue