From 8481acd87332c4d6ed3cac2674014b9b72f62acd Mon Sep 17 00:00:00 2001 From: s9e Date: Wed, 30 Oct 2013 12:17:58 +0100 Subject: [PATCH] Added install callback to check the PHP version --- .travis.yml | 3 ++- build/addon.xml | 2 +- build/upload/library/s9e/MediaBBCodes.php | 8 ++++++ scripts/build.php | 30 ++++++++++++++++++----- scripts/installRunkit.sh | 10 ++++++++ tests/Test.php | 30 ++++++++++++++++++++++- www/configure.html | 4 +++ 7 files changed, 78 insertions(+), 9 deletions(-) create mode 100755 scripts/installRunkit.sh diff --git a/.travis.yml b/.travis.yml index 3ba13bc..0f9f11e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,10 @@ before_script: - echo "zend.enable_gc=off" >> ~/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/php.ini - mkdir releases tests/.cache - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then composer install --dev --no-interaction; fi" + - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then scripts/installRunkit.sh; fi" - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.3' ]; then phpenv config-rm xdebug.ini; fi" - php -i script: - phpunit -c phpunit-$TRAVIS_PHP_VERSION.xml after_script: - - sh -c "if [ $TRAVIS_PHP_VERSION = '5.5' ]; then php vendor/bin/coveralls -v; fi" \ No newline at end of file + - sh -c "if [ '$TRAVIS_PHP_VERSION' = '5.5' ]; then php vendor/bin/coveralls -v; fi" \ No newline at end of file diff --git a/build/addon.xml b/build/addon.xml index 7ea45c0..1795054 100644 --- a/build/addon.xml +++ b/build/addon.xml @@ -1,5 +1,5 @@ - + !bandcamp\.com/album/.! diff --git a/build/upload/library/s9e/MediaBBCodes.php b/build/upload/library/s9e/MediaBBCodes.php index d2d3ded..741eb2d 100644 --- a/build/upload/library/s9e/MediaBBCodes.php +++ b/build/upload/library/s9e/MediaBBCodes.php @@ -12,6 +12,14 @@ class s9e_MediaBBCodes */ public static $cacheDir; + public static function install() + { + if (version_compare(phpversion(), '5.3', '<')) + { + throw new RuntimeException('Requires PHP 5.3 or later'); + } + } + public static function match($url, $regexps, $scrapes) { $vars = array(); diff --git a/scripts/build.php b/scripts/build.php index 11e8286..4068080 100755 --- a/scripts/build.php +++ b/scripts/build.php @@ -30,6 +30,14 @@ class s9e_MediaBBCodes */ public static $cacheDir; + public static function install() + { + if (version_compare(phpversion(), '5.3', '<')) + { + throw new RuntimeException('Requires PHP 5.3 or later'); + } + } + public static function match($url, $regexps, $scrapes) { $vars = array(); @@ -232,18 +240,28 @@ protected static function getNamedCaptures($string, $regexps) $dom = new DOMDocument('1.0', 'utf-8'); $addon = $dom->appendChild($dom->createElement('addon')); +// The version is simply the current UTC day, optionally followed by the first argument given to +// this script $versionId = gmdate('Ymd'); - if (isset($_SERVER['argv'][1])) { $versionId .= $_SERVER['argv'][1]; } -$addon->setAttribute('addon_id', 's9e'); -$addon->setAttribute('title', 's9e Media Pack'); -$addon->setAttribute('url', 'https://github.com/s9e/XenForoMediaBBCodes'); -$addon->setAttribute('version_id', $versionId); -$addon->setAttribute('version_string', $versionId); +// Set the add-on informations +$attributes = [ + 'addon_id' => 's9e', + 'title' => 's9e Media Pack', + 'url' => 'https://github.com/s9e/XenForoMediaBBCodes', + 'version_id' => $versionId, + 'version_string' => $versionId, + 'install_callback_class' => 's9e_MediaBBCodes', + 'install_callback_method' => 'install' +]; +foreach ($attributes as $attrName => $attrValue) +{ + $addon->setAttribute($attrName, $attrValue); +} $rows = []; $rows[] = ''; diff --git a/scripts/installRunkit.sh b/scripts/installRunkit.sh new file mode 100755 index 0000000..f3d21a9 --- /dev/null +++ b/scripts/installRunkit.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +wget -O - https://codeload.github.com/php/pecl-php-runkit/tar.gz/master | tar xzf - -C/tmp && \ +cd /tmp/pecl-php-runkit-master && \ +phpize && \ +./configure --enable-runkit-modify --disable-runkit-super --disable-runkit-sandbox && \ +make && \ +sudo make install && \ +echo "extension=runkit.so" >> ~/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/php.ini && \ +echo "runkit.internal_override=1" >> ~/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/php.ini \ No newline at end of file diff --git a/tests/Test.php b/tests/Test.php index 9ff179e..f76e6b5 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -18,7 +18,35 @@ public function testBuild() public function testLint() { - include __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php'; + include_once __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php'; + } + + public function testInstall() + { + if (!class_exists('s9e_MediaBBCodes')) + { + include __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php'; + } + + s9e_MediaBBCodes::install(); + } + + /** + * @runInSeparateProcess + * @requires extension runkit + * @expectedException RuntimeException + * @expectedException RuntimeExceptionMessage Requires PHP 5.3 or later + */ + public function testInstallFailure() + { + if (!class_exists('s9e_MediaBBCodes')) + { + include __DIR__ . '/../build/upload/library/s9e/MediaBBCodes.php'; + } + + runkit_function_redefine('phpversion', '', "return '5.2.5';"); + + s9e_MediaBBCodes::install(); } /** diff --git a/www/configure.html b/www/configure.html index b7da652..39c5fee 100644 --- a/www/configure.html +++ b/www/configure.html @@ -226,7 +226,11 @@