Add support for developers to insert a small sample of data from remote testing areas.
This commit is contained in:
parent
2f614ae19c
commit
7d7e84ff7a
|
@ -5,6 +5,12 @@
|
|||
|
||||
return array(
|
||||
|
||||
// PVL deployment API sent by this application. Contact PVL lead developer for info.
|
||||
'pvl_api_key' => '',
|
||||
|
||||
// PVL deployment API keys accepted by this application.
|
||||
'pvl_api_keys' => array(),
|
||||
|
||||
// Mandrill SMTP service.
|
||||
'smtp' => array(
|
||||
'server' => 'smtp.mandrillapp.com',
|
||||
|
|
|
@ -66,6 +66,7 @@ class Api extends \DF\Controller\Action
|
|||
'status' => 'success',
|
||||
'result' => $data,
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function returnError($message)
|
||||
|
@ -74,6 +75,7 @@ class Api extends \DF\Controller\Action
|
|||
'status' => 'error',
|
||||
'error' => $message,
|
||||
));
|
||||
return false;
|
||||
}
|
||||
|
||||
public function returnToScreen($obj)
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
class Api_DevController extends \PVL\Controller\Action\Api
|
||||
{
|
||||
public function preDispatch()
|
||||
{
|
||||
parent::preDispatch();
|
||||
|
||||
if (!$this->hasParam('key'))
|
||||
die('ERROR: No API key specified!');
|
||||
|
||||
$supplied_key = $this->getParam('key');
|
||||
$accepted_api_keys = $this->config->apis->pvl_api_keys->toArray();
|
||||
|
||||
$key_accepted = false;
|
||||
foreach($accepted_api_keys as $api_key)
|
||||
{
|
||||
if (strcmp(md5($api_key), $supplied_key) === 0)
|
||||
$key_accepted = true;
|
||||
}
|
||||
|
||||
if (!$key_accepted)
|
||||
die('ERROR: API key specified is not valid.');
|
||||
}
|
||||
|
||||
public function importAction()
|
||||
{
|
||||
ini_set('memory_limit', '250M');
|
||||
ini_set('display_errors', 0);
|
||||
|
||||
// Tables to export from local DB.
|
||||
$tables = array(
|
||||
'settings',
|
||||
'block',
|
||||
'action',
|
||||
'role',
|
||||
'role_has_action',
|
||||
'station',
|
||||
'podcast',
|
||||
'podcast_on_station',
|
||||
'artist',
|
||||
'songs',
|
||||
);
|
||||
|
||||
// Compose mysqldump command.
|
||||
$db_config = $this->config->db->toArray();
|
||||
|
||||
$destination_path = DF_INCLUDE_TEMP.DIRECTORY_SEPARATOR.'pvl_import.sql';
|
||||
|
||||
$command_flags = array(
|
||||
'-h '.$db_config['host'],
|
||||
'-u '.$db_config['user'],
|
||||
'-p'.$db_config['password'],
|
||||
'--no-create-info',
|
||||
$db_config['dbname'],
|
||||
implode(' ', $tables),
|
||||
);
|
||||
$command = 'mysqldump '.implode(' ', $command_flags).' > '.$destination_path;
|
||||
|
||||
// Execute mysqldump.
|
||||
exec($command);
|
||||
|
||||
// Stream file out to screen.
|
||||
if (file_exists($destination_path))
|
||||
{
|
||||
$fp = fopen($destination_path, 'r');
|
||||
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Length: " . filesize($destination_path));
|
||||
|
||||
fpassthru($fp);
|
||||
fclose($fp);
|
||||
|
||||
@unlink($destination_path);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,4 +4,4 @@
|
|||
* * * * * sudo -u www-data php /var/www/vagrant/util/nowplaying.php
|
||||
* * * * * sleep 15; sudo -u www-data php /var/www/vagrant/util/nowplaying.php
|
||||
* * * * * sleep 30; sudo -u www-data php /var/www/vagrant/util/nowplaying.php
|
||||
* * * * * sleep 45; sudo -u www-data php /var/www/vagrant/util/nowplaying.php
|
||||
* * * * * sleep 45; sudo -u www-data php /var/www/vagrant/util/nowplaying.php
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* Vagrant Remote API importer script.
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../app/bootstrap.php';
|
||||
$application->bootstrap();
|
||||
|
||||
set_time_limit(0);
|
||||
error_reporting(E_ALL & ~E_NOTICE);
|
||||
|
||||
$api_key = $config->apis->pvl_api_key;
|
||||
|
||||
if (empty($api_key))
|
||||
die('No API key specified in app/config/apis.conf.php. Please contact PVL developer team!');
|
||||
|
||||
$remote_base = 'http://ponyvillelive.com';
|
||||
$remote_url = $remote_base.'/api/dev/import?key='.$api_key;
|
||||
|
||||
$local_temp = DF_INCLUDE_TEMP.DIRECTORY_SEPARATOR.'vagrant_import.sql';
|
||||
|
||||
// Pull from remote API.
|
||||
$fp = fopen($local_temp, 'w');
|
||||
|
||||
$options = array(
|
||||
CURLOPT_FILE => $fp,
|
||||
CURLOPT_TIMEOUT => 28800,
|
||||
CURLOPT_URL => $remote_url,
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $options);
|
||||
curl_exec($ch);
|
||||
fclose($fp);
|
||||
|
||||
// Check local file.
|
||||
if (!file_exists($local_temp))
|
||||
die('File could not be saved locally.');
|
||||
|
||||
// If returned value was JSON error, decode it.
|
||||
if (filesize($local_temp) < (1024*2))
|
||||
{
|
||||
$results = file_get_contents($local_temp);
|
||||
echo $results.PHP_EOL;
|
||||
|
||||
@unlink($local_temp);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Prepare and execute mysqlimport command.
|
||||
$db_config = $config->db->toArray();
|
||||
|
||||
$destination_path = DF_INCLUDE_TEMP.DIRECTORY_SEPARATOR.'pvl_import.sql';
|
||||
|
||||
$command_flags = array(
|
||||
'-h '.$db_config['host'],
|
||||
'-u '.$db_config['user'],
|
||||
'-p'.$db_config['password'],
|
||||
$db_config['dbname']
|
||||
);
|
||||
$command = 'mysql '.implode(' ', $command_flags).' < '.$local_temp;
|
||||
|
||||
echo $command;
|
||||
|
||||
passthru($command);
|
||||
|
||||
// @unlink($local_temp);
|
||||
|
||||
echo 'Database import complete.'.PHP_EOL;
|
||||
exit;
|
Loading…
Reference in New Issue