/**
  * @param \Pipe\Organization $org
  * @throws \Exception
  */
 public function saveToPipe(\Pipe\Organization $org)
 {
     $postData = array('name' => $org->getName(), 'owner_id' => Config::get('pipedrive')['org_owner_id'], 'visible_to' => $org::VISIBLE_TO_COMPANY);
     $this->log->write('Saving ' . print_r($postData, true) . 'to pipe drive');
     try {
         $responseData = (new PipeApi())->makeRequest($postData, 'organizations');
         $response = json_decode($responseData, true);
     } catch (\Exception $e) {
         $this->logAndForwardException($e);
     }
     $this->log->write('Response' . print_r($response, true));
     if ($response) {
         if (!$response['success']) {
             throw new \Exception($response['error']);
         } else {
             $org->setPipeId($response['data']['id']);
         }
     } else {
         throw new \Exception('No RESPONSE!');
     }
     //save daughters
     if (count($org->getDaughters())) {
         foreach ($org->getDaughters() as $daughter) {
             $this->saveToPipe($daughter);
         }
     }
 }
    public function saveToLocal(\Pipe\Organization $org)
    {
        if (count($org->getDaughters())) {
            foreach ($org->getDaughters() as $daughter) {
                $this->getDb()->query('
					INSERT INTO organizationRelation
					SET
						rel_owner_org_id = :rel_owner_org_id,
						rel_linked_org_id = :rel_linked_org_id,
						rel_type = :rel_type
				', array('rel_owner_org_id' => $org->getId(), 'rel_linked_org_id' => $daughter->getId(), 'rel_type' => \Pipe\OrganizationRelationship::TYPE_PARENT));
                $this->saveToLocal($daughter);
            }
        }
    }