We now are having an item class and a method to change item entries
This commit is contained in:
		
					parent
					
						
							
								ec879f3194
							
						
					
				
			
			
				commit
				
					
						81925e3730
					
				
			
		
					 2 changed files with 58 additions and 6 deletions
				
			
		
							
								
								
									
										56
									
								
								src/Model/Item.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								src/Model/Item.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,56 @@ | |||
| <?php | ||||
| 
 | ||||
| /** | ||||
|  * @file src/Model/Item.php | ||||
|  */ | ||||
| 
 | ||||
| namespace Friendica\Model; | ||||
| 
 | ||||
| use Friendica\Core\Worker; | ||||
| use dba; | ||||
| 
 | ||||
| require_once 'include/tags.php'; | ||||
| require_once 'include/files.php'; | ||||
| require_once 'include/threads.php'; | ||||
| 
 | ||||
| class Item | ||||
| { | ||||
| 	/** | ||||
| 	 * @brief Update existing item entries | ||||
| 	 * | ||||
| 	 * @param array $fields The fields that are to be changed | ||||
| 	 * @param array $condition The condition for finding the item entries | ||||
| 	 * | ||||
| 	 * @return boolean success | ||||
| 	 */ | ||||
| 	public static function update(array $fields, array $condition) | ||||
| 	{ | ||||
| 		if (empty($condition) || empty($fields)) { | ||||
| 			return false; | ||||
| 		} | ||||
| 
 | ||||
| 		$success = dba::update('item', $fields, $condition); | ||||
| 
 | ||||
| 		if (!$success) { | ||||
| 			return false; | ||||
| 		} | ||||
| 
 | ||||
| 		// We cannot simply expand the condition to check for origin entries
 | ||||
| 		// The condition needn't to be a simple array but could be a complex condition.
 | ||||
| 		$items = dba::select('item', ['id', 'origin'], $condition); | ||||
| 		while ($item = dba::fetch($items)) { | ||||
| 			// We only need to notfiy others when it is an original entry from us
 | ||||
| 			if (!$item['origin']) { | ||||
| 				continue; | ||||
| 			} | ||||
| 
 | ||||
| 			create_tags_from_item($item['id']); | ||||
| 			create_files_from_item($item['id']); | ||||
| 			update_thread($item['id']); | ||||
| 
 | ||||
| 			Worker::add(PRIORITY_HIGH, "Notifier", 'edit_post', $item['id']); | ||||
| 		} | ||||
| 
 | ||||
| 		return true; | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue