Scalr\Farm\Role\FarmRoleStorageConfig::delete PHP Метод

delete() публичный Метод

public delete ( $id = null )
    public function delete($id = null)
    {
        $id = !is_null($id) ? $id : $this->id;
        $this->db->Execute('DELETE FROM farm_role_storage_settings WHERE storage_config_id = ?', array($id));
        //TODO: NEET TO SET FarmRoleStorageDevice::TYPE_ZOMBY to all devices of deleted config
        // $this->db->Execute('DELETE FROM farm_role_storage_devices WHERE storage_id = ?', array($id));
        $this->db->Execute('DELETE FROM farm_role_storage_config WHERE id = ?', array($id));
    }

Usage Example

Пример #1
0
 /**
  * Save storage configs
  *
  * @param   array   $configs    Array of storage config
  * @param   bool    $validate   optional    If true validate config before save
  * @throws  FarmRoleStorageException
  */
 public function setConfigs($configs, $validate = true)
 {
     $configs = is_array($configs) ? $configs : [];
     $ephemeralEc2 = [];
     $ephemeralGce = [];
     foreach ($configs as $value) {
         if (!is_array($value) || !is_array($value['settings'])) {
             continue;
         }
         $object = new FarmRoleStorageConfig($this->farmRole);
         $object->apply($value);
         if ($validate) {
             $r = $object->validate();
             if ($r !== true) {
                 throw new FarmRoleStorageException($r);
             }
         }
         $config = new FarmRoleStorageConfig($this->farmRole);
         $config->create($object);
         if ($config->type == FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL) {
             $ephemeralEc2[$config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME]] = $config->id;
         } else {
             if ($config->type == FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL) {
                 $ephemeralGce[$config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME]] = $config->id;
             }
         }
     }
     // validate ephemeral configs
     foreach (self::getConfigs() as $config) {
         if ($config->type == FarmRoleStorageConfig::TYPE_EC2_EPHEMERAL) {
             $name = $config->settings[FarmRoleStorageConfig::SETTING_EC2_EPHEMERAL_NAME];
             if (!isset($ephemeralEc2[$name]) || $ephemeralEc2[$name] != $config->id) {
                 $config->delete();
             }
         } else {
             if ($config->type == FarmRoleStorageConfig::TYPE_GCE_EPHEMERAL) {
                 $name = $config->settings[FarmRoleStorageConfig::SETTING_GCE_EPHEMERAL_NAME];
                 if (!isset($ephemeralGce[$name]) || $ephemeralGce[$name] != $config->id) {
                     $config->delete();
                 }
             }
         }
     }
 }