Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,3 @@
#!/bin/sh
curl --silent --compressed http://example.com/cron/YOURKEY

View file

@ -0,0 +1,3 @@
#!/bin/sh
/usr/bin/lynx -source http://example.com/cron/YOURKEY > /dev/null 2>&1

View file

@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
/**
* @file
* A command line application to import a database generation script.
*/
use Drupal\Core\Command\DbToolsApplication;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
if (PHP_SAPI !== 'cli') {
return;
}
// Bootstrap.
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
$application = new DbToolsApplication();
$application->run();

143
web/core/scripts/drupal.sh Executable file
View file

@ -0,0 +1,143 @@
#!/usr/bin/env php
<?php
/**
* Drupal shell execution script
*
* Check for your PHP interpreter - on Windows you'll probably have to
* replace line 1 with
* #!c:/program files/php/php.exe
*
* @param path Drupal's absolute root directory in local file system (optional).
* @param URI A URI to execute, including HTTP protocol prefix.
*/
$script = basename(array_shift($_SERVER['argv']));
if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
echo <<<EOF
Execute a Drupal page from the shell.
Usage: {$script} [OPTIONS] "<URI>"
Example: {$script} "http://mysite.org/node"
All arguments are long options.
--help This page.
--root Set the working directory for the script to the specified path.
To execute Drupal this has to be the root directory of your
Drupal installation, f.e. /home/www/foo/drupal (assuming Drupal
running on Unix). Current directory is not required.
Use surrounding quotation marks on Windows.
--verbose This option displays the options as they are set, but will
produce errors from setting the session.
URI The URI to execute, i.e. http://default/foo/bar for executing
the path '/foo/bar' in your site 'default'. URI has to be
enclosed by quotation marks if there are ampersands in it
(f.e. index.php?q=node&foo=bar). Prefix 'http://' is required,
and the domain must exist in Drupal's sites-directory.
If the given path and file exists it will be executed directly,
i.e. if URI is set to http://default/bar/foo.php
and bar/foo.php exists, this script will be executed without
bootstrapping Drupal. To execute Drupal's update.php, specify
http://default/update.php as the URI.
To run this script without --root argument invoke it from the root directory
of your Drupal installation with
./scripts/{$script}
\n
EOF;
exit;
}
// define default settings
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
// toggle verbose mode
if (in_array('--verbose', $_SERVER['argv'])) {
$_verbose_mode = true;
}
else {
$_verbose_mode = false;
}
// parse invocation arguments
while ($param = array_shift($_SERVER['argv'])) {
switch ($param) {
case '--root':
// change working directory
$path = array_shift($_SERVER['argv']);
if (is_dir($path)) {
chdir($path);
if ($_verbose_mode) {
echo "cwd changed to: {$path}\n";
}
}
else {
echo "\nERROR: {$path} not found.\n\n";
}
break;
default:
if (substr($param, 0, 2) == '--') {
// ignore unknown options
break;
}
else {
// parse the URI
$path = parse_url($param);
// set site name
if (isset($path['host'])) {
$_SERVER['HTTP_HOST'] = $path['host'];
}
// set query string
if (isset($path['query'])) {
$_SERVER['QUERY_STRING'] = $path['query'];
parse_str($path['query'], $_GET);
$_REQUEST = $_GET;
}
// set file to execute or Drupal path (clean URLs enabled)
if (isset($path['path']) && file_exists(substr($path['path'], 1))) {
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = $path['path'];
$cmd = substr($path['path'], 1);
}
elseif (isset($path['path'])) {
$_SERVER['SCRIPT_NAME'] = '/' . $cmd;
$_SERVER['REQUEST_URI'] = $path['path'];
}
// display setup in verbose mode
if ($_verbose_mode) {
echo "Hostname set to: {$_SERVER['HTTP_HOST']}\n";
echo "Script name set to: {$cmd}\n";
echo "Path set to: {$path['path']}\n";
}
}
break;
}
}
if (file_exists($cmd)) {
include $cmd;
}
else {
echo "\nERROR: {$cmd} not found.\n\n";
}
exit();

View file

@ -0,0 +1,106 @@
#!/usr/bin/env php
<?php
/**
* Dump a Drupal 6 database into a Drupal 7 PHP script to test the upgrade
* process.
*
* Run this script at the root of an existing Drupal 6 installation.
*
* The output of this script is a PHP script that can be ran inside Drupal 7
* and recreates the Drupal 6 database as dumped. Transient data from cache
* session and watchdog tables are not recorded.
*/
// Define default settings.
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Include the utility drupal_var_export() function.
include_once __DIR__ . '/../includes/utility.inc';
// Output the PHP header.
$output = <<<ENDOFHEADER
<?php
/**
* @file
* Filled installation of Drupal 6.17, for test purposes.
*
* This file was generated by the dump-database-d6.sh tool, from an
* installation of Drupal 6, filled with data using the generate-d6-content.sh
* tool. It has the following modules installed:
ENDOFHEADER;
foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
$output .= " * - $module\n";
}
$output .= " */\n\n";
// Get the current schema, order it by table name.
$schema = drupal_get_schema();
ksort($schema);
// Override the field type of the filename primary key to bypass the
// InnoDB 191 character limitation.
if (isset($schema['system']['primary key']) && $schema['system']['primary key'] == 'filename' && isset($schema['system']['fields']['filename']['type']) && $schema['system']['fields']['filename']['type'] == 'varchar') {
$schema['system']['fields']['filename']['type'] = 'varchar_ascii';
}
// Export all the tables in the schema.
foreach ($schema as $table => $data) {
// Remove descriptions to save time and code.
unset($data['description']);
foreach ($data['fields'] as &$field) {
unset($field['description']);
}
// Dump the table structure.
$output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
// Don't output values for those tables.
if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
$output .= "\n";
continue;
}
// Prepare the export of values.
$result = db_query('SELECT * FROM {'. $table .'}');
$insert = '';
while ($record = db_fetch_array($result)) {
// users.uid is a serial and inserting 0 into a serial can break MySQL.
// So record uid + 1 instead of uid for every uid and once all records
// are in place, fix them up.
if ($table == 'users') {
$record['uid']++;
}
$insert .= '->values('. drupal_var_export($record) .")\n";
}
// Dump the values if there are some.
if ($insert) {
$output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
$output .= $insert;
$output .= "->execute();\n";
}
// Add the statement fixing the serial in the user table.
if ($table == 'users') {
$output .= "db_query('UPDATE {users} SET uid = uid - 1');\n";
}
$output .= "\n";
}
print $output;

View file

@ -0,0 +1,91 @@
#!/usr/bin/env php
<?php
/**
* @file
* Dumps a Drupal 7 database into a Drupal 7 PHP script to test the upgrade
* process.
*
* Run this script at the root of an existing Drupal 7 installation.
*
* The output of this script is a PHP script that can be run inside Drupal 7
* and recreates the Drupal 7 database as dumped. Transient data from cache,
* session, and watchdog tables are not recorded.
*/
// Define default settings.
define('DRUPAL_ROOT', getcwd());
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Include the utility drupal_var_export() function.
include_once dirname(__FILE__) . '/../includes/utility.inc';
// Output the PHP header.
$output = <<<ENDOFHEADER
<?php
/**
* @file
* Filled installation of Drupal 7.0, for test purposes.
*
* This file was generated by the dump-database-d7.sh tool, from an
* installation of Drupal 7, filled with data using the generate-d7-content.sh
* tool. It has the following modules installed:
ENDOFHEADER;
foreach (\Drupal::moduleHandler()->getModuleList() as $module => $filename) {
$output .= " * - $module\n";
}
$output .= " */\n\n";
// Get the current schema, order it by table name.
$schema = drupal_get_schema();
ksort($schema);
// Export all the tables in the schema.
foreach ($schema as $table => $data) {
// Remove descriptions to save time and code.
unset($data['description']);
foreach ($data['fields'] as &$field) {
unset($field['description']);
}
// Dump the table structure.
$output .= "db_create_table('" . $table . "', " . drupal_var_export($data) . ");\n";
// Don't output values for those tables.
if (substr($table, 0, 5) == 'cache' || $table == 'sessions' || $table == 'watchdog') {
$output .= "\n";
continue;
}
// Prepare the export of values.
$result = db_query('SELECT * FROM {'. $table .'}', array(), array('fetch' => PDO::FETCH_ASSOC));
$insert = '';
foreach ($result as $record) {
$insert .= '->values('. drupal_var_export($record) .")\n";
}
// Dump the values if there are some.
if ($insert) {
$output .= "db_insert('". $table . "')->fields(". drupal_var_export(array_keys($data['fields'])) .")\n";
$output .= $insert;
$output .= "->execute();\n";
}
$output .= "\n";
}
print $output;

View file

@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
/**
* @file
* A command line application to dump a database to a generation script.
*/
use Drupal\Core\Command\DbDumpApplication;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
if (PHP_SAPI !== 'cli') {
return;
}
// Bootstrap.
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
$application = new DbDumpApplication();
$application->run();

View file

@ -0,0 +1,206 @@
#!/usr/bin/env php
<?php
/**
* Generate content for a Drupal 6 database to test the upgrade process.
*
* Run this script at the root of an existing Drupal 6 installation.
* Steps to use this generation script:
* - Install drupal 6.
* - Run this script from your Drupal ROOT directory.
* - Use the dump-database-d6.sh to generate the D7 file
* modules/simpletest/tests/upgrade/database.filled.php
*/
// Define settings.
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
$modules_to_enable = array('path', 'poll');
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Enable requested modules
include_once './modules/system/system.admin.inc';
$form = system_modules();
foreach ($modules_to_enable as $module) {
$form_state['values']['status'][$module] = TRUE;
}
$form_state['values']['disabled_modules'] = $form['disabled_modules'];
system_modules_submit(NULL, $form_state);
unset($form_state);
// Run cron after installing
drupal_cron_run();
// Create six users
for ($i = 0; $i < 6; $i++) {
$name = "test user $i";
$pass = md5("test PassW0rd $i !(.)");
$mail = "test$i@example.com";
$now = mktime(0, 0, 0, 1, $i + 1, 2010);
db_query("INSERT INTO {users} (name, pass, mail, status, created, access) VALUES ('%s', '%s', '%s', %d, %d, %d)", $name, $pass, $mail, 1, $now, $now);
}
// Create vocabularies and terms
$terms = array();
// All possible combinations of these vocabulary properties.
$hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
$multiple = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);
$required = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
$voc_id = 0;
$term_id = 0;
for ($i = 0; $i < 24; $i++) {
$vocabulary = array();
++$voc_id;
$vocabulary['name'] = "vocabulary $voc_id (i=$i)";
$vocabulary['description'] = "description of ". $vocabulary['name'];
$vocabulary['nodes'] = $i > 11 ? array('page' => TRUE) : array();
$vocabulary['multiple'] = $multiple[$i % 12];
$vocabulary['required'] = $required[$i % 12];
$vocabulary['relations'] = 1;
$vocabulary['hierarchy'] = $hierarchy[$i % 12];
$vocabulary['weight'] = $i;
taxonomy_save_vocabulary($vocabulary);
$parents = array();
// Vocabularies without hierarchy get one term, single parent vocabularies get
// one parent and one child term. Multiple parent vocabularies get three
// terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
for ($j = 0; $j < $vocabulary['hierarchy'] + 1; $j++) {
$term = array();
$term['vid'] = $vocabulary['vid'];
// For multiple parent vocabularies, omit the t0-t1 relation, otherwise
// every parent in the vocabulary is a parent.
$term['parent'] = $vocabulary['hierarchy'] == 2 && i == 1 ? array() : $parents;
++$term_id;
$term['name'] = "term $term_id of vocabulary $voc_id (j=$j)";
$term['description'] = 'description of ' . $term['name'];
$term['weight'] = $i * 3 + $j;
taxonomy_save_term($term);
$terms[] = $term['tid'];
$parents[] = $term['tid'];
}
}
$node_id = 0;
$revision_id = 0;
module_load_include('inc', 'node', 'node.pages');
for ($i = 0; $i < 24; $i++) {
$uid = intval($i / 8) + 3;
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = $i < 12 ? 'page' : 'story';
$node->sticky = 0;
++$node_id;
++$revision_id;
$node->title = "node title $node_id rev $revision_id (i=$i)";
$type = node_get_types('type', $node->type);
if ($type->has_body) {
$node->body = str_repeat("node body ($node->type) - $i", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
}
$node->status = intval($i / 4) % 2;
$node->language = '';
$node->revision = $i < 12;
$node->promote = $i % 2;
$node->created = $now + $i * 86400;
$node->log = "added $i node";
// Make every term association different a little. For nodes with revisions,
// make the initial revision have a different set of terms than the
// newest revision.
$node_terms = $terms;
unset($node_terms[$i], $node_terms[47 - $i]);
if ($node->revision) {
$node->taxonomy = array($i => $terms[$i], 47-$i => $terms[47 - $i]);
}
else {
$node->taxonomy = $node_terms;
}
node_save($node);
path_set_alias("node/$node->nid", "content/$node->created");
if ($node->revision) {
$user = user_load($uid + 3);
++$revision_id;
$node->title .= " rev2 $revision_id";
$node->body = str_repeat("node revision body ($node->type) - $i", 100);
$node->log = "added $i revision";
$node->taxonomy = $node_terms;
node_save($node);
}
}
// Create poll content
for ($i = 0; $i < 12; $i++) {
$uid = intval($i / 4) + 3;
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = 'poll';
$node->sticky = 0;
$node->title = "poll title $i";
$type = node_get_types('type', $node->type);
if ($type->has_body) {
$node->body = str_repeat("node body ($node->type) - $i", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
}
$node->status = intval($i / 2) % 2;
$node->language = '';
$node->revision = 1;
$node->promote = $i % 2;
$node->created = $now + $i * 43200;
$node->log = "added $i poll";
$nbchoices = ($i % 4) + 2;
for ($c = 0; $c < $nbchoices; $c++) {
$node->choice[] = array('chtext' => "Choice $c for poll $i");
}
node_save($node);
path_set_alias("node/$node->nid", "content/poll/$i");
path_set_alias("node/$node->nid/results", "content/poll/$i/results");
// Add some votes
for ($v = 0; $v < ($i % 4) + 5; $v++) {
$c = $v % $nbchoices;
$form_state = array();
$form_state['values']['choice'] = $c;
$form_state['values']['op'] = t('Vote');
drupal_execute('poll_view_voting', $form_state, $node);
}
}
$uid = 6;
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = 'broken';
$node->sticky = 0;
$node->title = "node title 24";
$node->body = str_repeat("node body ($node->type) - 37", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
$node->status = 1;
$node->language = '';
$node->revision = 0;
$node->promote = 0;
$node->created = 1263769200;
$node->log = "added $i node";
node_save($node);
path_set_alias("node/$node->nid", "content/1263769200");

View file

@ -0,0 +1,318 @@
#!/usr/bin/env php
<?php
/**
* Generate content for a Drupal 7 database to test the upgrade process.
*
* Run this script at the root of an existing Drupal 7 installation.
*
* Steps to use this generation script:
* - Install drupal 7.
* - Run this script from your Drupal ROOT directory.
* - Use the dump-database-d7.sh to generate the D7 file
* modules/simpletest/tests/upgrade/database.filled.php
*/
// Define settings.
$cmd = 'index.php';
define('DRUPAL_ROOT', getcwd());
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
$modules_to_enable = array('path', 'poll', 'taxonomy');
// Bootstrap Drupal.
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Enable requested modules
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
include_once './modules/system/system.admin.inc';
$form = system_modules();
foreach ($modules_to_enable as $module) {
$form_state['values']['status'][$module] = TRUE;
}
$form_state['values']['disabled_modules'] = $form['disabled_modules'];
system_modules_submit(NULL, $form_state);
unset($form_state);
// Run cron after installing
drupal_cron_run();
// Create six users
$query = db_insert('users')->fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access'));
for ($i = 0; $i < 6; $i++) {
$name = "test user $i";
$pass = md5("test PassW0rd $i !(.)");
$mail = "test$i@example.com";
$now = mktime(0, 0, 0, 1, $i + 1, 2010);
$query->values(array(db_next_id(), $name, user_hash_password($pass), $mail, 1, $now, $now));
}
$query->execute();
// Create vocabularies and terms
$terms = array();
// All possible combinations of these vocabulary properties.
$hierarchy = array(0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2);
$multiple = array(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1);
$required = array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
$voc_id = 0;
$term_id = 0;
for ($i = 0; $i < 24; $i++) {
$vocabulary = new stdClass;
++$voc_id;
$vocabulary->name = "vocabulary $voc_id (i=$i)";
$vocabulary->machine_name = 'vocabulary_' . $voc_id . '_' . $i;
$vocabulary->description = "description of ". $vocabulary->name;
$vocabulary->multiple = $multiple[$i % 12];
$vocabulary->required = $required[$i % 12];
$vocabulary->relations = 1;
$vocabulary->hierarchy = $hierarchy[$i % 12];
$vocabulary->weight = $i;
taxonomy_vocabulary_save($vocabulary);
$field = array(
'field_name' => 'taxonomy_'. $vocabulary->machine_name,
'module' => 'taxonomy',
'type' => 'taxonomy_term_reference',
'cardinality' => $vocabulary->multiple || $vocabulary->tags ? FIELD_CARDINALITY_UNLIMITED : 1,
'settings' => array(
'required' => $vocabulary->required ? TRUE : FALSE,
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$node_types = $i > 11 ? array('page') : array_keys(node_type_get_types());
foreach ($node_types as $bundle) {
$instance = array(
'label' => $vocabulary->name,
'field_name' => $field['field_name'],
'bundle' => $bundle,
'entity_type' => 'node',
'settings' => array(),
'description' => $vocabulary->help,
'required' => $vocabulary->required,
'widget' => array(),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
'teaser' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
),
);
if ($vocabulary->tags) {
$instance['widget'] = array(
'type' => 'taxonomy_autocomplete',
'module' => 'taxonomy',
'settings' => array(
'size' => 60,
'autocomplete_path' => 'taxonomy/autocomplete',
),
);
}
else {
$instance['widget'] = array(
'type' => 'options_select',
'settings' => array(),
);
}
field_create_instance($instance);
}
$parents = array();
// Vocabularies without hierarchy get one term, single parent vocabularies get
// one parent and one child term. Multiple parent vocabularies get three
// terms: t0, t1, t2 where t0 is a parent of both t1 and t2.
for ($j = 0; $j < $vocabulary->hierarchy + 1; $j++) {
++$term_id;
$term = entity_create('taxonomy_term', array(
'vocabulary_machine_name' => $vocabulary->machine_name,
// For multiple parent vocabularies, omit the t0-t1 relation, otherwise
// every parent in the vocabulary is a parent.
'parent' => $vocabulary->hierarchy == 2 && i == 1 ? array() : $parents,
'name' => "term $term_id of vocabulary $voc_id (j=$j)",
'description' => 'description of ' . $term->name,
'format' => 'filtered_html',
'weight' => $i * 3 + $j,
));
taxonomy_term_save($term);
$terms[] = $term->tid;
$term_vocabs[$term->tid] = 'taxonomy_' . $vocabulary->machine_name;
$parents[] = $term->tid;
}
}
$node_id = 0;
$revision_id = 0;
module_load_include('inc', 'node', 'node.pages');
for ($i = 0; $i < 36; $i++) {
$uid = intval($i / 8) + 3;
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = 'page';
if ($i < 12) {
$node->type = 'page';
}
elseif ($i < 24) {
$node->type = 'story';
}
elseif (module_exists('blog')) {
$node->type = 'blog';
}
$node->sticky = 0;
++$node_id;
++$revision_id;
$node->title = "node title $node_id rev $revision_id (i=$i)";
$node->language = LANGUAGE_NONE;
$body_text = str_repeat("node body ($node->type) - $i", 100);
$node->body[$node->language][0]['value'] = $body_text;
$node->body[$node->language][0]['summary'] = text_summary($body_text);
$node->body[$node->language][0]['format'] = 'filtered_html';
$node->status = intval($i / 4) % 2;
$node->revision = $i < 12;
$node->promote = $i % 2;
$node->created = $now + $i * 86400;
$node->log = "added $i node";
// Make every term association different a little. For nodes with revisions,
// make the initial revision have a different set of terms than the
// newest revision.
$items = array();
if ($node->revision) {
$node_terms = array($terms[$i], $terms[47-$i]);
}
else {
$node_terms = $terms;
unset($node_terms[$i], $node_terms[47 - $i]);
}
foreach ($node_terms as $tid) {
$field_name = $term_vocabs[$tid];
$node->{$field_name}[LANGUAGE_NONE][] = array('tid' => $tid);
}
$node->path = array('alias' => "content/$node->created");
node_save($node);
if ($node->revision) {
$user = user_load($uid + 3);
++$revision_id;
$node->title .= " rev2 $revision_id";
$body_text = str_repeat("node revision body ($node->type) - $i", 100);
$node->body[$node->language][0]['value'] = $body_text;
$node->body[$node->language][0]['summary'] = text_summary($body_text);
$node->body[$node->language][0]['format'] = 'filtered_html';
$node->log = "added $i revision";
$node_terms = $terms;
unset($node_terms[$i], $node_terms[47 - $i]);
foreach ($node_terms as $tid) {
$field_name = $term_vocabs[$tid];
$node->{$field_name}[LANGUAGE_NONE][] = array('tid' => $tid);
}
node_save($node);
}
}
// Create poll content
for ($i = 0; $i < 12; $i++) {
$uid = intval($i / 4) + 3;
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = 'poll';
$node->sticky = 0;
$node->title = "poll title $i";
$node->language = LANGUAGE_NONE;
$node->status = intval($i / 2) % 2;
$node->revision = 1;
$node->promote = $i % 2;
$node->created = REQUEST_TIME + $i * 43200;
$node->runtime = 0;
$node->active = 1;
$node->log = "added $i poll";
$node->path = array('alias' => "content/poll/$i");
$nbchoices = ($i % 4) + 2;
for ($c = 0; $c < $nbchoices; $c++) {
$node->choice[] = array('chtext' => "Choice $c for poll $i", 'chvotes' => 0, 'weight' => 0);
}
node_save($node);
$path = array(
'alias' => "content/poll/$i/results",
'source' => "node/$node->nid/results",
);
path_save($path);
// Add some votes
$node = node_load($node->nid);
$choices = array_keys($node->choice);
$original_user = $GLOBALS['user'];
for ($v = 0; $v < ($i % 4); $v++) {
drupal_static_reset('ip_address');
$_SERVER['REMOTE_ADDR'] = "127.0.$v.1";
$GLOBALS['user'] = drupal_anonymous_user();// We should have already allowed anon to vote.
$c = $v % $nbchoices;
$form_state = array();
$form_state['values']['choice'] = $choices[$c];
$form_state['values']['op'] = t('Vote');
drupal_form_submit('poll_view_voting', $form_state, $node);
}
}
$uid = 6;
$node_type = 'broken';
$user = user_load($uid);
$node = new stdClass();
$node->uid = $uid;
$node->type = 'article';
$body_text = str_repeat("node body ($node_type) - 37", 100);
$node->sticky = 0;
$node->title = "node title 24";
$node->language = LANGUAGE_NONE;
$node->body[$node->language][0]['value'] = $body_text;
$node->body[$node->language][0]['summary'] = text_summary($body_text);
$node->body[$node->language][0]['format'] = 'filtered_html';
$node->status = 1;
$node->revision = 0;
$node->promote = 0;
$node->created = 1263769200;
$node->log = "added a broken node";
$node->path = array('alias' => "content/1263769200");
node_save($node);
db_update('node')
->fields(array(
'type' => $node_type,
))
->condition('nid', $node->nid)
->execute();
db_update('field_data_body')
->fields(array(
'bundle' => $node_type,
))
->condition('entity_id', $node->nid)
->condition('entity_type', 'node')
->execute();
db_update('field_revision_body')
->fields(array(
'bundle' => $node_type,
))
->condition('entity_id', $node->nid)
->condition('entity_type', 'node')
->execute();
db_update('field_config_instance')
->fields(array(
'bundle' => $node_type,
))
->condition('bundle', 'article')
->execute();

View file

@ -0,0 +1,28 @@
#!/usr/bin/env php
<?php
/**
* @file
* A command line application to generate proxy classes.
*/
use Drupal\Core\Command\GenerateProxyClassApplication;
use Drupal\Core\DrupalKernel;
use Drupal\Core\ProxyBuilder\ProxyBuilder;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
if (PHP_SAPI !== 'cli') {
return;
}
// Bootstrap.
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
$application = new GenerateProxyClassApplication(new ProxyBuilder());
$application->run();

View file

@ -0,0 +1,70 @@
#!/usr/bin/env php
<?php
/**
* Drupal hash script - to generate a hash from a plaintext password
*
* @param password1 [password2 [password3 ...]]
* Plain-text passwords in quotes (or with spaces backslash escaped).
*/
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
if (PHP_SAPI !== 'cli') {
return;
}
if (version_compare(PHP_VERSION, '5.4.5') < 0) {
$version = PHP_VERSION;
echo <<<EOF
ERROR: This script requires at least PHP version 5.4.5. You invoked it with
PHP version {$version}.
\n
EOF;
exit;
}
$script = basename(array_shift($_SERVER['argv']));
if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {
echo <<<EOF
Generate Drupal password hashes from the shell.
Usage: {$script} [OPTIONS] "<plan-text password>"
Example: {$script} "mynewpassword"
All arguments are long options.
--help Print this page.
"<password1>" ["<password2>" ["<password3>" ...]]
One or more plan-text passwords enclosed by double quotes. The
output hash may be manually entered into the
{users_field_data}.pass field to change a password via SQL to a
known value.
EOF;
exit;
}
// Password list to be processed.
$passwords = $_SERVER['argv'];
$autoloader = require __DIR__ . '/../../autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE);
$kernel->boot();
$password_hasher = $kernel->getContainer()->get('password');
foreach ($passwords as $password) {
print("\npassword: $password \t\thash: ". $password_hasher->hash($password) ."\n");
}
print("\n");

View file

@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
/**
* @file
* Command line token calculator for rebuild.php.
*/
use Drupal\Component\Utility\Crypt;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
if (PHP_SAPI !== 'cli') {
return;
}
require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(DrupalKernel::findSitePath($request));
$timestamp = time();
$token = Crypt::hmacBase64($timestamp, Settings::get('hash_salt'));
print "timestamp=$timestamp&token=$token\n";

1549
web/core/scripts/run-tests.sh Executable file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,4 @@
This file is for testing purposes only.
It is used to test the functionality of drupal_get_filename(). See
BootstrapGetFilenameTestCase::testDrupalGetFilename() for more information.

View file

@ -0,0 +1,664 @@
<?php
/**
* @file
* Unifies formats of transliteration data from various sources.
*
* A few notes about this script:
* - The functions in this file are NOT SECURE, because they use PHP functions
* like eval(). Absolutely do not run this script unless you trust the data
* files used for input.
* - You will need to change the name of this file to remove the .txt extension
* before running it (it has been given this name so that you cannot run it
* by mistake). When you do that, move it out of your web root as well so
* that it cannot be run via a URL, and run the script via the PHP command
* at a command prompt.
* - This script, depending on which portions of it you run, depends on having
* input data from various sources in sub-directories below where this file
* is located. The data inputs are as follows:
* - Existing Drupal Core transliteration data: Sub-directory 'data'; comes
* from core/lib/Drupal/Component/Transliteration/data
* - Midgardmvc data: Sub-directory 'utf8_to_ascii_db'; download from
* https://github.com/bergie/midgardmvc_helper_urlize/downloads
* - CPAN Text-Unidecode data: Sub-directory 'Unidecode'; download from
* http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm
* - Node.js project: Sub-directory 'unidecoder_data'; download from
* https://github.com/bitwalker/stringex/downloads
* - JUnidecode project: Sub-directory 'junidecode'; download source from
* http://www.ippatsuman.com/projects/junidecode/index.html
* - You will also need to make directory 'outdata' to hold output.
* - If you plan to use the 'intl' data, you will also need to have the PECL
* packages 'yaml' and 'intl' installed. See
* http://php.net/manual/install.pecl.downloads.php for generic PECL
* package installation instructions. The following commands on Ubuntu Linux
* will install yaml and intl packages:
* @code
* sudo apt-get install libyaml-dev
* sudo pecl install yaml
* sudo apt-get install php5-intl
* sudo apt-get install libicu-dev
* sudo pecl install intl
* @endcode
* After running these commands, you will need to make sure
* 'extension=intl.so' and 'extension=yaml.so' are added to the php.ini file
* that is in use for the PHP command-line command.
* - When you have collected all of the data and installed the required
* packages, you will need to find the specific commands below that you want
* to use and un-comment them. The preferred data source for Drupal Core is
* the PECL 'intl' package, and the line that needs to be un-commented in
* order to make a Drupal Core patch is:
* @code
* patch_drupal('outdata');
* @endcode
* - The functions are documented in more detail in their headers where they
* are defined. Many have parameters that you can use to change the output.
*/
// Commands to read various data sources:
// $data = read_drupal_data();
// $data = read_midgard_data();
// $data = read_cpan_data();
// $data = read_nodejs_data();
// $data = read_intl_data();
// $data = read_junidecode_data();
// After running a read_*_data() function, you can print out the data
// (it will make a LOT of output):
// print_r($data);
// Command to read in all of data sources and output in CSV format, explaining
// the differences:
// read_all_to_csv();
// Command to patch Drupal Core data, using the intl data set, and put the
// resulting changed data files in the 'outdata' directory:
patch_drupal('outdata');
/**
* Reads in all transliteration data and outputs differences in CSV format.
*
* Each data set is compared to the Drupal Core reference data set, and the
* differences are noted. The data must be in the locations noted in the
* file header above. The CSV output has several columns. The first one is the
* Unicode character code. The next columns contain the transliteration of
* that character in each of the data sets. The last column, tells what the
* differences are between the Drupal Core reference set and the other data
* sets:
* - missing: The target set is missing data that the Drupal set has.
* - provided: The target set has provided data that Drupal does not have.
* - case: The target and Drupal set output differ only in upper/lower case.
* - different: The target and Drupal set output differ in more than just case.
*
* @param bool $print_all
* TRUE to print all data; FALSE (default) to print just data where there
* are differences between the Drupal set and other data sources.
* @param bool $print_missing
* TRUE to print cases where one of the non-Drupal sets is missing information
* and that is the only difference; FALSE (default) to include these rows.
*/
function read_all_to_csv($print_all = FALSE, $print_missing = FALSE) {
$data = array();
$types = array('drupal', 'midgard', 'cpan', 'nodejs', 'junidecode', 'intl');
// Alternatively, if you just want to compare a couple of data sets, you can
// uncomment and edit the following line:
// $types = array('drupal', 'intl');
// Read in all the data.
foreach ($types as $type) {
$data[$type] = call_user_func('read_' . $type . '_data');
}
// Print CSV header row.
print "character,";
print implode(',', $types);
print ",why\n";
// Go through all the banks of character data.
for ($bank = 0; $bank < 256; $bank++) {
// Go through characters in bank; skip pure ASCII characters.
$start = ($bank == 0) ? 0x80 : 0;
for ($chr = $start; $chr < 256; $chr++) {
// Gather the data together for this character.
$row = array();
foreach ($types as $type) {
$row[$type] = (isset($data[$type][$bank][$chr]) && is_string($data[$type][$bank][$chr])) ? $data[$type][$bank][$chr] : '';
}
// Only print if there are differences or we are printing all data.
$print = $print_all;
$ref = $row['drupal'];
$why = array();
foreach ($types as $type) {
// Try to characterize what the differences are.
if ($row[$type] != $ref) {
if ($row[$type] == '') {
$why['missing'] = 'missing';
if ($print_missing) {
$print = TRUE;
}
}
elseif ($ref == '') {
$why['provided'] = 'provided';
$print = TRUE;
}
elseif ($row[$type] == strtolower($ref) || $row[$type] == strtoupper($ref)) {
$why['case'] = 'case';
$print = TRUE;
}
else {
$why['different'] = 'different';
$print = TRUE;
}
}
}
// Print the data line.
if ($print) {
print '0x' . sprintf('%04x', 256 * $bank + $chr) . ',';
foreach ($row as $out) {
print '"' . addcslashes($out, '"') . '", ';
}
print implode(':', $why);
print "\n";
}
}
}
}
/**
* Reads in 'intl' transliteration data and writes out changed Drupal files.
*
* Writes out the Drupal data files that would have to change to make our data
* match the intl data set.
*
* @param string $outdir
* Directory to put the patched data files in (under where the script is
* being run).
*/
function patch_drupal($outdir) {
$data = array();
// Note that this is hard-wired below. Changing this line will have no
// effect except to break this function.
$types = array('drupal', 'intl');
// Read in all the data.
foreach ($types as $type) {
$data[$type] = call_user_func('read_' . $type . '_data');
}
// Go through all the banks of character data.
for ($bank = 0; $bank < 256; $bank++) {
$print_bank = FALSE;
// Go through characters in bank; skip pure ASCII characters.
$start = ($bank == 0) ? 0x80 : 0;
$newdata = array();
for ($chr = 0; $chr < 256; $chr++) {
// Fill up the start of the ASCII range.
if ($chr < $start) {
$newdata[$chr] = chr($chr);
continue;
}
// Figure out what characters we actually have.
$drupal = isset($data['drupal'][$bank][$chr]) ? $data['drupal'][$bank][$chr] : NULL;
// Note that for intl, we only want to keep the transliteration if it
// has something other than '' in it.
$intl = isset($data['intl'][$bank][$chr]) && $data['intl'][$bank][$chr] != '' ? $data['intl'][$bank][$chr] : NULL;
// Make sure we have something in the Drupal data set, in case we need
// to print.
$newdata[$chr] = $drupal;
if (!isset($intl)) {
continue;
}
if (!isset($drupal) || $drupal != $intl) {
$print_bank = TRUE;
$newdata[$chr] = $intl;
}
}
// If we found a difference, output a data file.
if ($print_bank) {
write_data_file($newdata, $bank, $outdir);
}
}
}
/**
* Reads in the Drupal Core generic transliteration data set.
*
* The data is expected to be in files xNN.php in directory 'data' under
* this file's directory.
*
* @return array
* Nested array of transliteration data. Outer keys are the first two
* bytes of Unicode characters (or 0 for base ASCII characters). The next
* level is the other two bytes, and the values are the transliterations.
*
* @see PhpTransliteration::readGenericData()
*/
function read_drupal_data() {
$dir = __DIR__ . '/data';
$out = array();
// Read data files.
for ($bank = 0; $bank < 256; $bank++) {
$base = array();
$file = $dir . '/x' . sprintf('%02x', $bank) . '.php';
if (is_file($file)) {
include($file);
}
$out[$bank] = $base;
}
return $out;
}
/**
* Reads in the MidgardMVC transliteration data.
*
* The data is expected to be in files xNN.php in directory utf8_to_ascii_db
* under the directory where this file resides. It can be downloaded from
* https://github.com/bergie/midgardmvc_helper_urlize/downloads.
*
* @return array
* Nested array of transliteration data. Outer keys are the first two
* bytes of Unicode characters (or 0 for base ASCII characters). The next
* level is the other two bytes, and the values are the transliterations.
*/
function read_midgard_data() {
$dir = __DIR__ . '/utf8_to_ascii_db';
$out = array();
// Read data files.
for ($bank = 0; $bank < 256; $bank++) {
$UTF8_TO_ASCII = array($bank => array());
$file = $dir . '/x' . sprintf('%02x', $bank) . '.php';
if (is_file($file)) {
include($file);
}
$base = $UTF8_TO_ASCII[$bank];
// For unknown characters, these files have '[?]' in them. Replace with
// NULL for compatibility with our data.
$base = array_map('_replace_question_with_null', $base);
$out[$bank] = $base;
}
return $out;
}
/**
* Reads in the CPAN Text::Unidecode data set.
*
* The data is expected to be in files xNN.pm in directory 'Unidecode' under
* this file's directory. It can be downloaded from
* http://search.cpan.org/~sburke/Text-Unidecode-0.04/lib/Text/Unidecode.pm.
*
* @return array
* Nested array of transliteration data. Outer keys are the first two
* bytes of Unicode characters (or 0 for base ASCII characters). The next
* level is the other two bytes, and the values are the transliterations.
*/
function read_cpan_data() {
$dir = __DIR__ . '/Unidecode';
$out = array();
// Read data files.
for ($bank = 0; $bank < 256; $bank++) {
$base = array();
$file = $dir . '/x' . sprintf('%02x', $bank) . '.pm';
if (is_file($file)) {
$base = _cpan_read_file($file);
}
$out[$bank] = $base;
}
return $out;
}
/**
* Reads in the data in a single file from the Text::Unidecode CPAN project.
*
* @param string $file
* File to read from.
*
* @return array
* Data read from the file.
*
* @see read_cpan_data()
*/
function _cpan_read_file($file) {
$contents = file($file);
$save = '';
foreach ($contents as $line) {
// Discard lines starting with # or $. The first line seems to have a
// comment starting with #, the second has a Perl line like
// $Text::Unidecode::Char[0x04] = [, -- and we do not want either.
if (preg_match('|^\s*[#\$]|', $line)) {
continue;
}
// Discard lines ending with semi-colons, which we also don't want
// (there seem to be two of these lines at the end of the files).
if (preg_match('|;\s*$|', $line)) {
continue;
}
// Replace '[?]' with nothing (that means "don't know how to
// transliterate"). In some files, this is encoded as qq{[?]} or
// qq{[?] } instead.
$line = str_replace('qq{[?]}', 'NULL', $line);
$line = str_replace('qq{[?] }', 'NULL', $line);
$line = str_replace("'[?]'", 'NULL', $line);
// Replace qq{} with either "" or '' or nothing, depending on what is
// inside it.
$line = str_replace('qq{\{}', "'{'", $line);
$line = str_replace('qq{\}}', "'}'", $line);
$line = str_replace('qq{\} }', "'} '", $line);
$line = str_replace("qq{\\\\}", '"\\\\"', $line);
$line = str_replace("qq{\\", "qq{'", $line);
$line = str_replace("qq{\"'}", "\"\\\"'\"", $line);
$line = preg_replace('|qq\{([^\'\}]+)\}|', "'$1'", $line);
$line = preg_replace('|qq\{([^\}]+)\}|', '"$1"', $line);
$save .= $line;
}
// Now we should have a string that looks like:
// 'a', 'b', ...
// Evaluate as an array.
$save = 'return array(' . $save . ');';
$data = @eval($save);
if (isset($data) && is_array($data)) {
$data = array_map('_replace_hex_with_character', $data);
}
else {
// There was a problem, so throw an error and exit.
print "Problem in evaluating $file\n";
print $save;
eval($save);
exit();
}
// For unknown characters, these files may still have '[?]' in them. Replace
// with NULL for compatibility with our data.
$data = array_map('_replace_question_with_null', $data);
return $data;
}
/**
* Reads in the Node.js transliteration data.
*
* The data is expected to be in files xNN.yml in directory unidecoder_data
* under the directory where this file resides. It can be downloaded from
* https://github.com/bitwalker/stringex/downloads. You also need the PECL
* 'yaml' extension installed for this function to work.
*
* @return array
* Nested array of transliteration data. Outer keys are the first two
* bytes of Unicode characters (or 0 for base ASCII characters). The next
* level is the other two bytes, and the values are the transliterations.
*/
function read_nodejs_data() {
$dir = __DIR__ . '/unidecoder_data';
$out = array();
// Read data files.
for ($bank = 0; $bank < 256; $bank++) {
$base = array();
$file = $dir . '/x' . sprintf('%02x', $bank) . '.yml';
if (is_file($file)) {
$base = yaml_parse_file($file);
// For unknown characters, these files have '[?]' in them. Replace with
// NULL for compatibility with our data.
$base = array_map('_replace_question_with_null', $base);
}
$out[$bank] = $base;
}
return $out;
}
/**
* Loads the PECL 'intl' Transliterator class's transliteration data.
*
* You need to have the PECL 'intl' package installed for this to work.
*
* @return array
* Nested array of transliteration data. Outer keys are the first two
* bytes of Unicode characters (or 0 for base ASCII characters). The next
* level is the other two bytes, and the values are the transliterations.
*/
function read_intl_data() {
// In order to transliterate, you first have to create a transliterator
// object. This needs a list of transliteration operations. You can get a
// list of available operations with:
// print_r(Transliterator::listIDs()); exit();
// And a few of these are documented on
// http://userguide.icu-project.org/transforms/general and
// http://www.unicode.org/reports/tr15/ (for normalizations).
// There are also maps to the Unicode characters at:
// http://www.unicode.org/roadmaps/bmp/
// http://www.unicode.org/charts/nameslist/
$ops = '';
// The first step in any transform: separate out accents and remove them.
$ops .= 'NFD; [:Nonspacing Mark:] Remove; NFC;';
// Then you need to do a bunch of language-specific or script-specific
// transliterations. Here is hopefully a representative set. There are
// quite a few scripts that don't appear to have rules currently, such
// as Etheopian.
$ops .= 'Greek-Latin; ';
$ops .= 'Cyrillic-Latin; ';
$ops .= 'Armenian-Latin; ';
$ops .= 'Hebrew-Latin; ';
$ops .= 'Arabic-Latin; ';
$ops .= 'Syriac-Latin; ';
$ops .= 'Thaana-Latin; ';
$ops .= 'Devanagari-Latin; ';
$ops .= 'Bengali-Latin; ';
$ops .= 'Gurmukhi-Latin; ';
$ops .= 'Gujarati-Latin; ';
$ops .= 'Oriya-Latin; ';
$ops .= 'Tamil-Latin; ';
$ops .= 'Telugu-Latin; ';
$ops .= 'Kannada-Latin; ';
$ops .= 'Malayalam-Latin; ';
$ops .= 'Thai-Latin; ';
$ops .= 'Georgian-Latin; ';
$ops .= 'Hangul-Latin; ';
$ops .= 'Mongolian-Latin/BGN; ';
$ops .= 'Jamo-Latin; ';
$ops .= 'Katakana-Latin; ';
$ops .= 'Any-Latin; ';
// Finally, after transforming to Latin, transform to ASCII.
$ops .= 'Latin-ASCII; ';
// Remove any remaining accents and recompose.
$ops .= 'NFD; [:Nonspacing Mark:] Remove; NFC;';
$trans = Transliterator::create($ops);
$out = array();
// Transliterate all possible characters.
for ($bank = 0; $bank < 256; $bank++) {
$data = array();
for ($chr = 0; $chr < 256; $chr++) {
// Skip the UTF-16 and "private use" ranges completely.
$OK = ($bank <= 0xd8 || $bank > 0xf8);
$result = $OK ? $trans->transliterate(mb_convert_encoding(pack('n', 256 * $bank + $chr), 'UTF-8', 'UTF-16BE')) : '';
// See if we have managed to transliterate this to ASCII or not. If not,
// return NULL instead of this character.
$max = chr(127);
foreach (preg_split('//u', $result, 0, PREG_SPLIT_NO_EMPTY) as $character) {
if ($character > $max) {
$OK = $OK && FALSE;
break;
}
}
$data[$chr] = ($OK) ? $result : NULL;
}
$out[$bank] = $data;
}
return $out;
}
/**
* Reads in the JUnidecode data set.
*
* The data is expected to be in files XNN.java in directory 'junidecode' under
* this file's directory. It can be downloaded from
* http://www.ippatsuman.com/projects/junidecode/index.html
*
* @return array
* Nested array of transliteration data. Outer keys are the first two
* bytes of Unicode characters (or 0 for base ASCII characters). The next
* level is the other two bytes, and the values are the transliterations.
*/
function read_junidecode_data() {
$dir = __DIR__ . '/junidecode';
$out = array();
// Read data files.
for ($bank = 0; $bank < 256; $bank++) {
$base = array();
$file = $dir . '/X' . sprintf('%02x', $bank) . '.java';
if (is_file($file)) {
$base = _junidecode_read_file($file);
}
$out[$bank] = $base;
}
return $out;
}
/**
* Reads in the data in a single file from the JUnidecode project.
*
* @param string $file
* File to read from.
*
* @return array
* Data read from the file.
*
* @see read_junidecode_data()
*/
function _junidecode_read_file($file) {
$contents = file($file);
$save = '';
foreach ($contents as $line) {
// Discard lines starting with * or / or package or class or public or },
// to get rid of comments and Java code.
if (preg_match('|^\s*[\*/\}]|', $line)) {
continue;
}
if (preg_match('/^\s*package|public|class/', $line)) {
continue;
}
// Some of the lines look like this:
// new String("" + (char) 0x00), // 0x00
// Transform to be '0x00,'
$line = preg_replace('|^\s*new\s+String\s*\(\s*""\s*\+\s*\(char\)\s+0x([0-9]+).*$|', '0x$1,', $line);
// Strings are in double quotes, yet many have \' in them.
$line = str_replace("\'", "'", $line);
// Everything else should probably be OK -- the lines are like:
// "Ie", // 0x00
$save .= $line;
}
// Evaluate as an array.
$save = 'return array(' . $save . ');';
$data = @eval($save);
if (isset($data) && is_array($data)) {
$data = array_map('_replace_hex_with_character', $data);
$data = array_map('_replace_question_with_null', $data);
}
else {
// There was a problem, so throw an error and exit.
print "Problem in evaluating $file\n";
print $save;
eval($save);
exit();
}
return $data;
}
/**
* Callback for array_map(): Returns $data, with '[?]' replaced with NULL.
*/
function _replace_question_with_null($data) {
return ($data == '[?]' || $data == '[?] ') ? NULL : $data;
}
/**
* Callback for array_map(): Replaces '\xNN' with the actual character.
*/
function _replace_hex_with_character($item) {
if (strpos($item, '\x') === 0) {
$item = eval($item);
}
return $item;
}
/**
* Writes a data file out in the standard Drupal Core data format.
*
* @param array $data
* Array of data to write out.
* @param string $bank
* Bank of characters it belongs to.
* @param string $dir
* Output directory.
*/
function write_data_file($data, $bank, $outdir) {
$dir = __DIR__ . '/' . $outdir;
$file = $dir . '/x' . sprintf('%02x', $bank) . '.php';
$out = '';
$out .= "<?php\n\n/**\n * @file\n * Generic transliteration data for the PhpTransliteration class.\n */\n\n\$base = array(\n";
// The 00 file skips the ASCII range
$start = 0;
if ($bank == 0) {
$start = 0x80;
$out .= " // Note: to save memory plain ASCII mappings have been left out.\n";
}
for ($line = $start; $line <= 0xf0; $line += 0x10) {
$out .= ' 0x' . sprintf('%02X', $line) . ' =>';
$elems = array_values(array_slice($data, $line, 16));
for ($i = 0; $i < 16; $i++ ) {
if (isset($elems[$i])) {
$out .= " '" . addcslashes($elems[$i], "'\\") . "',";
}
else {
$out .= ' NULL,';
}
}
$out .= "\n";
}
$out .= ");\n";
file_put_contents($file, $out);
}

View file

@ -0,0 +1,99 @@
#!/bin/php
<?php
/**
* @file
* Updates CLDR codes in CountryManager.php to latest data.
*
* We rely on the CLDR data set, because it is easily accessible, scriptable,
* and in the right human-readable format.
*/
// Determine DRUPAL_ROOT.
$dir = dirname(__FILE__);
while (!defined('DRUPAL_ROOT')) {
if (is_dir($dir . '/core')) {
define('DRUPAL_ROOT', $dir);
}
$dir = dirname($dir);
}
// Determine source data file URI to process.
$uri = DRUPAL_ROOT . '/territories.json';
if (!file_exists($uri)) {
$usage = <<< USAGE
- Choose the latest release data from http://cldr.unicode.org/index/downloads
and download the json.zip file.
- Unzip the json.zip file and place the main/en/territories.json in the
Drupal root directory.
- Run this script.
USAGE;
exit('CLDR data file not found. (' . $uri . ")\n\n" . $usage . "\n");
}
// Fake the t() function used in CountryManager.php instead of attempting a full
// Drupal bootstrap of core/includes/bootstrap.inc (where t() is declared).
if (!function_exists('t')) {
function t($string) {
return $string;
}
}
// Read in existing codes.
// @todo Allow to remove previously existing country codes.
// @see https://www.drupal.org/node/1436754
require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManagerInterface.php';
require_once DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php';
$existing_countries = \Drupal\Core\Locale\CountryManager::getStandardList();
$countries = $existing_countries;
// Parse the source data into an array.
$data = json_decode(file_get_contents($uri));
foreach ($data->main->en->localeDisplayNames->territories as $code => $name) {
// Use any alternate codes the Drupal community wishes to.
$alt_codes = array(
// 'CI-alt-variant', // Use CI-alt-variant instead of the CI entry.
);
if (in_array($code, $alt_codes)) {
// Just use the first 2 character part of the alt code.
$code = strtok($code, '-');
}
// Skip any codes we wish to exclude from our country list.
$exclude_codes = array(
'EU', // The European Union is not a country.
'ZZ', // Don't allow "Unknown Region".
);
if (in_array($code, $exclude_codes)) {
continue;
}
// Ignore every territory that doesn't have a 2 character code.
if (strlen($code) !== 2) {
continue;
}
$countries[(string) $code] = $name;
}
if (empty($countries)) {
echo 'ERROR: Did not find expected country names.' . PHP_EOL;
exit;
}
// Sort by country code (to minimize diffs).
ksort($countries);
// Produce PHP code.
$out = '';
foreach ($countries as $code => $name) {
// For .po translation file's sake, use double-quotes instead of escaped
// single-quotes.
$name = (strpos($name, '\'') !== FALSE ? '"' . $name . '"' : "'" . $name . "'");
$out .= ' ' . var_export($code, TRUE) . ' => t(' . $name . '),' . "\n";
}
// Replace the actual PHP code in standard.inc.
$file = DRUPAL_ROOT . '/core/lib/Drupal/Core/Locale/CountryManager.php';
$content = file_get_contents($file);
$content = preg_replace('/(\$countries = array\(\n)(.+?)(^\s+\);)/ms', '$1' . $out . '$3', $content);
file_put_contents($file, $content);