Beispiel #1
0
void CompatibilityManager::resigner(const shared_ptr<IPortalDatabase> &database, shared_ptr<IdeSession> session)
{
	shared_ptr<ObjectsUser> user = session->getUser(database);
	if(user != nullptr)
	{
		Buffer signature = user->signature;
		if( (signature.getSize() == 1) && (signature.getAt(0) == 0) )
		{
			// Need re-sign.
			DataTable result;
			String sql = String::format(_S("select id,entity_author,author from os_entries where author='%S' union select id,entity_author,author from os_entries where entity_author='%S'").c_str(),user->id->toUTF16().c_str(),user->id->toUTF16().c_str());
			database->execute(sql,result);

			for(uint32 r=0;r<result.rows();r++)
			{
				String id = result.get(r,_S("id"));
				String entityAuthor = result.get(r,_S("entity_author"));
				String author = result.get(r,_S("author"));

				shared_ptr<ObjectsIObject> object = database->getPortal()->getObject(database, id.to_ascii());
				if(object != nullptr)
				{
					LanguageResult acceptable = object->acceptable(database);
					if(acceptable.empty())
					{
						if( (entityAuthor == user->id->toUTF16()) && (author == user->id->toUTF16()) )
						{
							shared_ptr<ObjectsIRevisionable> revisionable = objects_revisionable_cast(object);			
							if(revisionable != nullptr)
							{
								bool done = revisionable->signEntity(session->getPrivateKey(), database->getPortal()->getPortalID());
								OS_ASSERT(done);
							}
						}

						if(author == user->id->toUTF16())
						{
							bool done = object->sign(session->getPrivateKey(), database->getPortal()->getPortalID());							
							OS_ASSERT(done);
						}

						LanguageResult result = object->store(database);
						OS_ASSERT(result.empty());						
					}
				}
			}
		}
	}
}
Beispiel #2
0
//bool EntitiesEntity::_loadObject(const shared_ptr<IPortalDatabase> &database, shared_ptr<ObjectsIRevisionable> object)
bool EntitiesEntity::load(const shared_ptr<IPortalDatabase> &database, const EntityID & id)
{
	OS_TIMER_PERFORMANCE(TP, _S("Entity::_loadObject"));
	OS_LOCK(m_cs);

#ifndef OS_TODOCIP
	shared_ptr<ObjectsIRevisionable> object = objects_revisionable_cast(database->getPortal()->getObject(database, id.toUTF16()));
	m_primary = object;
	//OS_ASSERT(getEntityID() == id);
#endif

	if(database->getPortal()->getSnapshotManager()->m_enableEnsureLoadingEntity)
		database->getPortal()->getSnapshotManager()->ensure(database, id);

	DataTable result;
	// TOCLEAN_SNAPSHOT_SCORE
	//String sql = String::format(_S("select current,visible,score,depth,parent,section,stability_date from os_snapshot_objects where reference='%S'").c_str(), m_primary->id->toUTF16().c_str());
	String sql = String::format(_S("select type,current,visible,depth,parent,section,stability_date from os_snapshot_objects where entity='%S'").c_str(), id.toUTF16().c_str());
	database->execute(sql, result);
	if(!result.hasRow(0))
	{
		clear();
		return false;
	}
	else
	{
		ObjectID currentID = static_cast<String>(result.get(0,_S("current"))).to_ascii();
		m_type = Convert::toObjectType(static_cast<uint32>(result.get(0,_S("type"))));
		m_visible = result.get(0,_S("visible"));
		//m_score = *result.get(0,_S("score")); // TOCLEAN_SNAPSHOT_SCORE
		m_depth = result.get(0,_S("depth"));
		m_parent = static_cast<String>(result.get(0,_S("parent"))).to_ascii();
		m_section = static_cast<String>(result.get(0,_S("section"))).to_ascii();
		m_stabilityDate = String(result.get(0,_S("stability_date")));

		if(id == ObjectsSystem::instance()->getRootID())
			//m_current = objects_revisionable_cast(database->getPortal()->getObject(database, ObjectsSystem::instance()->getRootID().toObjectID()));
			m_current = ObjectsSection::getRootSection();
		else
		{		
#ifdef OS_TODOCIP
			/*
			if(currentID.empty())
				return false;
			m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
			if(m_current == nullptr)
				return false;				
			*/

			if(currentID.empty() == false)
				m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
#else
			if(currentID.empty())
			{
				m_current.reset();
				// OS_ASSERT(m_parent == ObjectsSystem::instance()->getSkippedID());
				// No, dato che la getEntity non fa + l'ensure, può succedere che carica un oggetto non stabilizzato.
				m_visible = false;
			}
			else
				m_current = objects_revisionable_cast(database->getPortal()->getObject(database, currentID));
#endif
		}

		return true;
	}
}