hasPriv('admin'))
util_show_error_page_and_exit("Only admins are allowed in here");
apidb_header('AppDB Control Center');
function updateAppMaintainerStates()
{
$hResult = application::objectGetEntries('accepted');
$i = 0;
while($oRow = mysql_fetch_object($hResult))
{
$oApp = new application(null, $oRow);
$oApp->updateMaintainerState();
$i++;
}
echo "Updated $i entries";
}
function updateVersionMaintainerStates()
{
$hResult = version::objectGetEntries('accepted');
$i = 0;
while($oRow = mysql_fetch_object($hResult))
{
$oVersion = new version(null, $oRow);
$oVersion->updateMaintainerState();
$i++;
}
echo "Updated $i entries";
}
function fixNoteLinks()
{
// Notes shown for app and all versions
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_ALL);
echo 'The following notes are set to show for app and all versions:
';
$iCount = 0;
$iSkipped = 0;
while(($oRow = mysql_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$iNoteId = $oNote->objectGetId();
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'
';
echo 'App: '.$oApp->objectMakeLink().'
';
$aVersions = $oApp->GetVersions(true);
foreach($aVersions as $oVersion)
{
$iVersionId = $oVersion->objectGetId();
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $iVersionId, $oRow->noteId);
$oRowTag = mysql_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('$iVersionId','$iNoteId')");
$iCount++;
} else
{
$iSkipped++;
}
}
echo '
';
}
echo "
Created $iCount tags ($iSkipped already existed)
";
// Notes shown for all versions
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_VERSIONS);
echo '
The following notes are set to show for all versions:
';
$iCount = 0;
$iSkipped = 0;
while(($oRow = mysql_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$iNoteId = $oNote->objectGetId();
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'
';
echo 'App: '.$oApp->objectMakeLink().'
';
$aVersions = $oApp->GetVersions(true);
foreach($aVersions as $oVersion)
{
$iVersionId = $oVersion->objectGetId();
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $iVersionId, $oRow->noteId);
$oRowTag = mysql_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('?','?')", $iVersionId, $iNoteId);
$iCount++;
} else
{
$iSkipped++;
}
}
echo '
';
}
echo "
Created $iCount tags ($iSkipped already existed)
";
// Notes shown for specific versions
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_SPECIFIC_VERSIONS);
echo '
The following notes are set to show for specific versions:
';
$iCount = 0;
$iSkipped =0;
while(($oRow = mysql_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$iNoteId = $oNote->objectGetId();
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'
';
echo 'App: '.$oApp->objectMakeLink().'
';
echo '
';
$hResult2 = query_parameters("SELECT DISTINCT(versionId) FROM appNotes WHERE linkedWith = '?'", $oNote->objectGetId());
while(($oRow2 = mysql_fetch_object($hResult2)))
{
$iVersionId = $oRow2->versionId;
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $iVersionId, $oRow->noteId);
$oRowTag = mysql_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('?','?')", $iVersionId, $iNoteId);
$iCount++;
} else
{
$iSkipped++;
}
}
}
echo "
Created $iCount tags ($iSkipped already existed)
";
// Notes shown for app
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId = '?'", APPNOTE_SHOW_FOR_APP);
echo '
The following notes are set to show on app page:
';
$iCount = 0;
while(($oRow = mysql_fetch_object($hResult)))
{
$oNote = new note(null, $oRow);
$oApp = new Application($oNote->iAppId);
echo 'ID: '.$oNote->objectGetId().'
';
echo 'App: '.$oApp->objectMakeLink().'
';
echo '
';
$iCount++;
}
echo "
$iCount in total
";
// Create links for ordinary notes
echo "
Creating tags for ordinar notes
";
$hResult = query_parameters("SELECT * FROM appNotes WHERE versionId > '0' AND linkedWith = '0'");
$iTagsCreated = 0;
$iSkipped = 0;
while(($oRow = mysql_fetch_object($hResult)))
{
$hResultTag = query_parameters("SELECT COUNT(*) as count FROM tags_NoteVersion_assignments WHERE tagId = '?' AND taggedId = '?'", $oRow->versionId, $oRow->noteId);
$oRowTag = mysql_fetch_object($hResultTag);
if(!$oRowTag->count)
{
query_parameters("INSERT INTO tags_NoteVersion_assignments (tagId,taggedId) VALUES('?','?')", $oRow->versionId, $oRow->noteId);
$iTagsCreated++;
} else
{
$iSkipped++;
}
}
echo "Created $iTagsCreated note tags ($iSkipped already existed)
";
echo "
Deleting note links
";
$hResult = query_parameters("DELETE FROM appNotes WHERE linkedWith != '0'");
echo "Deleted ".mysql_affected_rows()." links
";
}
function showChoices()
{
echo 'Fix/Show note links
';
echo 'Update application maintainer states
';
echo 'Update version maintainer states
';
}
switch(getInput('sAction', $aClean))
{
case 'updateAppMaintainerStates':
updateAppMaintainerStates();
break;
case 'updateVersionMaintainerStates':
updateVersionMaintainerStates();
break;
case 'fixNoteLinks':
fixNoteLinks();
break;
default:
showChoices();
break;
}
apidb_footer();
?>