You are here

function skinr_skin_import in Skinr 8.2

Same name and namespace in other branches
  1. 7.2 skinr.module \skinr_skin_import()

Import a skin configuration object as defined in skinr_skin_defaults().

Parameters

$default_skin: A skin configuration object.

$force: If FALSE (default) the default skin will only be imported if the skin configuration doesn't exist, or if storage is default in code. If TRUE, the skin configuration in code will always be overwritten.

Return value

If import failed, returns FALSE. If it succeeded, returns TRUE.

4 calls to skinr_skin_import()
SkinrApiTest::_testSkinrSkinDefaults in src/Tests/SkinrApiTest.php
Test default skin configurations (in code).
SkinrApiTestCase::testSkinrSkinDefaults in src/Tests/skinr.test
Test default skin configurations (in code).
skinr_skin_defaults_import in ./skinr.module
Imports default skin confiuration objects from code into database.
skinr_skin_revert in ./skinr.module
Revert a skin configuration object that's stored in code to its default state.

File

./skinr.module, line 836
Handles core Skinr functionality.

Code

function skinr_skin_import($default_skin, $force = FALSE) {

  // Make sure we don't modify the cached default skin array.
  $skin = clone $default_skin;

  // Functionality is abstracted for use in skinr_skin_storage().
  _skinr_skin_import($skin);
  if (!$force && !empty($skin->sid)) {

    // Load existing skin configuration from DB.
    $db_skin = entity_load('skin', $skin->sid, TRUE);

    // Sync status.
    $skin->status = $db_skin->status;
    if ($skin != $db_skin) {

      // Skin exists and is overridden, so cancel import.
      \Drupal::logger('skinr')
        ->warning('Canceled import of skin with UUID %uuid and SID %sid. It is overridden.', array(
        '%uuid' => $skin->uuid,
        '%sid' => $skin->sid,
      ));
      return FALSE;
    }
  }
  if ($status = skinr_skin_save($skin)) {
    drupal_static_reset('skinr_skin_uuid_to_sid');
    drupal_static_reset('skinr_skin_sid_to_uuid');
    \Drupal::logger('skinr')
      ->notice('Imported skin with UUID %uuid and SID %sid.', array(
      '%uuid' => $skin->uuid,
      '%sid' => $skin->sid,
    ));
  }
  else {
    \Drupal::logger('skinr')
      ->warning('Failed to import skin with UUID %uuid and SID %sid.', array(
      '%uuid' => $skin->uuid,
      '%sid' => isset($skin->sid) ? $skin->sid : t('unknown'),
    ));
  }
  return $status;
}