Skip to content

Commit

Permalink
[E] Revert of old opensource-socialnetwork#1436 as its never used any…
Browse files Browse the repository at this point in the history
  • Loading branch information
lianglee committed Feb 2, 2024
1 parent 5808d51 commit 900030c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 73 deletions.
1 change: 0 additions & 1 deletion actions/administrator/user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

$user->first_name = $vars['firstname'];
$user->last_name = $vars['lastname'];
$user->old_email = $user->email;
$user->email = $vars['email'];
$user->new_type = $vars['type'];

Expand Down
92 changes: 52 additions & 40 deletions classes/OssnObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct($guid = 0) {
if(!empty($guid)) {
$object = ossn_get_object($guid);
if($object) {
foreach($object as $item => $val) {
foreach ($object as $item => $val) {
$this->{$item} = $val;
}
} else {
Expand Down Expand Up @@ -90,7 +90,7 @@ public function addObject() {
if($this->insert($params)) {
$this->createdObject = $this->getLastEntry();
if(isset($this->data) && is_object($this->data)) {
foreach($this->data as $name => $value) {
foreach ($this->data as $name => $value) {
$this->owner_guid = $this->createdObject;
$this->type = 'object';
$this->subtype = $name;
Expand All @@ -114,16 +114,27 @@ public function addObject() {

/**
* Get object by object guid;
* Requires $object->object_guid
*
* Requires : $object->object_guid
*
* @return object;
* @return object|boolean
*/
public function getObjectById(array $options = array()) {
public function getObjectById() {
self::initAttributes();
if(empty($this->object_guid)) {
return false;
}
//caching
$cache = new OssnDynamicCaching();
if($cache->isAvailableEnabled()) {
try {
$data = $cache->handler()->get("OssnObject->getObjectById():guid={$this->object_guid}");
return $data;
} catch (OssnDynamicCacheKeyNotExists $e) {
//key doesn't exists so we will just fetch and store at end
//because if found it return in first step otherwise below step is excuted in both cases
//catching it because we don't want to terminate process
}
}
$params['from'] = 'ossn_object as o';
$params['params'] = array(
'o.guid',
Expand All @@ -134,22 +145,11 @@ public function getObjectById(array $options = array()) {
'o.type',
'o.subtype',
);
//Allow to set searchObject result params #1436
if(isset($options['params']) && is_array($options['params']) && !empty($options['params'])) {
$params['params'] = $options['params'];
}
if(isset($options['unset_params']) && is_array($options['unset_params'])) {
foreach($options['unset_params'] as $item) {
if(($key = array_search($item, $params['params'])) !== false) {
unset($params['params'][$key]);
}
}
}

$params['wheres'] = array(
"o.guid='{$this->object_guid}'",
);
//there is no need to order as its will fetch only one record
//$params['order_by'] = $this->order_by;
unset($this->order_by);

$object = $this->select($params);
Expand All @@ -161,18 +161,26 @@ public function getObjectById(array $options = array()) {

if($entities) {
$fileds = array();
foreach($entities as $entity) {
foreach ($entities as $entity) {
$fields[$entity->subtype] = $entity->value;
}
$object_array = get_object_vars($object);
if(is_array($object_array)) {
$data = array_merge($object_array, $fields);
}
if(!empty($fields)) {
return arrayObject($data, get_class($this));
$result = arrayObject($data, get_class($this));
if($cache->isAvailableEnabled()) {
$cache->handler()->store("OssnObject->getObjectById():guid={$this->object_guid}", $result);
}
return $result;
}
}
return arrayObject($object, get_class($this));
$object = arrayObject($object, get_class($this));
if($cache->isAvailableEnabled()) {
$cache->handler()->store("OssnObject->getObjectById():guid={$this->object_guid}", $object);
}
return $object;
}
return false;
}
Expand Down Expand Up @@ -242,6 +250,12 @@ public function updateObject($name, $value, $guid) {
$this->subtype = $subtype_self;
}
}
//caching
//invalidate
$cache = new OssnDynamicCaching();
if($cache->isAvailableEnabled()) {
$cache->handler()->delete("OssnObject->getObjectById():guid={$guid}");
}
return true;
}
return false;
Expand Down Expand Up @@ -285,20 +299,18 @@ public function deleteObject($object = '') {
/**
* Search object by its title, description etc
*
* @param array $params A valid options in format:
* 'search_type' => true(default) to performs matching on a per-character basis
* false for performs matching on exact value.
* 'subtype' => Valid object subtype
* 'type' => Valid object type
* 'title' => Valid object title
* 'description' => Valid object description
* 'owner_guid' => A valid owner guid, which results integer value
* 'entities_pairs' => A entities pairs options, must be array
* 'count' => True if you wanted to count search items.
* 'limit' => Result limit default, Default is 10 values
* 'order_by'=> To show result in sepcific order. Default is Assending
* @param string $params['search_type'] true(default) to performs matching on a per-character basis false for performs matching on exact value.
* @param string $params['subtype'] Valid object subtype
* @param string $param['type'] Valid object type
* @param string $param['title'] Valid object title
* @param string $param['description'] Valid object description
* @param int $param['owner_guid'] A valid owner guid, which results integer value
* @param array $param['entities_pairs'] A entities pairs options, must be array
* @param boolean $param['count'] True if you wanted to count search items.
* @param init $param['limit'] Result limit default, Default is 10 values
* @param string $param['order_by'] To show result in sepcific order. Default is Assending
*
* reutrn array|false;
* @reutrn array|boolean
*
*/
public function searchObject(array $params = array()) {
Expand Down Expand Up @@ -390,7 +402,7 @@ public function searchObject(array $params = array()) {
}
}
if(isset($options['entities_pairs']) && is_array($options['entities_pairs'])) {
foreach($options['entities_pairs'] as $key => $pair) {
foreach ($options['entities_pairs'] as $key => $pair) {
$operand = empty($pair['operand']) ? '=' : $pair['operand'];
if(!empty($pair['name']) && isset($pair['value']) && !empty($operand)) {
if(!empty($pair['value'])) {
Expand All @@ -417,13 +429,13 @@ public function searchObject(array $params = array()) {
if(!is_array($options['wheres'])) {
$wheres[] = $options['wheres'];
} else {
foreach($options['wheres'] as $witem) {
foreach ($options['wheres'] as $witem) {
$wheres[] = $witem;
}
}
}
if(isset($options['joins']) && !empty($options['joins']) && is_array($options['joins'])) {
foreach($options['joins'] as $jitem) {
foreach ($options['joins'] as $jitem) {
$params['joins'][] = $jitem;
}
}
Expand Down Expand Up @@ -466,9 +478,9 @@ public function searchObject(array $params = array()) {
//load fetch query after count condition #1316
$this->get = $this->select($params, true);
if($this->get) {
foreach($this->get as $object) {
foreach ($this->get as $object) {
$this->object_guid = $object->guid;
$objects[] = $this->getObjectById($options);
$objects[] = $this->getObjectById();
}
return $objects;
}
Expand Down Expand Up @@ -507,4 +519,4 @@ public function save() {
}
return false;
}
}
}
35 changes: 3 additions & 32 deletions libraries/ossn.lib.objects.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,9 @@ function ossn_get_object($guid){
if(empty($guid)){
return false;
}
$getObject = function($guid){
if(!empty($guid)){
$object = new OssnObject;
$search = $object->searchObject(array(
'wheres'=> "o.guid='{$guid}'",
'offset' => 1
));
if($search && isset($search[0]->guid)){
return $search[0];
}
}
return false;
};
//caching
$cache = new OssnDynamicCaching();
if($cache->isAvailableEnabled()){
try {

$data = $cache->handler()->get("ossn_get_object({$guid})");
return $data;

} catch(OssnDynamicCacheKeyNotExists $e){

$data = $getObject($guid);
//don't store if its not exists in system
if($data){
$cache->handler()->store("ossn_get_object({$guid})", $data);
}
return $data;
}
}
return $getObject($guid);
$object = new OssnObject;
$object->object_guid = $guid;
return $object->getObjectById();
}
/**
* Get entities of object
Expand Down

0 comments on commit 900030c

Please sign in to comment.