Skip to content
GitLab
Explore
Sign in
project
drupal
Compare revisions
956c27fd269e57fbaf4816c5c6e21caa3fe8c2f6 to 8.0-alpha6
Hide whitespace changes
Inline
Side-by-side
core/modules/comment/comment.module
View file @
172cd265
...
...
@@ -1731,3 +1731,20 @@ function comment_library_info() {
);
return
$libraries
;
}
/**
* #post_render_cache callback; replaces the placeholder with the comment form.
*
* @param array $context
* An array with the following keys:
* - entity_type: an entity type
* - entity_id: an entity ID
* - field_name: a comment field name
*
* @return array $element
* The updated $element.
*/
function
comment_replace_form_placeholder
(
array
$context
)
{
$entity
=
entity_load
(
$context
[
'entity_type'
],
$context
[
'entity_id'
]);
return
comment_add
(
$entity
,
$context
[
'field_name'
]);
}
core/modules/comment/lib/Drupal/comment/Plugin/Field/FieldFormatter/CommentDefaultFormatter.php
View file @
172cd265
...
...
@@ -138,7 +138,24 @@ public function viewElements(FieldItemListInterface $items) {
if
(
$status
==
COMMENT_OPEN
&&
$comment_settings
[
'form_location'
]
==
COMMENT_FORM_BELOW
)
{
// Only show the add comment form if the user has permission.
if
(
$this
->
currentUser
->
hasPermission
(
'post comments'
))
{
$output
[
'comment_form'
]
=
comment_add
(
$entity
,
$field_name
);
// All users in the "anonymous" role can use the same form: it is fine
// for this form to be stored in the render cache.
if
(
$this
->
currentUser
->
isAnonymous
())
{
$output
[
'comment_form'
]
=
comment_add
(
$entity
,
$field_name
);
}
// All other users need a user-specific form, which would break the
// render cache: hence use a #post_render_cache callback.
else
{
$output
[
'comment_form'
]
=
array
(
'#type'
=>
'render_cache_placeholder'
,
'#callback'
=>
'comment_replace_form_placeholder'
,
'#context'
=>
array
(
'entity_type'
=>
$entity
->
entityType
(),
'entity_id'
=>
$entity
->
id
(),
'field_name'
=>
$field_name
),
);
}
}
}
...
...
core/modules/content_translation/content_translation.module
View file @
172cd265
...
...
@@ -156,7 +156,7 @@ function content_translation_menu() {
if
(
content_translation_enabled
(
$entity_type
))
{
$path
=
_content_translation_link_to_router_path
(
$entity_type
,
$info
[
'links'
][
'canonical'
]);
$entity_position
=
count
(
explode
(
'/'
,
$path
))
-
1
;
$keys
=
array_flip
(
array
(
'load_arguments'
));
$keys
=
array_flip
(
array
(
'theme_callback'
,
'theme_arguments'
,
'load_arguments'
));
$menu_info
=
array_intersect_key
(
$info
[
'translation'
][
'content_translation'
],
$keys
)
+
array
(
'file'
=>
'content_translation.pages.inc'
);
$item
=
array
();
...
...
core/modules/contextual/contextual.module
View file @
172cd265
...
...
@@ -6,6 +6,21 @@
* Adds contextual links to perform actions related to elements on a page.
*/
/**
* Implements hook_menu().
*/
function
contextual_menu
()
{
// @todo Remove this menu item in http://drupal.org/node/1954892 when theme
// callbacks are replaced with something else.
$items
[
'contextual/render'
]
=
array
(
'route_name'
=>
'contextual.render'
,
'theme callback'
=>
'ajax_base_page_theme'
,
'type'
=>
MENU_CALLBACK
,
);
return
$items
;
}
/**
* Implements hook_toolbar().
*/
...
...
core/modules/contextual/contextual.routing.yml
View file @
172cd265
...
...
@@ -2,7 +2,5 @@ contextual.render:
path
:
'
/contextual/render'
defaults
:
_controller
:
'
\Drupal\contextual\ContextualController::render'
options
:
_theme
:
ajax_base_page
requirements
:
_permission
:
'
access
contextual
links'
core/modules/contextual/css/contextual.theme.css
View file @
172cd265
...
...
@@ -91,9 +91,7 @@
}
.contextual-region
.contextual
.contextual-links
a
{
background-color
:
#fff
;
/* This is an unfortunately necessary use of !important to prevent white
* links on a white background or some similar illegible combination. */
color
:
#333
!important
;
color
:
#333
;
display
:
block
;
font-family
:
sans-serif
;
font-size
:
small
;
...
...
core/modules/edit/edit.module
View file @
172cd265
...
...
@@ -17,6 +17,26 @@
use
Drupal\entity\Entity\EntityDisplay
;
use
Drupal\user\TempStoreFactory
;
/**
* Implements hook_menu().
*/
function
edit_menu
()
{
// @todo Remove these menu items in http://drupal.org/node/1954892 when theme
// callbacks are replaced with something else.
$items
[
'edit/metadata'
]
=
array
(
'route_name'
=>
'edit.metadata'
,
'theme callback'
=>
'ajax_base_page_theme'
,
'type'
=>
MENU_CALLBACK
,
);
$items
[
'edit/form/%/%/%/%/%'
]
=
array
(
'route_name'
=>
'edit.field_form'
,
'theme callback'
=>
'ajax_base_page_theme'
,
'type'
=>
MENU_CALLBACK
,
);
return
$items
;
}
/**
* Implements hook_permission().
*/
...
...
core/modules/edit/edit.routing.yml
View file @
172cd265
...
...
@@ -2,10 +2,9 @@ edit.metadata:
path
:
'
/edit/metadata'
defaults
:
_controller
:
'
\Drupal\edit\EditController::metadata'
options
:
_theme
:
ajax_base_page
requirements
:
_permission
:
'
access
in-place
editing'
edit.attachments
:
path
:
'
/edit/attachments'
defaults
:
...
...
@@ -17,9 +16,6 @@ edit.field_form:
path
:
'
/edit/form/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}'
defaults
:
_controller
:
'
\Drupal\edit\EditController::fieldForm'
options
:
_access_mode
:
'
ALL'
_theme
:
ajax_base_page
requirements
:
_permission
:
'
access
in-place
editing'
_access_edit_entity_field
:
'
TRUE'
...
...
core/modules/editor/editor.module
View file @
172cd265
...
...
@@ -139,6 +139,21 @@ function editor_library_info() {
return
$libraries
;
}
/**
* Implements hook_menu().
*/
function
editor_menu
()
{
// @todo Remove this menu item in http://drupal.org/node/1954892 when theme
// callbacks are replaced with something else.
$items
[
'editor/%/%/%/%/%'
]
=
array
(
'route_name'
=>
'editor.field_untransformed_text'
,
'theme callback'
=>
'ajax_base_page_theme'
,
'type'
=>
MENU_CALLBACK
,
);
return
$items
;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
...
...
core/modules/editor/editor.routing.yml
View file @
172cd265
...
...
@@ -2,8 +2,6 @@ editor.field_untransformed_text:
path
:
'
/editor/{entity_type}/{entity}/{field_name}/{langcode}/{view_mode_id}'
defaults
:
_controller
:
'
\Drupal\editor\EditorController::getUntransformedText'
options
:
_theme
:
ajax_base_page
requirements
:
_permission
:
'
access
in-place
editing'
_access_edit_entity_field
:
'
TRUE'
...
...
core/modules/file/file.module
View file @
172cd265
...
...
@@ -37,6 +37,21 @@ function file_help($path, $arg) {
}
}
/**
* Implements hook_menu().
*/
function
file_menu
()
{
$items
=
array
();
$items
[
'file/ajax'
]
=
array
(
'route_name'
=>
'file.ajax_upload'
,
'theme callback'
=>
'ajax_base_page_theme'
,
'type'
=>
MENU_CALLBACK
,
);
return
$items
;
}
/**
* Implements hook_element_info().
*
...
...
core/modules/file/file.routing.yml
View file @
172cd265
...
...
@@ -2,8 +2,6 @@ file.ajax_upload:
path
:
'
/file/ajax'
defaults
:
_controller
:
'
\Drupal\file\Controller\FileWidgetAjaxController::upload'
options
:
_theme
:
ajax_base_page
requirements
:
_permission
:
'
access
content'
...
...
core/modules/migrate/config/migrate.migration.d6_system_cron.yml
0 → 100644
View file @
172cd265
id
:
d6_system_cron
source
:
plugin
:
drupal6_variable
variables
:
-
cron_threshold_warning
-
cron_threshold_error
-
cron_last
process
:
'
threshold:warning'
:
cron_threshold_warning
'threshold:error': cron_threshold_error
destination
:
plugin
:
d8_config
config_name
:
system.cron
core/modules/migrate/config/migrate.migration.d6_system_rss.yml
0 → 100644
View file @
172cd265
id
:
d6_system_rss
source
:
plugin
:
drupal6_variable
variables
:
-
feed_default_items
process
:
'
items:limit'
:
feed_default_items
destination
:
plugin
:
d8_config
config_name
:
system.rss
core/modules/migrate/config/migrate.migration.d6_system_site.yml
0 → 100644
View file @
172cd265
id
:
d6_system_site
source
:
plugin
:
drupal6_variable
variables
:
-
site_name
-
site_mail
-
site_slogan
-
site_frontpage
-
site_403
-
site_404
-
drupal_weight_select_max
-
admin_compact_mode
process
:
name
:
site_name
mail
:
site_mail
slogan
:
site_slogan
'
page:front'
:
site_frontpage
'
page:403'
:
site_403
'
page:404'
:
site_404
weight_select_max
:
drupal_weight_select_max
admin_compact_mode
:
admin_compact_mode
destination
:
plugin
:
d8_config
config_name
:
system.site
core/modules/migrate/lib/Drupal/migrate/Entity/Migration.php
0 → 100644
View file @
172cd265
<?php
/**
* @file
* Contains \Drupal\migrate\Entity\Migration.
*/
namespace
Drupal\migrate\Entity
;
use
Drupal\Core\Config\Entity\ConfigEntityBase
;
use
Drupal\migrate\MigrateException
;
use
Drupal\migrate\Plugin\MigrateIdMapInterface
;
/**
* Defines the Migration entity.
*
* The migration entity stores the information about a single migration, like
* the source, process and destination plugins.
*
* @EntityType(
* id = "migration",
* label = @Translation("Migration"),
* module = "migrate",
* controllers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
* "list" = "Drupal\Core\Config\Entity\DraggableListController",
* "access" = "Drupal\Core\Entity\EntityAccessController",
* "form" = {
* "add" = "Drupal\Core\Entity\EntityFormController",
* "edit" = "Drupal\Core\Entity\EntityFormController",
* "delete" = "Drupal\Core\Entity\EntityFormController"
* }
* },
* config_prefix = "migrate.migration",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "weight" = "weight",
* "uuid" = "uuid"
* }
* )
*/
class
Migration
extends
ConfigEntityBase
implements
MigrationInterface
{
/**
* The migration ID (machine name).
*
* @var string
*/
public
$id
;
/**
* The migration UUID.
*
* This is assigned automatically when the migration is created.
*
* @var string
*/
public
$uuid
;
/**
* The human-readable label for the migration.
*
* @var string
*/
public
$label
;
/**
* The plugin ID for the row.
*
* @var string
*/
public
$row
;
/**
* The source configuration, with at least a 'plugin' key.
*
* Used to initialize the $sourcePlugin.
*
* @var array
*/
public
$source
;
/**
* The source plugin.
*
* @var \Drupal\migrate\Plugin\MigrateSourceInterface
*/
protected
$sourcePlugin
;
/**
* The configuration describing the process plugins.
*
* @var array
*/
public
$process
;
/**
* The destination configuration, with at least a 'plugin' key.
*
* Used to initialize $destinationPlugin.
*
* @var array
*/
public
$destination
;
/**
* The destination plugin.
*
* @var \Drupal\migrate\Plugin\MigrateDestinationInterface
*/
protected
$destinationPlugin
;
/**
* The identifier map data.
*
* Used to initialize $idMapPlugin.
*
* @var string
*/
public
$idMap
=
array
();
/**
* The identifier map.
*
* @var \Drupal\migrate\Plugin\MigrateIdMapInterface
*/
protected
$idMapPlugin
;
/**
* The source identifiers.
*
* An array of source identifiers: the keys are the name of the properties,
* the values are dependent on the ID map plugin.
*
* @var array
*/
public
$sourceIds
=
array
();
/**
* The destination identifiers.
*
* An array of destination identifiers: the keys are the name of the
* properties, the values are dependent on the ID map plugin.
*
* @var array
*/
public
$destinationIds
=
array
();
/**
* Information on the highwater mark.
*
* @var array
*/
public
$highwaterProperty
;
/**
* Indicate whether the primary system of record for this migration is the
* source, or the destination (Drupal). In the source case, migration of
* an existing object will completely replace the Drupal object with data from
* the source side. In the destination case, the existing Drupal object will
* be loaded, then changes from the source applied; also, rollback will not be
* supported.
*
* @var string
*/
public
$systemOfRecord
=
self
::
SOURCE
;
/**
* Specify value of needs_update for current map row. Usually set by
* MigrateFieldHandler implementations.
*
* @var int
*/
public
$needsUpdate
=
MigrateIdMapInterface
::
STATUS_IMPORTED
;
/**
* @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
protected
$highwaterStorage
;
/**
* @var bool
*/
public
$trackLastImported
=
FALSE
;
/**
* {@inheritdoc}
*/
public
function
getSourcePlugin
()
{
if
(
!
isset
(
$this
->
sourcePlugin
))
{
$this
->
sourcePlugin
=
\Drupal
::
service
(
'plugin.manager.migrate.source'
)
->
createInstance
(
$this
->
source
[
'plugin'
],
$this
->
source
,
$this
);
}
return
$this
->
sourcePlugin
;
}
/**
* {@inheritdoc}
*/
public
function
getProcessPlugins
(
array
$process
=
NULL
)
{
if
(
!
isset
(
$process
))
{
$process
=
$this
->
process
;
}
$process_plugins
=
array
();
foreach
(
$this
->
getProcessNormalized
(
$process
)
as
$property
=>
$configurations
)
{
$process_plugins
[
$property
]
=
array
();
foreach
(
$configurations
as
$configuration
)
{
if
(
isset
(
$configuration
[
'source'
]))
{
$process_plugins
[
$property
][]
=
\Drupal
::
service
(
'plugin.manager.migrate.process'
)
->
createInstance
(
'get'
,
$configuration
,
$this
);
}
// Get is already handled.
if
(
$configuration
[
'plugin'
]
!=
'get'
)
{
$process_plugins
[
$property
][]
=
\Drupal
::
service
(
'plugin.manager.migrate.process'
)
->
createInstance
(
$configuration
[
'plugin'
],
$configuration
,
$this
);
}
if
(
!
$process_plugins
[
$property
])
{
throw
new
MigrateException
(
"Invalid process configuration for
$property
"
);
}
}
}
return
$process_plugins
;
}
/**
* Resolve shorthands into a list of plugin configurations.
*
* @param array $process
* A process configuration array.
*
* @return array
* The normalized process configuration.
*/
protected
function
getProcessNormalized
(
array
$process
)
{
$normalized_configurations
=
array
();
foreach
(
$process
as
$destination
=>
$configuration
)
{
if
(
is_string
(
$configuration
))
{
$configuration
=
array
(
'plugin'
=>
'get'
,
'source'
=>
$configuration
,
);
}
if
(
isset
(
$configuration
[
'plugin'
]))
{
$configuration
=
array
(
$configuration
);
}
$normalized_configurations
[
$destination
]
=
$configuration
;
}
return
$normalized_configurations
;
}
/**
* {@inheritdoc}
*/
public
function
getDestinationPlugin
()
{
if
(
!
isset
(
$this
->
destinationPlugin
))
{
$this
->
destinationPlugin
=
\Drupal
::
service
(
'plugin.manager.migrate.destination'
)
->
createInstance
(
$this
->
destination
[
'plugin'
],
$this
->
destination
,
$this
);
}
return
$this
->
destinationPlugin
;
}
/**
* {@inheritdoc}
*/
public
function
getIdMap
()
{
if
(
!
isset
(
$this
->
idMapPlugin
))
{
$configuration
=
$this
->
idMap
;
$plugin
=
isset
(
$configuration
[
'plugin'
])
?
$configuration
[
'plugin'
]
:
'sql'
;
$this
->
idMapPlugin
=
\Drupal
::
service
(
'plugin.manager.migrate.id_map'
)
->
createInstance
(
$plugin
,
$configuration
,
$this
);
}
return
$this
->
idMapPlugin
;
}
/**
* @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface
*/
protected
function
getHighWaterStorage
()
{
if
(
!
isset
(
$this
->
highwaterStorage
))
{
$this
->
highwaterStorage
=
\Drupal
::
keyValue
(
'migrate:highwater'
);
}
return
$this
->
highwaterStorage
;
}
public
function
getHighwater
()
{
return
$this
->
getHighWaterStorage
()
->
get
(
$this
->
id
());
}
public
function
saveHighwater
(
$highwater
)
{
$this
->
getHighWaterStorage
()
->
set
(
$this
->
id
(),
$highwater
);
}
}
core/modules/migrate/lib/Drupal/migrate/Entity/MigrationInterface.php
0 → 100644
View file @
172cd265
<?php
/**
* @file
* Contains \Drupal\migrate\Entity\MigrationInterface.
*/
namespace
Drupal\migrate\Entity
;
use
Drupal\Core\Config\Entity\ConfigEntityInterface
;
/**
* Interface for migrations.
*/
interface
MigrationInterface
extends
ConfigEntityInterface
{
const
SOURCE
=
'source'
;
const
DESTINATION
=
'destination'
;
/**
* Codes representing the current status of a migration, and stored in the
* migrate_status table.
*/
const
STATUS_IDLE
=
0
;
const
STATUS_IMPORTING
=
1
;
const
STATUS_ROLLING_BACK
=
2
;
const
STATUS_STOPPING
=
3
;
const
STATUS_DISABLED
=
4
;
/**
* Message types to be passed to saveMessage() and saved in message tables.
* MESSAGE_INFORMATIONAL represents a condition that did not prevent the
* operation from succeeding - all others represent different severities of
* conditions resulting in a source record not being imported.
*/
const
MESSAGE_ERROR
=
1
;
const
MESSAGE_WARNING
=
2
;
const
MESSAGE_NOTICE
=
3
;
const
MESSAGE_INFORMATIONAL
=
4
;
/**
* Codes representing the result of a rollback or import process.
*/
const
RESULT_COMPLETED
=
1
;
// All records have been processed
const
RESULT_INCOMPLETE
=
2
;
// The process has interrupted itself (e.g., the
// memory limit is approaching)
const
RESULT_STOPPED
=
3
;
// The process was stopped externally (e.g., via
// drush migrate-stop)
const
RESULT_FAILED
=
4
;
// The process had a fatal error
const
RESULT_SKIPPED
=
5
;
// Dependencies are unfulfilled - skip the process
const
RESULT_DISABLED
=
6
;
// This migration is disabled, skipping
/**
* Returns the initialized source plugin.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface
*/
public
function
getSourcePlugin
();
/**
* Returns the process plugins.
*
* @param array $process
* A process configuration array.
*
* @return array
* A list of process plugins.
*/
public
function
getProcessPlugins
(
array
$process
=
NULL
);
/**
* Returns the initialized destination plugin.
*
* @return \Drupal\migrate\Plugin\MigrateDestinationInterface
*/
public
function
getDestinationPlugin
();
/**
* Returns the initialized id_map plugin.
*
* @return \Drupal\migrate\Plugin\MigrateIdMapInterface
*/
public
function
getIdMap
();
/**
* @return int
*/
public
function
getHighwater
();
public
function
saveHighwater
(
$highwater
);
}
core/modules/migrate/lib/Drupal/migrate/MigrateException.php
0 → 100644
View file @
172cd265
<?php
/**
* @file
* Contains \Drupal\migrate\MigrateException.
*/
namespace
Drupal\migrate
;
use
Drupal\migrate\Entity\MigrationInterface
;
use
Drupal\migrate\Plugin\MigrateIdMapInterface
;
/**
* Defines the migrate exception class.
*/
class
MigrateException
extends
\Exception
{
/**
* The level of the error being reported.
*
* The value is a Migration::MESSAGE_* constant.
*
* @var int
*/
protected
$level
;
/**
* The status to record in the map table for the current item.
*
* The value is a MigrateMap::STATUS_* constant.
*
* @var int
*/
protected
$status
;
/**
* Constructs a MigrateException object.
*
* @param string $message
* The message for the exception.
* @param int $code
* The Exception code.
* @param \Exception $previous
* The previous exception used for the exception chaining.
* @param int $level
* The level of the error, a Migration::MESSAGE_* constant.
* @param int $status
* The status of the item for the map table, a MigrateMap::STATUS_*
* constant.
*/
public
function
__construct
(
$message
=
null
,
$code
=
0
,
\Exception
$previous
=
null
,
$level
=
MigrationInterface
::
MESSAGE_ERROR
,
$status
=
MigrateIdMapInterface
::
STATUS_FAILED
)
{
$this
->
level
=
$level
;
$this
->
status
=
$status
;
parent
::
__construct
(
$message
);
}
/**
* Gets the level.
*
* @return int
*/
public
function
getLevel
()
{
return
$this
->
level
;
}
/**
* Gets the status of the current item.
*
* @return int
*/
public
function
getStatus
()
{
return
$this
->
status
;
}
}
core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php
0 → 100644
View file @
172cd265
<?php
/**
* @file
* Contains \Drupal\migrate\MigrateExecutable.
*/
namespace
Drupal\migrate
;
use
Drupal\migrate\Entity\MigrationInterface
;
use
Drupal\migrate\Plugin\MigrateIdMapInterface
;
/**
* Defines a migrate executable class.
*/
class
MigrateExecutable
{
/**
* The migration to do.
*
* @var \Drupal\migrate\Entity\MigrationInterface
*/
protected
$migration
;
/**
* The number of successfully imported rows since feedback was given.
*
* @var int
*/
protected
$successes_since_feedback
;
/**
* The number of rows that were successfully processed.
*
* @var int
*/
protected
$total_successes
;
/**
* Status of one row.
*
* The value is a MigrateIdMapInterface::STATUS_* constant, for example:
* STATUS_IMPORTED.
*
* @var int
*/
protected
$needsUpdate
;
/**
* The number of rows processed.
*
* The total attempted, whether or not they were successful.
*
* @var int
*/
protected
$total_processed
;
/**
* The queued messages not yet saved.
*
* Each element in the array is an array with two keys:
* - 'message': The message string.
* - 'level': The level, a MigrationInterface::MESSAGE_* constant.
*
* @var array
*/
protected
$queuedMessages
=
array
();
/**
* The options that can be set when executing the migration.
*
* Values can be set for:
* - 'limit': Sets a time limit.
*
* @var array
*/
protected
$options
;
/**
* The fraction of the memory limit at which an operation will be interrupted.
* Can be overridden by a Migration subclass if one would like to push the
* envelope. Defaults to 85%.
*
* @var float
*/
protected
$memoryThreshold
=
0.85
;
/**
* The PHP memory_limit expressed in bytes.
*
* @var int
*/
protected
$memoryLimit
;
/**
* The fraction of the time limit at which an operation will be interrupted.
* Can be overridden by a Migration subclass if one would like to push the
* envelope. Defaults to 90%.
*
* @var float
*/
protected
$timeThreshold
=
0.90
;
/**
* The PHP max_execution_time.
*
* @var int
*/
protected
$timeLimit
;
/**
* @var array
*/
protected
$sourceIdValues
;
/**
* @var int
*/
protected
$processed_since_feedback
=
0
;
/**
* The translation manager.
*
* @var \Drupal\Core\StringTranslation\TranslationInterface
*/
protected
$translationManager
;
/**
* @param MigrationInterface $migration
* @param MigrateMessageInterface $message
*
* @throws \Drupal\migrate\MigrateException
*/
public
function
__construct
(
MigrationInterface
$migration
,
MigrateMessageInterface
$message
)
{
$this
->
migration
=
$migration
;
$this
->
message
=
$message
;
$this
->
migration
->
getIdMap
()
->
setMessage
(
$message
);
// Record the memory limit in bytes
$limit
=
trim
(
ini_get
(
'memory_limit'
));
if
(
$limit
==
'-1'
)
{
$this
->
memoryLimit
=
PHP_INT_MAX
;
}
else
{
if
(
!
is_numeric
(
$limit
))
{
$last
=
strtolower
(
substr
(
$limit
,
-
1
));
switch
(
$last
)
{
case
'g'
:
$limit
*=
1024
;
case
'm'
:
$limit
*=
1024
;
case
'k'
:
$limit
*=
1024
;
break
;
default
:
throw
new
MigrateException
(
$this
->
t
(
'Invalid PHP memory_limit !limit'
,
array
(
'!limit'
=>
$limit
)));
}
}
$this
->
memoryLimit
=
$limit
;
}
}
/**
* @return \Drupal\migrate\Source
*/
public
function
getSource
()
{
if
(
!
isset
(
$this
->
source
))
{
$this
->
source
=
new
Source
(
$this
->
migration
,
$this
);
}
return
$this
->
source
;
}
/**
* The rollback action to be saved for the current row.
*
* @var int
*/
public
$rollbackAction
;
/**
* An array of counts. Initially used for cache hit/miss tracking.
*
* @var array
*/
protected
$counts
=
array
();
/**
* When performing a bulkRollback(), the maximum number of items to pass in
* a single call. Can be overridden in derived class constructor.
*
* @var int
*/
protected
$rollbackBatchSize
=
50
;
/**
* The object currently being constructed
* @var \stdClass
*/
protected
$destinationValues
;
/**
* The current data row retrieved from the source.
* @var \stdClass
*/
protected
$sourceValues
;
/**
* Perform an import operation - migrate items from source to destination.
*/
public
function
import
()
{
$return
=
MigrationInterface
::
RESULT_COMPLETED
;
$source
=
$this
->
getSource
();
$destination
=
$this
->
migration
->
getDestinationPlugin
();
$id_map
=
$this
->
migration
->
getIdMap
();
try
{
$source
->
rewind
();
}
catch
(
\Exception
$e
)
{
$this
->
message
->
display
(
$this
->
t
(
'Migration failed with source plugin exception: !e'
,
array
(
'!e'
=>
$e
->
getMessage
())));
return
MigrationInterface
::
RESULT_FAILED
;
}
while
(
$source
->
valid
())
{
$row
=
$source
->
current
();
if
(
$this
->
sourceIdValues
=
$row
->
getSourceIdValues
())
{
// Wipe old messages, and save any new messages.
$id_map
->
delete
(
$row
->
getSourceIdValues
(),
TRUE
);
$this
->
saveQueuedMessages
();
}
$this
->
processRow
(
$row
);
try
{
$destination_id_values
=
$destination
->
import
(
$row
);
// @TODO handle the successful but no ID case like config.
if
(
$destination_id_values
)
{
$id_map
->
saveIdMapping
(
$row
,
$destination_id_values
,
$this
->
needsUpdate
,
$this
->
rollbackAction
);
$this
->
successes_since_feedback
++
;
$this
->
total_successes
++
;
}
else
{
$id_map
->
saveIdMapping
(
$row
,
array
(),
MigrateIdMapInterface
::
STATUS_FAILED
,
$this
->
rollbackAction
);
if
(
$id_map
->
messageCount
()
==
0
)
{
$message
=
$this
->
t
(
'New object was not saved, no error provided'
);
$this
->
saveMessage
(
$message
);
$this
->
message
->
display
(
$message
);
}
}
}
catch
(
MigrateException
$e
)
{
$this
->
migration
->
getIdMap
()
->
saveIdMapping
(
$row
,
array
(),
$e
->
getStatus
(),
$this
->
rollbackAction
);
$this
->
saveMessage
(
$e
->
getMessage
(),
$e
->
getLevel
());
$this
->
message
->
display
(
$e
->
getMessage
());
}
catch
(
\Exception
$e
)
{
$this
->
migration
->
getIdMap
()
->
saveIdMapping
(
$row
,
array
(),
MigrateIdMapInterface
::
STATUS_FAILED
,
$this
->
rollbackAction
);
$this
->
handleException
(
$e
);
}
$this
->
total_processed
++
;
$this
->
processed_since_feedback
++
;
if
(
$highwater_property
=
$this
->
migration
->
get
(
'highwaterProperty'
))
{
$this
->
migration
->
saveHighwater
(
$row
->
getSourceProperty
(
$highwater_property
[
'name'
]));
}
// Reset row properties.
unset
(
$sourceValues
,
$destinationValues
);
$this
->
needsUpdate
=
MigrateIdMapInterface
::
STATUS_IMPORTED
;
// TODO: Temporary. Remove when http://drupal.org/node/375494 is committed.
// TODO: Should be done in MigrateDestinationEntity
if
(
!
empty
(
$destination
->
entityType
))
{
entity_get_controller
(
$destination
->
entityType
)
->
resetCache
();
}
if
((
$return
=
$this
->
checkStatus
())
!=
MigrationInterface
::
RESULT_COMPLETED
)
{
break
;
}
if
(
$this
->
timeOptionExceeded
())
{
break
;
}
try
{
$source
->
next
();
}
catch
(
\Exception
$e
)
{
$this
->
message
->
display
(
$this
->
t
(
'Migration failed with source plugin exception: !e'
,
array
(
'!e'
=>
$e
->
getMessage
())));
return
MigrationInterface
::
RESULT_FAILED
;
}
}
/**
* @TODO uncomment this
*/
#$this->progressMessage($return);
return
$return
;
}
/**
* @param Row $row
* The $row to be processed.
* @param array $process
* A process pipeline configuration. If not set, the top level process
* configuration in the migration entity is used.
* @param mixed $value
* Optional initial value of the pipeline for the first destination.
* Usually setting this is not necessary as $process typically starts with
* a 'get'. This is useful only when the $process contains a single
* destination and needs to access a value outside of the source. See
* \Drupal\migrate\Plugin\migrate\process\Iterator::transformKey for an
* example.
*/
public
function
processRow
(
Row
$row
,
array
$process
=
NULL
,
$value
=
NULL
)
{
foreach
(
$this
->
migration
->
getProcessPlugins
(
$process
)
as
$destination
=>
$plugins
)
{
foreach
(
$plugins
as
$plugin
)
{
$value
=
$plugin
->
transform
(
$value
,
$this
,
$row
,
$destination
);
}
$row
->
setDestinationProperty
(
$destination
,
$value
);
// Reset the value.
$value
=
NULL
;
}
}
/**
* Fetch the key array for the current source record.
*
* @return array
*/
protected
function
currentSourceIds
()
{
return
$this
->
getSource
()
->
getCurrentIds
();
}
/**
* Test whether we've exceeded the designated time limit.
*
* @return boolean
* TRUE if the threshold is exceeded, FALSE if not.
*/
protected
function
timeOptionExceeded
()
{
if
(
!
$time_limit
=
$this
->
getTimeLimit
())
{
return
FALSE
;
}
$time_elapsed
=
time
()
-
REQUEST_TIME
;
if
(
$time_elapsed
>=
$time_limit
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
public
function
getTimeLimit
()
{
if
(
isset
(
$this
->
options
[
'limit'
])
&&
(
$this
->
options
[
'limit'
][
'unit'
]
==
'seconds'
||
$this
->
options
[
'limit'
][
'unit'
]
==
'second'
))
{
return
$this
->
options
[
'limit'
][
'value'
];
}
else
{
return
NULL
;
}
}
/**
* Pass messages through to the map class.
*
* @param string $message
* The message to record.
* @param int $level
* Optional message severity (defaults to MESSAGE_ERROR).
*/
public
function
saveMessage
(
$message
,
$level
=
MigrationInterface
::
MESSAGE_ERROR
)
{
$this
->
migration
->
getIdMap
()
->
saveMessage
(
$this
->
sourceIdValues
,
$message
,
$level
);
}
/**
* Queue messages to be later saved through the map class.
*
* @param string $message
* The message to record.
* @param int $level
* Optional message severity (defaults to MESSAGE_ERROR).
*/
public
function
queueMessage
(
$message
,
$level
=
MigrationInterface
::
MESSAGE_ERROR
)
{
$this
->
queuedMessages
[]
=
array
(
'message'
=>
$message
,
'level'
=>
$level
);
}
/**
* Save any messages we've queued up to the message table.
*/
public
function
saveQueuedMessages
()
{
foreach
(
$this
->
queuedMessages
as
$queued_message
)
{
$this
->
saveMessage
(
$queued_message
[
'message'
],
$queued_message
[
'level'
]);
}
$this
->
queuedMessages
=
array
();
}
/**
* Standard top-of-loop stuff, common between rollback and import - check
* for exceptional conditions, and display feedback.
*/
protected
function
checkStatus
()
{
if
(
$this
->
memoryExceeded
())
{
return
MigrationInterface
::
RESULT_INCOMPLETE
;
}
if
(
$this
->
timeExceeded
())
{
return
MigrationInterface
::
RESULT_INCOMPLETE
;
}
/*
* @TODO uncomment this
if ($this->getStatus() == MigrationInterface::STATUS_STOPPING) {
return MigrationBase::RESULT_STOPPED;
}
*/
// If feedback is requested, produce a progress message at the proper time
/*
* @TODO uncomment this
if (isset($this->feedback)) {
if (($this->feedback_unit == 'seconds' && time() - $this->lastfeedback >= $this->feedback) ||
($this->feedback_unit == 'items' && $this->processed_since_feedback >= $this->feedback)) {
$this->progressMessage(MigrationInterface::RESULT_INCOMPLETE);
}
}
*/
return
MigrationInterface
::
RESULT_COMPLETED
;
}
/**
* Test whether we've exceeded the desired memory threshold. If so, output a message.
*
* @return boolean
* TRUE if the threshold is exceeded, FALSE if not.
*/
protected
function
memoryExceeded
()
{
$usage
=
memory_get_usage
();
$pct_memory
=
$usage
/
$this
->
memoryLimit
;
if
(
$pct_memory
>
$this
->
memoryThreshold
)
{
$this
->
message
->
display
(
$this
->
t
(
'Memory usage is !usage (!pct% of limit !limit), resetting statics'
,
array
(
'!pct'
=>
round
(
$pct_memory
*
100
),
'!usage'
=>
format_size
(
$usage
),
'!limit'
=>
format_size
(
$this
->
memoryLimit
))),
'warning'
);
// First, try resetting Drupal's static storage - this frequently releases
// plenty of memory to continue
drupal_static_reset
();
$usage
=
memory_get_usage
();
$pct_memory
=
$usage
/
$this
->
memoryLimit
;
// Use a lower threshold - we don't want to be in a situation where we keep
// coming back here and trimming a tiny amount
if
(
$pct_memory
>
(
.90
*
$this
->
memoryThreshold
))
{
$this
->
message
->
display
(
$this
->
t
(
'Memory usage is now !usage (!pct% of limit !limit), not enough reclaimed, starting new batch'
,
array
(
'!pct'
=>
round
(
$pct_memory
*
100
),
'!usage'
=>
format_size
(
$usage
),
'!limit'
=>
format_size
(
$this
->
memoryLimit
))),
'warning'
);
return
TRUE
;
}
else
{
$this
->
message
->
display
(
$this
->
t
(
'Memory usage is now !usage (!pct% of limit !limit), reclaimed enough, continuing'
,
array
(
'!pct'
=>
round
(
$pct_memory
*
100
),
'!usage'
=>
format_size
(
$usage
),
'!limit'
=>
format_size
(
$this
->
memoryLimit
))),
'warning'
);
return
FALSE
;
}
}
else
{
return
FALSE
;
}
}
/**
* Test whether we're approaching the PHP time limit.
*
* @return boolean
* TRUE if the threshold is exceeded, FALSE if not.
*/
protected
function
timeExceeded
()
{
if
(
$this
->
timeLimit
==
0
)
{
return
FALSE
;
}
$time_elapsed
=
time
()
-
REQUEST_TIME
;
$pct_time
=
$time_elapsed
/
$this
->
timeLimit
;
if
(
$pct_time
>
$this
->
timeThreshold
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
/**
* Takes an Exception object and both saves and displays it, pulling additional
* information on the location triggering the exception.
*
* @param \Exception $exception
* Object representing the exception.
* @param boolean $save
* Whether to save the message in the migration's mapping table. Set to FALSE
* in contexts where this doesn't make sense.
*/
public
function
handleException
(
$exception
,
$save
=
TRUE
)
{
$result
=
_drupal_decode_exception
(
$exception
);
$message
=
$result
[
'!message'
]
.
' ('
.
$result
[
'%file'
]
.
':'
.
$result
[
'%line'
]
.
')'
;
if
(
$save
)
{
$this
->
saveMessage
(
$message
);
}
$this
->
message
->
display
(
$message
);
}
/**
* Translates a string to the current language or to a given language.
*
* See the t() documentation for details.
*/
protected
function
t
(
$string
,
array
$args
=
array
(),
array
$options
=
array
())
{
return
$this
->
translationManager
()
->
translate
(
$string
,
$args
,
$options
);
}
/**
* Gets the translation manager.
*
* @return \Drupal\Core\StringTranslation\TranslationInterface
* The translation manager.
*/
protected
function
translationManager
()
{
if
(
!
$this
->
translationManager
)
{
$this
->
translationManager
=
\Drupal
::
translation
();
}
return
$this
->
translationManager
;
}
}
core/modules/migrate/lib/Drupal/migrate/MigrateMessage.php
0 → 100644
View file @
172cd265
<?php
/**
* @file
* Contains \Drupal\migrate\MigrateMessage.
*/
namespace
Drupal\migrate
;
/**
* Defines a migrate message class.
*/
class
MigrateMessage
implements
MigrateMessageInterface
{
/**
* Displays a migrate message.
*
* @param string $message
* The message to display.
* @param string $type
* The type of message, for example: status or warning.
*/
function
display
(
$message
,
$type
=
'status'
)
{
drupal_set_message
(
$message
,
$type
);
}
}
Prev
1
2
3
4
5
6
Next