2 commits - lib/api lib/kolab_api_service.php lib/SQL.php
Aleksander Machniak
machniak at kolabsys.com
Mon Sep 24 14:33:01 CEST 2012
lib/SQL.php | 5 ++++
lib/api/kolab_api_service_type.php | 18 +++++++--------
lib/kolab_api_service.php | 44 +++++++++++++++++--------------------
3 files changed, 35 insertions(+), 32 deletions(-)
New commits:
commit 778844077ffadd242a431411554d0e3ac137a717
Author: Aleksander Machniak <alec at alec.pl>
Date: Mon Sep 24 14:32:43 2012 +0200
Implemented type.delete
diff --git a/lib/api/kolab_api_service_type.php b/lib/api/kolab_api_service_type.php
index 54d1464..4b71080 100644
--- a/lib/api/kolab_api_service_type.php
+++ b/lib/api/kolab_api_service_type.php
@@ -91,20 +91,20 @@ class kolab_api_service_type extends kolab_api_service
*/
public function type_delete($getdata, $postdata)
{
- //console("type_delete()", $getdata, $postdata);
- if (!isset($postdata['type'])) {
+ if (empty($postdata['type']) || empty($postdata['id'])) {
return false;
}
- // TODO: Input validation
-// $auth = Auth::get_instance();
-// $result = $auth->type_delete($postdata['type']);
-
- if ($result) {
- return $result;
+ if (!in_array($postdata['type'], $this->supported_types_db)) {
+ return false;
}
- return false;
+ $object_name = $postdata['type'];
+ $object_id = $postdata['id'];
+
+ $this->db->query("DELETE FROM {$object_name}_types WHERE id = ?", array($object_id));
+
+ return (bool) $this->db->affected_rows();
}
/**
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 3fcefda..c45f811 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -32,6 +32,8 @@ abstract class kolab_api_service
protected $conf;
protected $controller;
protected $db;
+ protected $supported_types_db = array('group', 'resource', 'role', 'user');
+ protected $supported_types = array('domain', 'group', 'resource', 'role', 'user');
/**
* Class constructor.
@@ -40,10 +42,10 @@ abstract class kolab_api_service
*/
public function __construct($ctrl)
{
- $this->conf = Conf::get_instance();
$this->controller = $ctrl;
+ $this->conf = Conf::get_instance();
$this->db = SQL::get_instance();
- }
+ }
/**
* Advertise this service's capabilities
@@ -61,8 +63,7 @@ abstract class kolab_api_service
*/
protected function object_type_attributes($object_name, $type_id, $required = true)
{
- $supported = array('domain', 'group', 'resource', 'role', 'user');
- if (!$object_name || !in_array($object_name, $supported)) {
+ if (!$object_name || !in_array($object_name, $this->supported_types)) {
return array();
}
@@ -79,25 +80,23 @@ abstract class kolab_api_service
if (empty($object_types[$type_id])) {
if ($object_name == 'domain') {
$result = array(
- 'auto_form_fields' => array(),
- 'form_fields' => array(
- 'associateddomain' => array(
- 'type' => 'list'
- ),
- ),
- 'fields' => array(
- 'objectclass' => array(
- 'top',
- 'domainrelatedobject',
- ),
- ),
- );
-
- //console("object_type_attributes('domain', $type_id);", $result);
+ 'auto_form_fields' => array(),
+ 'form_fields' => array(
+ 'associateddomain' => array(
+ 'type' => 'list'
+ ),
+ ),
+ 'fields' => array(
+ 'objectclass' => array(
+ 'top',
+ 'domainrelatedobject',
+ ),
+ ),
+ );
return $result;
-
- } else {
+ }
+ else {
throw new Exception($this->controller->translate($object_name . '.invalidtypeid'), 35);
}
}
@@ -181,8 +180,7 @@ abstract class kolab_api_service
*/
protected function object_types($object_name)
{
- $supported = array('group', 'resource', 'role', 'user');
- if (!$object_name || !in_array($object_name, $supported)) {
+ if (!$object_name || !in_array($object_name, $this->supported_types_db)) {
return array();
}
commit bd71b0f69fbe15c789a3c48610f5c0d4e75878ad
Author: Aleksander Machniak <alec at alec.pl>
Date: Mon Sep 24 14:30:00 2012 +0200
Added affected_rows() method
diff --git a/lib/SQL.php b/lib/SQL.php
index b3d3823..d5b6737 100644
--- a/lib/SQL.php
+++ b/lib/SQL.php
@@ -98,6 +98,11 @@ class SQL
return mysql_fetch_assoc($result);
}
+ public function affected_rows()
+ {
+ return mysql_affected_rows($this->conn);
+ }
+
public function escape($str)
{
if ($str === null || is_array($str)) {
More information about the commits
mailing list