Example #1
0
	public function convert()
	{
		if (empty($this->_projects))
		{
			throw new RuntimeException('Projects convert should be set!');
		}

		// get data from database
		$query = 'SELECT * FROM ' . $this->getDB()->getSourcePrefix() . 'list_tasktype';
		$stmt = $this->getDB()->getSource()->query($query);

		$pp_types = array();
		while($row = $stmt->fetch(PDO::FETCH_ASSOC))
		{
			$pp_type = new PP_Project_Categories($this->getDB());
			$pp_type->setOldId($row['tasktype_id']);
			if ($row['project_id'] == '0')
			{
				$pp_type->setProject_id(0);
			}
			else
			{
				$pp_type->setProject_id($this->_projects->getNewId($row['project_id']));
			}
			$pp_type->setName($row['tasktype_name']);
			$pp_type->setDescription($row['tasktype_name']);			
			$pp_types[ $row['tasktype_id'] ] = $pp_type;
		}
		$stmt->closeCursor();
				
		// insert in db
		$this->setNewIds($pp_types[ array_rand($pp_types) ]->writes2DB($pp_types));
		
		// clean memory
		unset($pp_types);
	}
Example #2
0
	private function _convertTasks()
	{
		// get data from database
		$query = 'SELECT t.*, GROUP_CONCAT(a.user_id SEPARATOR \',\') AS assigned_user_id FROM ' . $this->getDB()->getSourcePrefix() . 'tasks t
				LEFT JOIN ' . $this->getDB()->getSourcePrefix() . 'assigned a ON a.task_id = t.task_id GROUP BY task_id';
		$stmt = $this->getDB()->getSource()->query($query);

		$pp_tickets = array();
		$assigned = array();
		while($row = $stmt->fetch(PDO::FETCH_ASSOC))
		{
			$pp_ticket = new PP_Project_Tickets($this->getDB());
			$pp_ticket->setOldId($row['task_id']);
			$pp_ticket->setProject_id($this->_projects->getNewId($row['project_id']));
			$pp_ticket->setCategory_id($this->_categories->getNewId($row['task_type']));
			$pp_ticket->setCreated_on(time2SqlDateTime($row['date_opened']));
			$pp_ticket->setCreated_by_id($this->_users->getNewId($row['opened_by']));
			$this->_closureComments[ $row['task_id'] ] = array($row['is_closed'], $this->_users->getNewId($row['opened_by']), $row['closure_comment']);
			if ($row['is_closed'] == '1')
			{
				$pp_ticket->setClosed_on(time2SqlDateTime($row['date_closed']));
				$pp_ticket->setClosed_by_id($this->_users->getNewId($row['closed_by']));
				$pp_ticket->setUpdated('closed');
				$pp_ticket->setState('closed');
			}
			else
			{
				$pp_ticket->setClosed_on('0000-00-00 00:00:00');
				$pp_ticket->setClosed_by_id(null);
				$pp_ticket->setUpdated('open');
				$pp_ticket->setState('opened');
			}
			$pp_ticket->updated_on = time2SqlDateTime($row['date_opened']);
			$pp_ticket->updated_by_id = $this->_users->getNewId($row['opened_by']);

			if ($row['mark_private'] == '1')
			{
				$pp_ticket->setIs_private(1);
			}
			else
			{
				$pp_ticket->setIs_private(0);
			}
			
			$pp_ticket->setSummary($row['item_summary']);
			$pp_ticket->setDescription($row['detailed_desc']);
			$pp_ticket->setPriority($row['task_priority']);
			if (!empty($row['assigned_user_id']))
			{
				$users_assigned = explode(',', $row['assigned_user_id']);
				$pp_ticket->setAssigned_to_user_id($this->_users->getNewId($users_assigned[0]));
				$assigned[ $row['task_id'] ] = $users_assigned;
			}
			else
			{
				$pp_ticket->setAssigned_to_user_id(null);
			}
		
			$pp_tickets[ $row['task_id'] ] = $pp_ticket;
		}
		$stmt->closeCursor();

		// insert in db
		$this->setNewIds($pp_tickets[ array_rand($pp_tickets) ]->writes2DB($pp_tickets));
		
		// clean memory
		unset($pp_tickets);
		
		// ticket subscription (no multiple assignement on pp, so use subscriptions ...)
		$ticketSubscriptions = array();
		foreach ($assigned as $oldTicketId => $assigned_users)
		{
			foreach ($assigned_users as $user_id)
			{
				$ticketSubscriptions[ $oldTicketId ] = new PP_Project_Ticket_Subscriptions($this->getDB());
				$ticketSubscriptions[ $oldTicketId ]->setTicket_id($this->getNewId($oldTicketId));
				$ticketSubscriptions[ $oldTicketId ]->setUser_id($this->_users->getNewId($user_id));
			}
		}
		$ticketSubscriptions[ array_rand($ticketSubscriptions) ]->writes2DB($ticketSubscriptions);
		unset($ticketSubscriptions);
	}