Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 73 lines (70 sloc) 1.902 kb
34f7a6a @chadsmith first commit
authored
1 <?php
2 if(!OpenVBX::isAdmin())
3 die();
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
4 if(!class_exists('ZipArchive') && !class_exists('Archive_Tar'))
5 die('The <a href="http://www.php.net/manual/en/book.zip.php">ZipArchive</a> or <a href="http://pear.php.net/package/Archive_Tar/">Archive_Tar</a> class must be installed to use this plugin.');
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
6 $cwd = dirname(__FILE__);
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
7 if(!is_writable($cwd))
8 die($cwd . ' must be writable by ' . get_current_user());
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
9 $root = dirname(dirname($cwd));
34f7a6a @chadsmith first commit
authored
10 if(!is_writable($root))
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
11 die($root . ' must be writable by ' . get_current_user());
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
12 $tmp = $cwd . '/tmp/';
13 mkdir($tmp);
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
14 if(class_exists('ZipArchive')) {
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
15 $archive = $tmp . 'OpenVBX.zip';
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
16 file_put_contents($archive, file_get_contents('https://github.com/twilio/OpenVBX/zipball/master'));
17 $z = new ZipArchive;
18 if(true === $z->open($archive)) {
34f7a6a @chadsmith first commit
authored
19 $z->extractTo($tmp);
20 $z->close();
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
21 unlink($archive);
22 }
23 else
24 die('Upgrade failed.');
34f7a6a @chadsmith first commit
authored
25 }
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
26 else {
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
27 $archive = $tmp . 'OpenVBX.tar.gz';
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
28 file_put_contents($archive, file_get_contents('https://github.com/twilio/OpenVBX/tarball/master'));
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
29 $a = new Archive_Tar($archive);
30 if(true === $a->extract($tmp))
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
31 unlink($archive);
32 else
33 die('Upgrade failed.');
34 }
35 $d = dir($tmp);
36 while($file = $d->read())
37 if(!in_array($file, array('.', '..'))) {
38 mvdir($tmp . $file, $root);
0949954 @chadsmith switched to Archive_Tar; remove tmp after upgrade
authored
39 rmall($tmp);
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
40 }
41 $d->close();
42 die('Success!');
43
44 function mvdir($source, $target) {
45 if(is_dir($source)) {
34f7a6a @chadsmith first commit
authored
46 @mkdir($target);
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
47 $d = dir($source);
48 while($file = $d->read())
49 if(!in_array($file, array('.', '..'))) {
50 $path = $source . '/' . $file;
34f7a6a @chadsmith first commit
authored
51 if(is_dir($path))
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
52 mvdir($path, $target . '/' . $file);
34f7a6a @chadsmith first commit
authored
53 else
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
54 @rename($path, $target . '/' . $file);
34f7a6a @chadsmith first commit
authored
55 }
56 $d->close();
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
57 }
58 else
59 @rename($source, $target);
34f7a6a @chadsmith first commit
authored
60 }
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
61
62 function rmall($dir) {
63 $files = glob($dir . '*', GLOB_MARK);
64 foreach($files as $file) {
34f7a6a @chadsmith first commit
authored
65 if(is_dir($file))
66 rmall($file);
67 else
68 @unlink($file);
69 }
70 if(is_dir($dir))
71 @rmdir($dir);
c6acf26 @chadsmith use Phar class is ZipArchive is not installed
authored
72 }
Something went wrong with that request. Please try again.