Resolve conflicts by prompting the user for action

@access private
@param array $result A copymap result containing updates and conflicts
@return boolean TRUE if the user overwrite with the new version, FALSE otherwise
488349
private function resolve(&$result)
	{
		if (!isset($result['conflicts']) || !count($result['conflicts'])) {
			return;
		}

		$original_checksums = isset($this->installationMap['__CHECKSUMS__'])
			? $this->installationMap['__CHECKSUMS__']
			: array();

		foreach ($result['conflicts'] as $a => $b) {
			$base_path        = str_replace(DIRECTORY_SEPARATOR, '/', getcwd());
			$opus_path        = str_replace($base_path, '', $b);
			$current_checksum = md5(@file_get_contents($b));
			$new_checksum     = md5(@file_get_contents($a));
			$old_checksum     = isset($original_checksums[$opus_path])
				? $original_checksums[$opus_path]
				: md5(FALSE);

			switch ($this->integrity) {
				case 'low':
					copy ($a, $b);
					break;

				case 'medium':
					if ($new_checksum == $old_checksum) {

						//
						// A conflict is only raised if the destinaton differs from the source.
						// However, if we "keep" a file on a previous conflict, the map will be
						// updated with the new checksum even though the file is not copied.  By
						// checking if the new checksum is equal to the old, we can determine if
						// the file has actually changed in the package.  If it has not, we
						// don't need to do anything.
						//

						break;

					} elseif ($old_checksum == $current_checksum) {

						//
						// If we didn't pass the previous condition, then it means that the file
						// in the package has changed since the previous copy or keep.  So now
						// we want to see if the old checksum is equivalent to the current file.
						// This would imply we have not changed it.  If we have no customizations
						// then we can  safely copy the file and update the checksum in the map.
						//

						copy($a, $b);
						$result['updates'][$opus_path] = $new_checksum;
						break;

					} else {

						//
						// Lastly, if our new checksum is not the same as our old one and our
						// old one is not our current one, we want to give the user the option
						// to resolve this as if it were 'high' integrity.
						//

					}

				case 'high':
					$answer = NULL;
					$this->io->write(
						PHP_EOL . self::TAB . 'The following conflicts were found:' . PHP_EOL
					);

					while (!$answer) {
						$answer = $this->io->ask(sprintf(
							self::TAB . '- %s [o=overwrite (default), k=keep, d=diff]: ',
							$opus_path
						), 'o');

						switch(strtolower($answer[0])) {
							case 'o':
								copy($a, $b);
								$result['updates'][$opus_path] = $new_checksum;
								break;

							case 'k':
								$result['updates'][$opus_path] = $new_checksum;
								break;

							case 'd':
								$this->io->write(PHP_EOL . self::diff($a, $b) . PHP_EOL);
							default:
								$answer = NULL;
								break;
						}
					}

					break;
			}
		}
	}
521807
public function onResult(\pq\Result $result = null) {
		if ($result && $result->status != \pq\Result::TUPLES_OK) {
			return $result;
		}
		
		$rowset = $this->getRowsetPrototype();
		if (is_callable($rowset)) {
			return $rowset($result);
		} elseif ($rowset) {
			return new $rowset($this, $result);
		}
		
		return $result;
	}
960862
protected function reduceResult($result)
    {
        if (is_array($result) && (count($result) == 1)) {
            reset($result);
            return $this->reduceResult($result[key($result)]);
        } else {
            return $result;
        }
    }
471595
public function setResult($jobname, $result = null)
    {
        if (isset($this->results[$jobname])) {
            return false;
        }
        $this->results[$jobname] = $result;
        ++$this->resultsNum;
        $this->checkIfAllReady();
        return true;
    }
265780
protected function finishAddOrderCheckout(array $result)
    {
        if (!empty($result['order']['order_id'])) {

            $vars = array(
                '@num' => $result['order']['order_id'],
                '@name' => $result['order']['customer_name'],
                '@status' => $this->order->getStatusName($result['order']['status'])
            );

            $message = $this->text('Order #@num has been created for user @name. Order status: @status', $vars);
            $this->redirect("admin/sale/order/{$result['order']['order_id']}", $message, 'success');
        }
    }
189788
protected function finishOrderCheckout(array $result)
    {
        if ($this->admin === 'add') {
            $this->finishAddOrderCheckout($result);
        } else if ($this->admin === 'clone') {
            $this->finishCloneOrderCheckout($result);
        }

        $this->redirect($result['redirect'], $result['message'], $result['severity']);
    }
595239
public static function keyPair(array $result): array
    {
        $firstRow = current($result);
        if (empty($firstRow)) {
            return $result;
        }

        list($keyName, $valueName) = array_keys($firstRow);

        return array_combine(
            array_column($result, $keyName),
            array_column($result, $valueName)
        );
    }
1001310
public function getRow($result = NULL, $useExceptions = _DbConfig::USE_EXCEPTIONS) {
        if ($result === NULL) {
            $result = $this->lastResult;
        }
        if ($this->count() <= 0) {
            return FALSE;
        }
        $this->lastRow = $this->lastResult->fetch_assoc();
        return $this->lastRow;
    }
171687
private function processResult(array $result)
    {
        $this->checkResponseStatus($result['http_code']);

        // Get decoded response data
        $responseArr = json_decode($result['response'], true);

        $this->checkJsonError();

        return $responseArr;
    }
131874
private function createResult($result)
    {
        switch (\pg_result_status($result, \PGSQL_STATUS_LONG)) {
            case \PGSQL_EMPTY_QUERY:
                throw new QueryError("Empty query string");

            case \PGSQL_COMMAND_OK:
                return new PgSqlCommandResult($result);

            case \PGSQL_TUPLES_OK:
                return new PgSqlResultSet($result);

            case \PGSQL_NONFATAL_ERROR:
            case \PGSQL_FATAL_ERROR:
                $diagnostics = [];
                foreach (self::DIAGNOSTIC_CODES as $fieldCode => $desciption) {
                    $diagnostics[$desciption] = \pg_result_error_field($result, $fieldCode);
                }
                throw new QueryExecutionError(\pg_result_error($result), $diagnostics);

            case \PGSQL_BAD_RESPONSE:
                throw new FailureException(\pg_result_error($result));

            default:
                // @codeCoverageIgnoreStart
                throw new FailureException("Unknown result status");
                // @codeCoverageIgnoreEnd
        }
    }
1364771
protected function handleResult(array $result)
    {
        if ($this->onlyCount && isset($result[0]) && is_array($result[0])) {
            return (int)current($result[0]);
        }

        $entities = [];
        foreach ($result as $row) {
            $model = clone $this->getModel();
            $model->populate($row);
            $entities[] = $model;
        }
        return $entities;
    }
521898
protected function _autoBuild($result) {
		$hasError = (
			isset($result['error']) &&
			isset($result['reason']) &&
			$result['reason'] === "no_db_file"
		);
		if ($hasError) {
			$this->connection->put($this->_config['database']);
			return true;
		}
		return false;
	}
1112981
protected function after_update($result) {
        global $DB;

        if (!$result) {
            $this->beforeupdate = null;
            return;
        }

        // The parent ID has changed, we need to fix all the paths of the children.
        if ($this->beforeupdate->get('parentid') != $this->get('parentid')) {
            $beforepath = $this->beforeupdate->get('path') . $this->get('id') . '/';

            $like = $DB->sql_like('path', '?');
            $likesearch = $DB->sql_like_escape($beforepath) . '%';

            $table = '{' . self::TABLE . '}';
            $sql = "UPDATE $table SET path = REPLACE(path, ?, ?) WHERE " . $like;
            $DB->execute($sql, array(
                $beforepath,
                $this->get('path') . $this->get('id') . '/',
                $likesearch
            ));

            // Resolving sortorder holes left after changing parent.
            $table = '{' . self::TABLE . '}';
            $sql = "UPDATE $table SET sortorder = sortorder -1 "
                    . " WHERE  competencyframeworkid = ? AND parentid = ? AND sortorder > ?";
            $DB->execute($sql, array($this->get('competencyframeworkid'),
                                        $this->beforeupdate->get('parentid'),
                                        $this->beforeupdate->get('sortorder')
                                    ));
        }

        $this->beforeupdate = null;
    }
204708
protected function collectionFromResult($result)
    {
        // If we have one result which is not an assoc array, make it the first element of an array for the
        // collectionFromResult function so we always return a collection from filter
        if ((bool) count(array_filter(array_keys($result), 'is_string'))) {
            $result = [$result];
        }

        $class = $this->class;
        $collection = [];

        foreach ($result as $r) {
            $collection[] = new $class($this->connection, $r);
        }

        return $collection;
    }
176052
public function buildResult($result)
    {
        $chatMembers = [];

        foreach ($result as $item) {
            $chatMembers[] = new ChatMember($item);
        }

        return $chatMembers;
    }
981620
protected function renameResult(array &$result, $old, $new)
    {

        // Check to see if the old item is there
        if (isset($result[$old])) {
            $result[$new] = $result[$old];
            unset($result[$old]);
        }
    }
739307
protected function _checkResult($result) {
        $rvalue = true;
        foreach ($result as $socketName => $value) {
            if ($value !== true) {
                Mage::helper('turpentine/debug')->logWarn(
                    'Error in Varnish action result for server [%s]: %s',
                    $socketName, $value );
                $rvalue = false;
            }
        }
        return $rvalue;
    }