示例#1
0
 /**
  * @param User $user
  * @param Invitation $invitation
  * @return void
  * @throws Runtime\DuplicateUsernameException
  * @throws Runtime\DuplicateEmailException
  * @throws Runtime\InvitationNotFoundException
  * @throws Runtime\InvitationExpiredException
  * @throws Runtime\InvitationTokenMatchException
  * @throws \DibiException
  */
 public function registerNewUser(User $user, Invitation $invitation)
 {
     if (!$user->isDetached()) {
         throw new InvalidArgumentException('Only detached instances of Entity ' . User::class . ' can pass.');
     }
     $this->checkInvitation($user->email, $invitation->token);
     try {
         $this->transaction->begin();
         $this->userRepository->persist($user);
         $this->removeInvitation($invitation);
         $this->transaction->commit();
     } catch (\DibiException $e) {
         if ($e->getCode() == 1062) {
             try {
                 $this->userRepository->checkUsername($user->username);
             } catch (Runtime\UserAlreadyExistsException $usernameException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateUsernameException();
             }
             try {
                 $this->userRepository->checkEmail($user->email);
             } catch (Runtime\UserAlreadyExistsException $emailException) {
                 $this->transaction->rollback();
                 throw new Runtime\DuplicateEmailException();
             }
         }
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
 /**
  * Override BundlableLabelableBaseModelWithAttributes::changeType() to update
  * current location "subclass" (ie. type) value when type change is used.
  * This should be invoked by any model that can be used to indicate object
  * storage location. This includes, for now at least, ca_loans, ca_movements, 
  * ca_occurrences and ca_objects_x_storage_locations.
  *
  * @param mixed $pm_type The type_id or code to change the current type to
  * @return bool True if change succeeded, false if error
  */
 public function changeType($pm_type)
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     // row must be loaded
     if (!($vb_already_in_transaction = $this->inTransaction())) {
         $this->setTransaction($o_t = new Transaction($this->getDb()));
     }
     if ($vn_rc = parent::changeType($pm_type)) {
         $o_db = $this->getDb();
         $o_db->query("\n\t\t\t\t\tUPDATE ca_objects SET current_loc_subclass = ? \n\t\t\t\t\tWHERE \n\t\t\t\t\t\tcurrent_loc_class = ? AND current_loc_id = ?\n\t\t\t\t", array($this->get('type_id'), $this->tableNum(), $this->getPrimaryKey()));
         if ($o_db->numErrors()) {
             $this->errors = $o_db->errors;
             if (!$vb_already_in_transaction) {
                 $o_t->rollback();
             }
             return false;
         }
     }
     if (!$vb_already_in_transaction) {
         $o_t->commit();
     }
     return $vn_rc;
 }
示例#3
0
 /**
  * @param ListingItem $listingItem
  * @return ListingItem
  * @throws ListingItemDayAlreadyExistsException
  * @throws \DibiException
  */
 public function saveListingItem(ListingItem $listingItem)
 {
     try {
         $this->transaction->begin();
         $this->listingItemRepository->persist($listingItem);
         $this->localityRepository->saveLocalityToUserList($listingItem->locality, $listingItem->listing->getRowData()['userID']);
         $this->transaction->commit();
         return $listingItem;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         if ($e->getCode() == 1062) {
             throw new ListingItemDayAlreadyExistsException();
         }
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
示例#4
0
function deleteWidget($id)
{
    try {
        $transaction = new Transaction();
        $result = DAOFactory::getAfiliadoWidgetDAO()->delete($id);
        $transaction->commit();
        return $result;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
 public function rollback($auth = NULL)
 {
     if ($auth != Transaction::SIGNATURE) {
         return Transaction::rollback();
     }
     if (!$this->txn) {
         return FALSE;
     }
     if ($this->lock) {
         return TRUE;
     }
     $rs = (bool) $this->__call(__FUNCTION__, array());
     $this->lock = TRUE;
     return $rs;
 }
示例#6
0
function deleteFaq($id)
{
    try {
        $transaction = new Transaction();
        $faq = DAOFactory::getFaqDAO()->load($id);
        DAOFactory::getFaqDAO()->delete($id);
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#7
0
function insertBusquedaDisponibilidad($data)
{
    try {
        $transaction = new Transaction();
        $busqueda = DAOFactory::getBusquedaDisponibilidadDAO()->prepare($data);
        $id = DAOFactory::getBusquedaDisponibilidadDAO()->insert($busqueda);
        $transaction->commit();
        return $id;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#8
0
 /**
  * @param array $messages Key => recipientID, Value = Message entity or array of messages
  * @throws InvalidArgumentException
  * @throws \DibiException
  * @return array
  */
 public function sendMessages(array $messages)
 {
     $ex = new InvalidArgumentException('Only non-persisted instances of ' . Message::class . ' can pas.');
     $msgs = [];
     foreach ($messages as $recipientID => $recipientMessages) {
         Validators::assert($recipientID, 'numericint');
         if (is_array($recipientMessages)) {
             foreach ($recipientMessages as $message) {
                 if (!($message instanceof Message and $message->isDetached())) {
                     throw $ex;
                 }
                 $msgs[] = $message;
             }
         } else {
             // recipientMessages contains only one message
             if (!($recipientMessages instanceof Message and $recipientMessages->isDetached())) {
                 throw $ex;
             }
             $msgs[] = $recipientMessages;
         }
     }
     try {
         $this->transaction->begin();
         $this->messageRepository->saveMessages($msgs);
         unset($msgs);
         $usersMessages = [];
         foreach ($messages as $recipientID => $recipientMessages) {
             if (is_array($recipientMessages)) {
                 foreach ($recipientMessages as $message) {
                     $recipientMessage = new UserMessage($message, $recipientID);
                     $usersMessages[] = $recipientMessage;
                 }
             } else {
                 $recipientMessage = new UserMessage($recipientMessages, $recipientID);
                 $usersMessages[] = $recipientMessage;
             }
         }
         $this->userMessageRepository->sendMessagesToRecipients($usersMessages);
         $this->transaction->commit();
         return $usersMessages;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
示例#9
0
 public function action_update(Params $param)
 {
     $this->content->bind('form', $torn);
     $project = Jelly::select('project')->link($param->id)->load();
     if (!$project->loaded()) {
         throw new Error404_Exception();
     }
     $torn = new Torn($project);
     if ($torn->check()) {
         try {
             Transaction::begin();
             $project->set($_FILES + $_POST);
             $project->save();
             Transaction::commit();
             $this->request->redirect(Route::get('protected')->uri(array('controller' => 'project')));
         } catch (Validate_Exception $e) {
             Transaction::rollback();
             $torn->catch_errors($e);
         }
     }
 }
示例#10
0
function updateFactura($id, $data = array(), $trasactional = true)
{
    try {
        if ($trasactional) {
            $transaction = new Transaction();
        }
        $factura = getFactura($id);
        $factura = DAOFactory::getFacturaDAO()->prepare($data, $id);
        DAOFactory::getFacturaDAO()->update($factura);
        if ($trasactional) {
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#11
0
function updateCart($idCart, $data = array())
{
    try {
        $transaction = new Transaction();
        if (isset($data['apartamento'])) {
            $data['apartamento'] = json_encode($data['apartamento']);
        }
        if (isset($data['excursiones'])) {
            $data['excursiones'] = json_encode($data['excursiones']);
        }
        //print_r($data);
        $cart = DAOFactory::getShoppingCartDAO()->prepare($data, $idCart);
        DAOFactory::getShoppingCartDAO()->update($cart);
        $transaction->commit();
        return $idCart;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#12
0
function updateDireccionByHotelId($idHotel, $data = array())
{
    try {
        $transaction = new Transaction();
        $hotel = getHotelById($idHotel);
        if ($hotel->direccion) {
            updateDireccion($hotel->direccion->id, $data);
        } else {
            $dir = DAOFactory::getDireccionDAO()->prepare($data);
            $dir_id = DAOFactory::getDireccionDAO()->insert($dir);
            $hd = DAOFactory::getHotelDireccionDAO()->prepare(array('hotelId' => $hotel->id, 'direccionId' => $dir_id));
            DAOFactory::getHotelDireccionDAO()->insert($hd);
        }
        $transaction->commit();
        return $idDireccion;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#13
0
 /**
  * @param Listing $baseListing
  * @param Listing $listingToMerge
  * @param array $selectedCollisionItems
  * @param \App\Model\Entities\User|int|null $user
  * @return Listing
  * @throws NoCollisionListingItemSelectedException
  * @throws \DibiException
  */
 public function mergeListings(Listing $baseListing, Listing $listingToMerge, array $selectedCollisionItems = [], $user = null)
 {
     $this->checkListingValidity($baseListing);
     $this->checkListingValidity($listingToMerge);
     if (!$this->haveListingsSamePeriod($baseListing, $listingToMerge)) {
         throw new InvalidArgumentException('Given Listings must have same Period(Year and Month).');
     }
     $userID = $this->getIdOfSignedInUserOnNull($user);
     $items = $this->itemService->getMergedListOfItems($baseListing, $listingToMerge, $selectedCollisionItems);
     try {
         $this->transaction->begin();
         $newListing = new Listing($baseListing->year, $baseListing->month, $userID);
         $this->saveListing($newListing);
         $this->itemService->setListingForGivenItems($items, $newListing);
         $this->listingItemRepository->saveListingItems($items);
         $this->transaction->commit();
         return $newListing;
     } catch (\DibiException $e) {
         $this->transaction->rollback();
         Debugger::log($e, Debugger::ERROR);
         throw $e;
     }
 }
示例#14
0
function updatePromocionPalabrasClave($id, $data = array(), $data_hoteles = array())
{
    try {
        $transaction = new Transaction();
        $promocion = DAOFactory::getPromocionPalabrasClavesDAO()->prepare($data, $id);
        DAOFactory::getPromocionPalabrasClavesDAO()->update($promocion);
        DAOFactory::getPromocionPalabrasClavesHotelDAO()->deleteByPromocionId($id);
        if ($data_hoteles && is_array($data_hoteles) && count($data_hoteles)) {
            foreach ($data_hoteles as $hid) {
                $hotel_promo = DAOFactory::getPromocionPalabrasClavesHotelDAO()->prepare(array('promocionId' => $id, 'hotelId' => $hid));
                DAOFactory::getPromocionPalabrasClavesHotelDAO()->insert($hotel_promo);
            }
        }
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        error_log($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#15
0
function updateDominioCampania($idCampania, $dominio)
{
    try {
        $transaction = new Transaction();
        $data = array('subdominio' => $dominio);
        $campania = DAOFactory::getCampaniaDAO()->prepare($data, $idCampania);
        DAOFactory::getCampaniaDAO()->update($campania);
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
 /**
  * Change type of record, removing any metadata that is invalid for the new type
  *
  * @param mixed $pm_type The type_id or code to change the current type to
  * @return bool True if change succeeded, false if error
  */
 public function changeType($pm_type)
 {
     if (!$this->getPrimaryKey()) {
         return false;
     }
     // row must be loaded
     if (!method_exists($this, 'getTypeID')) {
         return false;
     }
     // model must be type-able
     unset($_REQUEST['form_timestamp']);
     if (!($vb_already_in_transaction = $this->inTransaction())) {
         $this->setTransaction($o_t = new Transaction($this->getDb()));
     }
     $vn_old_type_id = $this->getTypeID();
     $this->setMode(ACCESS_WRITE);
     $this->set($this->getTypeFieldName(), $pm_type, array('allowSettingOfTypeID' => true));
     // remove attributes that are not valid for new type
     $va_old_elements = $this->getApplicableElementCodes($vn_old_type_id);
     $va_new_elements = $this->getApplicableElementCodes($this->getTypeID());
     foreach ($va_old_elements as $vn_old_element_id => $vs_old_element_code) {
         if (!isset($va_new_elements[$vn_old_element_id])) {
             $this->removeAttributes($vn_old_element_id, array('force' => true));
         }
     }
     if ($this->update()) {
         if (!$vb_already_in_transaction) {
             $o_t->commit();
         }
         return true;
     }
     if (!$vb_already_in_transaction) {
         $o_t->rollback();
     }
     return false;
 }
<?php

require_once 'classes/ar/ProdutoComTransacao.php';
require_once 'classes/api/Connection.php';
require_once 'classes/api/Transaction.php';
try {
    Transaction::open('estoque');
    $p1 = new Produto();
    $p1->descricao = 'Chocolate amargo';
    $p1->estoque = 80;
    $p1->preco_custo = 4;
    $p1->preco_venda = 7;
    $p1->codigo_barras = '68323453234234';
    $p1->data_cadastro = date('Y-m-d');
    $p1->origem = 'N';
    $p1->save();
    Transaction::close();
} catch (Exception $e) {
    Transaction::rollback();
    print $e->getMessage();
}
示例#18
0
function validarReservas($reservas, $importes)
{
    try {
        $transaction = new Transaction();
        foreach ($importes as $rid => $imp) {
            $status = in_array($rid, $reservas) ? 'Stayed' : 'No show';
            $reserva = DAOFactory::getReservaDAO()->prepare(array('estado' => $status), $rid);
            DAOFactory::getReservaDAO()->update($reserva);
            //estado actualizado
            $moneda = getMoneda($reserva->monedaId);
            $productos = DAOFactory::getReservaProductoDAO()->queryByReservaId($rid);
            foreach ($productos as $p) {
                if ($p->tipo == 'apartamento') {
                    $precio = $imp;
                    if ($moneda->codigo != 'EUR') {
                        $precio = convertFromMonedaToMoneda($imp, 'EUR', $moneda->codigo);
                    }
                    $producto = DAOFactory::getReservaProductoDAO()->prepare(array('precioUnitario' => $precio), $p->id);
                    DAOFactory::getReservaProductoDAO()->update($producto);
                    break;
                }
            }
        }
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#19
0
function deleteCondicion($id, $transactional = true)
{
    try {
        if ($transactional) {
            $transaction = new Transaction();
        }
        DAOFactory::getHotelCondicionDAO()->deleteByCondicionId($id);
        DAOFactory::getCondicionDAO()->delete($id);
        if ($transactional) {
            $transaction->commit();
        }
        return $id;
    } catch (Exception $e) {
        var_dump($e);
        if ($transactional && $transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
 /**
  * Applies specified update to system
  *
  * @param int $pn_version Version number of update to apply
  * @param array $pa_options Array of options. Supported options are:
  *		cleanCache = Remove all application caches after database update if true. Default is false.
  * @return bool
  */
 static function performDatabaseUpdate($pn_version, $pa_options = null)
 {
     if (($pn_version = (int) $pn_version) <= 0) {
         return null;
     }
     $va_messages = array();
     $t = new Transaction();
     $o_db = $t->getDb();
     if (!file_exists(__CA_BASE_DIR__ . "/support/sql/migrations/{$pn_version}.sql")) {
         return null;
     }
     $o_handle = fopen(__CA_BASE_DIR__ . "/support/sql/migrations/{$pn_version}.sql", "r");
     $vn_query_total_nb = 0;
     $vs_query = '';
     while (!feof($o_handle)) {
         $vs_line = fgets($o_handle, 8128);
         // $vs_query gets a concat of lines while a ; is not met
         $vs_query .= $vs_line;
         // Reading 1 character before the EOL
         $vs_before_eol = substr(rtrim($vs_line), -1);
         if ($vs_before_eol == ';') {
             //If the line ends with a ; then we will take all what's before and execute it
             //Counts the number of requests contained in the SQL file
             $vn_query_total_nb++;
             //Launching the query
             $o_db->query($vs_query);
             if ($o_db->numErrors() > 0) {
                 // temp array to catch the errors
                 $va_error_array_for_printing = $o_db->getErrors();
                 $va_messages['error_' . $pn_version] = _t("Error applying database migration %1: %2; error was at query %3; query was %4", $pn_version, join('; ', $va_error_array_for_printing), $vn_query_total_nb, $vs_query);
                 $o_db->clearErrors();
                 $t->rollback();
                 return $va_messages;
             }
             // Reset variable
             $vs_query = '';
         }
         $t->commit();
     }
     if (isset($pa_options['cleanCache']) && $pa_options['cleanCache']) {
         // Clean cache
         caRemoveDirectory(__CA_APP_DIR__ . '/tmp', false);
     }
     return $va_messages;
 }
                    $activity->setCategory(Factory::getView(new CategoryKey(trim($data['category']))));
                }
                $transaction->commit();
                break;
        }
        echo json_encode(array('success' => 'true'));
    } else {
        $smarty = new MySmarty($SMARTY_CONFIG);
        $smarty->assign('res', $user->getActivities());
        $userCategories = Category::getOptions(array("USER_ID" => $user->getId(), "ACTIVE" => 1));
        $allCategories = Category::getOptions(array("ACTIVE" => 1));
        $categories = '';
        foreach ($userCategories as $index => $value) {
            $categories .= "{\"value\": \"{$index}\", \"label\": \"{$value}\"},";
        }
        $smarty->assign('allCategories', $categories);
        $smarty->assign('user', $user);
        $smarty->assign('left_menu', true);
        //$smarty->assign('BASE_URL', $BASE_URL);
        $smarty->display('transactions.tpl');
    }
} catch (AccessDeniedException $e) {
    header('HTTP/1.1 401 Access Denied');
    echo "AccessDeniedException: " . $e->getMessage();
} catch (Exception $e) {
    if ($transaction && !$transaction->isComplete()) {
        $transaction->rollback();
    }
    header('HTTP/1.1 500 Internal Server Error');
    echo "Exception: " . $e->getMessage();
}
示例#22
0
function deleteAfiliado($idAfiliado)
{
    try {
        $transaction = new Transaction();
        DAOFactory::getAfiliadoHotelDAO()->deleteByAfiliadoId($idAfiliado);
        DAOFactory::getAfiliadoEventoDAO()->deleteByAfiliadoId($idAfiliado);
        $afiliado = DAOFactory::getAfiliadoDAO()->load($idAfiliado);
        $cuenta = array_pop(DAOFactory::getUsuarioCuentaDAO()->queryByUsuarioId($afiliado->usuarioId));
        if ($cuenta) {
            DAOFactory::getUsuarioCuentaDAO()->deleteByUsuarioId($afiliado->usuarioId);
            DAOFactory::getDireccionDAO()->delete($cuenta->direccionId);
        }
        DAOFactory::getAfiliadoDAO()->delete($idAfiliado);
        $result = DAOFactory::getUsuarioDAO()->delete($afiliado->usuarioId);
        $transaction->commit();
        return $result;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#23
0
function deleteTicketsByEvento($eventoId, $transactional = true)
{
    try {
        if ($transactional) {
            $transaction = new Transaction();
        }
        $tickets = DAOFactory::getTicketDAO()->queryByEventoId($eventoId);
        if ($tickets && is_array($tickets)) {
            foreach ($tickets as $ticket) {
                DAOFactory::getTicketFechaDAO()->deleteByTicketId($ticket->id);
            }
        }
        DAOFactory::getTicketDAO()->deleteByEventoId($eventoId);
        if ($transactional) {
            $transaction->commit();
        }
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#24
0
function updateAdwordHotel($idAdword, $idHotel)
{
    try {
        $transaction = new Transaction();
        $adwords = DAOFactory::getAdwordDAO()->queryByHotelId($idHotel);
        if ($adwords) {
            foreach ($adwords as $adword) {
                $adword->hotelId = NULL;
                DAOFactory::getAdwordDAO()->update($adword);
            }
        }
        if (strlen(trim($idAdword))) {
            $adword = DAOFactory::getAdwordDAO()->load($idAdword);
            $adword->hotelId = $idHotel;
            DAOFactory::getAdwordDAO()->update($adword);
        }
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#25
0
 public function delete()
 {
     $tx = new Transaction();
     try {
         $this->title->delete();
         $this->text->delete();
         $this->excerpt->delete();
         foreach ($this->get_comments() as $comment) {
             $comment->delete();
         }
         qdb("DELETE FROM `PREFIX_article_tag_relations` WHERE `article` = ?", $this->id);
         qdb("DELETE FROM `PREFIX_article_extradata` WHERE `article` = ?", $this->id);
         qdb("DELETE FROM `PREFIX_articles` WHERE `id` = ?", $this->id);
         $tx->commit();
     } catch (Exception $e) {
         $tx->rollback();
         throw $e;
     }
 }
示例#26
0
function deleteEmpresa($idEmpresa, $transactional = true)
{
    try {
        if ($transactional) {
            $transaction = new Transaction();
        }
        $empresa = DAOFactory::getEmpresaDAO()->load($idEmpresa);
        $hoteles = DAOFactory::getHotelDAO()->queryByEmpresaId($idEmpresa);
        if ($hoteles) {
            foreach ($hoteles as $hotel) {
                $el = deleteHotel($hotel->id, false);
                if (!$el) {
                    throw new Exception('No se pudo eliminar el hotel');
                }
            }
        }
        $campanias = DAOFactory::getCampaniaDAO()->queryByEmpresaId($idEmpresa);
        if ($campanias && count($campanias)) {
            foreach ($campanias as $c) {
                $d = eliminarCampania($c->id, false);
                if (!$d) {
                    throw new Exception('No se pudo borrar la campaña ' . $c->id);
                }
            }
        }
        $campanias = DAOFactory::getCampaniaDAO()->queryByEmpresaDistribuidoraId($idEmpresa);
        if ($campanias && count($campanias)) {
            foreach ($campanias as $c) {
                $d = eliminarCampania($c->id, false);
                if (!$d) {
                    throw new Exception('No se pudo borrar la campaña ' . $c->id);
                }
            }
        }
        DAOFactory::getUsuarioEmpresaDAO()->deleteByEmpresaId($idEmpresa);
        DAOFactory::getEmpresaDAO()->delete($idEmpresa);
        DAOFactory::getDireccionDAO()->delete($empresa->direccionId);
        if ($transactional) {
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#27
0
function actualizarCambioMoneda()
{
    try {
        set_time_limit(0);
        $moneda = getMonedaByCodigo('USD');
        $hoy = strtotime(date('Y-m-d'));
        $lastUpdate = strtotime(date('Y-m-d', $moneda->ultimaModificacion ? strtotime($moneda->ultimaModificacion) : 0));
        if ($hoy > $lastUpdate) {
            $monedas = getAllMonedas();
            $transaction = new Transaction();
            $change_url = 'https://www.google.com/finance/converter';
            $cant = 1;
            $from = 'EUR';
            foreach ($monedas as $moneda) {
                $content = file_get_contents($change_url . '?a=' . $cant . '&from=' . $from . '&to=' . $moneda->codigo);
                $dom = new DOMDocument();
                @$dom->loadHTML($content);
                $x = new DOMXPath($dom);
                foreach ($x->query('//span[@class="bld"]') as $node) {
                    $rate = floatval(trim(str_replace($moneda->codigo, '', $node->nodeValue)));
                    $m = DAOFactory::getMonedaDAO()->prepare(array('tasaCambio' => $rate, 'ultimaModificacion' => date('Y-m-d')), $moneda->id);
                    DAOFactory::getMonedaDAO()->update($m);
                }
            }
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        print_r($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#28
0
function completarCampania($idUsuario, $data_hotel, $data_empresa, $data_direccion, $idiomas, $monedas, $promociones)
{
    try {
        $transaction = new Transaction();
        $empresas = getEmpresasByUsuario($idUsuario);
        $empresa = $empresas[0];
        $emp = updateEmpresa($empresa->id, $data_empresa, $data_direccion, false);
        if (!$emp) {
            throw new Exception('No se guardaron los datos de la empresa');
        }
        $hoteles = getHotelesByUsuario($idUsuario);
        $idHotel = $hoteles[0]->id;
        $hotel = DAOFactory::getHotelDAO()->prepare($data_hotel, $idHotel);
        DAOFactory::getHotelDAO()->update($hotel);
        getClaveByHotel($idHotel);
        DAOFactory::getHotelIdiomaDAO()->deleteByHotelId($idHotel);
        if (count($idiomas)) {
            foreach ($idiomas as $idioma) {
                $id = DAOFactory::getHotelIdiomaDAO()->prepare(array('hotelId' => $idHotel, 'idiomaId' => $idioma));
                DAOFactory::getHotelIdiomaDAO()->insert($id);
            }
        }
        DAOFactory::getHotelMonedaDAO()->deleteByHotelId($idHotel);
        if (count($monedas)) {
            foreach ($monedas as $moneda) {
                $mon = DAOFactory::getHotelMonedaDAO()->prepare(array('hotelId' => $idHotel, 'monedaId' => $moneda));
                DAOFactory::getHotelMonedaDAO()->insert($mon);
            }
        }
        DAOFactory::getPromocionDAO()->deleteByHotelId($idHotel);
        foreach ($promociones as $data_promocion) {
            $data_promocion['hotelId'] = $idHotel;
            $promocion = DAOFactory::getPromocionDAO()->prepare($data_promocion);
            DAOFactory::getPromocionDAO()->insert($promocion);
        }
        $usuario = DAOFactory::getUsuarioDAO()->prepare(array('status' => 'activo'), $idUsuario);
        DAOFactory::getUsuarioDAO()->update($usuario);
        $transaction->commit();
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}
示例#29
0
 /**
  * Roll back a transaction without throwing errors if they occur.
  * 
  * @param Connection $con The Connection for the transaction.
  * @return void
  */
 public static function safeRollback($con) 
 {
     try {
         Transaction::rollback($con);
     } catch (PropelException $e) {
         Propel::log("An error occured during rollback: " . $e->getMessage(), Propel::LOG_ERR);
     }
 }
示例#30
0
function actualizarSEO($id = 0)
{
    try {
        if ($id) {
            $hotel = DAOFactory::getHotelDAO()->load($id);
            $hotel->descripciones = json_decode($hotel->descripcionLarga);
            $tituloSeo = $hotel->nombre;
            if ($hotel->destinoId) {
                $destino = DAOFactory::getDestinoTuristicoDAO()->load($hotel->destinoId);
                $tituloSeo .= ' | ' . $destino->nombre;
            }
            $descripcionesSeo = array();
            $keywordsSeo = array();
            foreach (get_object_vars($hotel->descripciones) as $k => $value) {
                $endD = strlen($value) > 150 ? '...' : '';
                $descripcionesSeo[$k] = strip_tags(substr($value, 0, 150)) . $endD;
                $keywordsSeo[$k] = $tituloSeo . ' ' . str_replace('...', '', $descripcionesSeo[$k]);
            }
            $hotel->tituloSeo = json_encode(array('es' => $tituloSeo));
            $hotel->descripcionCorta = json_encode($descripcionesSeo);
            $hotel->keywordsSeo = json_encode($keywordsSeo);
            DAOFactory::getHotelDAO()->update($hotel);
        } else {
            $transaction = new Transaction();
            $hoteles = DAOFactory::getHotelDAO()->queryAll();
            foreach ($hoteles as $hotel) {
                actualizarSeo($hotel->id);
            }
            $transaction->commit();
        }
        return true;
    } catch (Exception $e) {
        var_dump($e);
        if ($transaction) {
            $transaction->rollback();
        }
        return false;
    }
}