check functionality for existing updates

This commit is contained in:
shubham_meena 2014-06-19 14:53:49 +05:30
parent 2998ce870f
commit f04d5694f1

View file

@ -212,6 +212,8 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath )
{ {
mkdir( $tempPath . "/test" ); mkdir( $tempPath . "/test" );
} }
// extracting the update
if ( zipExtraction( $tempFile, $tempPath . "/test/" ) ) if ( zipExtraction( $tempFile, $tempPath . "/test/" ) )
{ {
$result = readPluginFile( ".info", $tempPath . "/test/" . $fileName ); $result = readPluginFile( ".info", $tempPath . "/test/" . $fileName );
@ -250,11 +252,20 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath )
} }
else else
{ {
// check if update already exists
if ( pluginUpdateExists( $info['Id'], $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) )
{
echo "Update already exists";
exit;
}
else {
// removing the preivous update
$dbr = new DBLayer( "lib" );
$dbr -> delete( "updates", array( 'id' => $info['Id'] ), "PluginId=:id" );
// storing update in the temp directory // storing update in the temp directory
// format of update save // format of update save
if ( move_uploaded_file( $tempFile, $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) ) { if ( move_uploaded_file( $tempFile, $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip" ) ) {
// setting update information in the database // setting update information in the database
$dbr = new DBLayer( "lib" );
$update['PluginId'] = $info['Id']; $update['PluginId'] = $info['Id'];
$update['UpdatePath'] = $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip"; $update['UpdatePath'] = $tempPath . "/" . trim( $fileName, ".zip" ) . "_" . $result['Version'] . ".zip";
$update['UpdateInfo'] = json_encode( $result ); $update['UpdateInfo'] = json_encode( $result );
@ -268,3 +279,28 @@ function checkForUpdate( $fileName, $findPath, $tempFile, $tempPath )
} }
} }
} }
}
/**
* Function to check for the update of a plugin already exists
*
* @param $pluginId id of the plugin for which update is available
* @param $updatePath path of the new update
* @return boolean if update for a plugin already exists or
* if update of same version is uploading
*/
function PluginUpdateExists( $pluginId, $updatePath )
{
$db = new DBLayer( 'lib' );
$sth = $db -> selectWithParameter( "UpdatePath", "updates", array( 'pluginid' => $pluginId ), "PluginId=:pluginid" );
$row = $sth -> fetch();
if ( $updatePath == $row['UpdatePath'] )
{
return true;
}
else
{
rmdir( $row['UpdatePath'] );
return false;
}
}