in my scenario, i have 3 Site : Shop / Admin / PublicAdmin.
Each site shares the same database.
because my PublicAdmin is a live sample, i've protected some datas.
each table had received a new row 'protected' (0 by default, 1 for protected data)
In my PublicAdmin, i've changed the sql query.
example for Customers Application :
.
\osCommerce\OM\Core\Site\PublicAdmin\Application\Customers\SQL\ANSI\Delete.php : (class deleted)
<?php
class Delete {
public static function execute($data) {
$OSCOM_PDO = Registry::get('PDO');
$Qdelete = $OSCOM_PDO->prepare('delete from :table_customers where customers_id = :customers_id');
$Qdelete->bindInt(':customers_id', $data['id']);
$Qdelete->execute();
return ( $Qdelete->rowCount() === 1 );
}
}
?>
became :
\osCommerce\OM\Core\Site\PublicAdmin\Application\Customers\SQL\MySQL\Standard\Delete.php :
<?php
class Delete {
public static function execute($data) {
$OSCOM_PDO = Registry::get('PDO');
$Qdelete = $OSCOM_PDO->prepare('CALL DeleteCustomer(:customers_id)');
$Qdelete->bindInt(':customers_id', $data['id']);
$Qdelete->execute();
return ( $Qdelete->rowCount() === 1 );
}
}
?>
the stored procedure inserted in database :
DROP PROCEDURE `DeleteCustomer`;
DELIMITER ;;
CREATE PROCEDURE `DeleteCustomer` (IN `custid` int)
BEGIN
DECLARE msg VARCHAR(255);
IF (SELECT protected FROM osc_customers WHERE customers_id = custid AND protected = 1) THEN
set msg = CONCAT("This action is forbidden for the customer with the ID " , custid);
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = msg;
ELSE
DELETE FROM osc_customers WHERE customers_id = custid;
END IF;
END;;
DELIMITER ;
For now, i catch the message (returning by the stored proc) with this code in :
\osCommerce\OM\Core\PDOStatement.php :
..../...
if ( $this->_is_error === true ) {
Registry::get('MessageStack')->add(null, self::_getErrorMessage() , 'error');
}
.../...
private function _getErrorMessage() {
$error_array = array();
$error_array = $this->errorInfo();
return end($error_array);
}
i've excluded error no & sqlstate
so, if a user in PublicAdmin deletes a protected customer, MessageStack displays :
Quote
This action is forbidden for the customer with the ID x
Error: There was a problem performing the action.
Error: There was a problem performing the action.
my code works.
but i wonder if it is better to introduce a new exception class for pdo, and if yes, how to integrate with the existant errorlog module ?
i work with mysql 5.5
developpers, what do you think about it ?
Regards
Edited by foxp2, 29 March 2012 - 12:56 PM.









