khanat-opennel-code/code/web/public_php/ams/func/update_plugin.php

40 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* This function is used in installing updates for plugins.
* It takes id of the plugin whose update is available using
2014-09-03 05:06:43 +00:00
* $_GET global variable and then extract the update details
* from db and then install it in the plugin.
2014-09-03 05:06:43 +00:00
*
* @author Shubham Meena, mentored by Matthew Lagoe
*/
function update_plugin() {
2014-09-03 05:06:43 +00:00
// if logged in
if ( WebUsers :: isLoggedIn() ) {
2014-09-03 05:06:43 +00:00
if ( isset( $_GET['id'] ) )
{
// id of plugin to update
$id = filter_var( $_GET['id'], FILTER_SANITIZE_FULL_SPECIAL_CHARS );
$db = new DBLayer( 'lib' );
$sth = $db -> executeWithoutParams( "SELECT * FROM plugins INNER JOIN updates ON plugins.Id=updates.PluginId Where plugins.Id=$id" );
$row = $sth -> fetch();
2014-09-03 05:06:43 +00:00
// replacing update in the database
Plugincache :: rrmdir( $row['FileName'] );
Plugincache :: zipExtraction( $row['UpdatePath'], rtrim( $row['FileName'], strtolower( $row['Name'] ) ) );
2014-09-03 05:06:43 +00:00
$db -> update( "plugins", array( 'Info' => $row['UpdateInfo'] ), "Id=$row[Id]" );
2014-09-03 05:06:43 +00:00
// deleting the previous update
$db -> delete( "updates", array( 'id' => $row['s.no'] ), "s.no=:id" );
2014-09-03 05:06:43 +00:00
// if update is installed succesffully redirect to show success message
2014-09-03 05:36:10 +00:00
header("Cache-Control: max-age=1");
header( "Location: index.php?page=plugins&result=8" );
2014-09-03 05:23:39 +00:00
throw new SystemExit();
2014-09-03 05:06:43 +00:00
}
}
}