Error when extending module-ui base js file magento 2 - magento

I am trying to extend module-ui/base/web/js/form/element/select.js
I have created a module, added requirejs-config.js and copied select.js by creating same file path as it in vendor.
After setup:upgrade and setup:static-content:deploy, I get error saying
"Uncaught Error: Script error for:
Thelist_Customjs/js/form/element/abstract"
My requirejs-config.js file code is as follows
var config = {
map: {
'*': {
'Magento_Ui/js/form/element/select':'Thelist_Customjs/js/form/element/select'
}
}
};

You need to also copy the file from
vendor\magento\module-ui\view\base\web\js\form\element\abstract.js
to
Thelist_Customjs/js/form/element/abstract.js
Becasue in select.js that file is used.

Related

Specifying rootPath for Liquibase via jOOQ generation

I'm trying to utilize jOOQ's ability to generate from Liquibase files. My file structure is as follows:
C
- dev
-- testproject
--- src/main/resources
---- db
----- changelog.xml
In order to reference this file from the jOOQ configuration, I have the following in my build.gradle.kts:
jooq {
configurations {
create("main") {
jooqConfiguration.apply {
generator.apply {
database.apply {
name = "org.jooq.meta.extensions.liquibase.LiquibaseDatabase"
properties.add(Property().apply {
key = "rootPath"
value = "C:/dev/testproject/src/main/resources/db/"
})
properties.add(Property().apply {
key = "scripts"
value = "changelog.xml"
})
}
}
}
}
}
}
I'm using plugin version 7.1.1 and have the following dependencies:
dependencies {
implementation("org.liquibase:liquibase-core:4.8.0") // I tried removing this, no change
jooqGenerator("org.postgresql:postgresql:42.3.2")
jooqGenerator("org.jooq:jooq-meta-extensions-liquibase:3.17.2")
jooqGenerator(files("src/main/resources")) // I don't think this is necessary
}
When I try to run jooqGenerate, the error I get is:
Caused by: liquibase.exception.ChangeLogParseException: The file changelog.xml was not found in
Specifying files by absolute path was removed in Liquibase 4.0. Please use a relative path or add '/' to the classpath parameter.
at liquibase.parser.core.xml.XMLChangeLogSAXParser.parseToNode(XMLChangeLogSAXParser.java:82)
at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:15)
at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:369)
Notice how it doesn't say which directories it looked in. As far as I can tell, the resource accessor is not receiving the rootPath from the configuration. The relevant output from Liquibase is here. Again, it should say it looked in the rootPath, but it doesn't print anything else, so there must be no directories searched.
Not sure if this is helpful, but the jOOQ configuration file in build/tmp/generateJooq definitely has the rootPath:
<property>
<key>rootPath</key>
<value>C:/dev/testproject/src/main/resources/db/</value>
</property>
I'm not sure where I'm going wrong. I've also tried the following values of scripts without setting rootPath and seen the same behavior:
C:/dev/testproject/src/main/resources/db/changelog.xml
src/main/resources/db/changelog.xml
/src/main/resources/db/changelog.xml
classpath:src/main/resources/db/changelog.xml
classpath:/src/main/resources/db/changelog.xml
This was causing the problem (or rather, the confusion):
jooqGenerator(files("src/main/resources"))
Apparently, this sets the classpath of the jooqGenerator task to be src/main/resources! So, knowing that, I fixed my configuration to look like this:
database.apply {
name = "org.jooq.meta.extensions.liquibase.LiquibaseDatabase"
properties.add(Property().apply {
key = "scripts"
value = "classpath:db/changelog.xml"
})
}
Everything is working nicely now.

How to move a file and create missing directories in OS X?

I want to move a file, in OSX, to another directory:
func moveFile(currentPath currentPath: String, targetPath: String) {
let fileManager = NSFileManager.defaultManager()
do { try fileManager.moveItemAtPath(currentPath, toPath: targetPath) }
catch let error as NSError { print(error.description) }
}
Everything is working fine, except the case when the target-directory doesn't exist. I figured out that .isWritableFileAtPath could be helpful.
However, in my declared function I use the full file path (including the filename).
How can I split the filename from the path or more in general: how can I force Swift to create the directory before moving the file if needed?
In the past I have solved this problem with code similar to the code below. Basically you just check to see if a file exists at the path representing the parent directory of the file you want to create. If it does not exist you create it and all folders above it in the path that don't exist as well.
func moveFile(currentPath currentPath: String, targetPath: String) {
let fileManager = NSFileManager.defaultManager()
let parentPath = (targetPath as NSString).stringByDeletingLastPathComponent()
var isDirectory: ObjCBool = false
if !fileManager.fileExistsAtPath(parentPath, isDirectory:&isDirectory) {
fileManager.createDirectoryAtPath(parentPath, withIntermediateDirectories: true, attributes: nil)
// Check to see if file exists, move file, error handling
}
else if isDirectory {
// Check to see if parent path is writable, move file, error handling
}
else {
// Parent path exists and is a file, error handling
}
}
You may also want to use the fileExistsAtPath:isDirectory: variant so you can handle other error cases. Same is true for
I've added this extension to FileManager to achieve this
extension FileManager {
func moveItemCreatingIntermediaryDirectories(at: URL, to: URL) throws {
let parentPath = to.deletingLastPathComponent()
if !fileExists(atPath: parentPath.path) {
try createDirectory(at: parentPath, withIntermediateDirectories: true, attributes: nil)
}
try moveItem(at: at, to: to)
}
}
Adding this because this question pops up in Google and the other answers use an API that they perhaps shouldn't in this context.
It's important to note this in the FileExists(atPath:) docs:
Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file-system race conditions, see Race Conditions and Secure File Operations in Secure Coding Guide.
Also, from the createDirectory(atPath:withIntermediateDirectories:attributes:) docs:
Return Value
true if the directory was created, true if createIntermediates is set and the directory already exists, or false if an error occurred.
Attempting to create a new directory with the withIntermediateDirectories: parameter set to true will not throw an error if that directory already exists, so you can safely use it even if the directory does already exist.
Skip the existence check, try to write the directory, then try to move the file:
func moveFile(from currentURL: URL, to targetURL: URL) {
// Get the target directory by removing the file component
let targetDir = targetURL.deletingLastPathComponent()
do {
try FileManager.default.createDirectory(at:targetDir, withIntermediateDirectories: true, attributes: nil)
} catch {
// Handle errors
}
do {
try FileManager.default.moveItem(at:currentURL, to: targetURL) }
catch {
// Handle errors
}
}

Warning include TestCase phpunit in Magento project

I'm using phpunit for testing in a magento's project.
The issues is that I got this directory inside magento:
magento/
-tests/
--integration/bootstrap.php
---Training/
----Example/
-----Helper/DataTest.php
So, I got a bootstrap.php, inside this file I turn off warnings for my testing:
require_once __DIR__ . '/../../app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
$handler = set_error_handler(function () {});
set_error_handler(function ($errno, $errstr, $errfile, $errline) use ($handler)
{
if (E_WARNING === $errno
&& 0 === strpos($errstr, 'include(')
&& substr($errfile, -19) == 'Varien/Autoload.php'
) {
return null;
}
return call_user_func($handler, $errno, $errstr, $errfile, $errline);
});
If this code is inside of DataTest.php inside the function setUpBeforeClass(), everything is ok, but when I create bootstrap.php and execute in console:
phpunit --bootstrap tests/integration/bootstrap.php tests/integration/
I got the following answer:
Fatal error: Uncaught exception 'Exception' with message 'Warning: include(PHPUnit\Extensions\Story\TestCase.php): failed to open stream: No such file or directory in C:\wamp\www\magento\lib\Varien\Autoload.php on line 94' in C:\wamp\www\magento\app\code\core\Mage\Core\functions.php on line 245
Exception: Warning: include(PHPUnit\Extensions\Story\TestCase.php): failed to open stream: No such file or directory in C:\wamp\www\magento\lib\Varien\Autoload.php on line 94 in C:\wamp\www\magento\app\code\core\Mage\Core\functions.php on line 245
I got phpunit in my local server in bin\php\php5.5.12 (in Windows) and I can access in any directory.
So, I don't understand what's going on... because I do not need to modify the core of magento to disable warnings.
Someone can help me to understand?
Thanks for all!!
:)
Your autoloader is trying to load classes it is not responsible for.

How to get a path out of an NSSavePanel object in Swift

I have been attempting to use the NSSavePanel to save text files in a program written in Swift. The only issue is that every time I attempt to use the URL attribute, it has a nil value. Yes, I have a folder selected and a file name in the input when testing. Here's my code:
let saveDialog = NSSavePanel();
saveDialog.beginWithCompletionHandler() { (result: Int) -> Void in
if result == NSFileHandlingPanelOKButton {
let file = NSFileHandle(forWritingToURL: saveDialog.URL!, error: nil)!;
for match in Globals.matches {
if let data = (match.toString() as NSString).dataUsingEncoding(NSUTF8StringEncoding) {
file.writeData(data);
}
}
}
}
// other setup code not shown
When I run this, I always get the Swift equivalent of a null-pointer exception on the
let file = NSFileHandle(forWritingToURL: saveDialog.URL!, error: nil)!;
line. Can I please have some help? What am I doing wrong?
Check the documentation for NSFileHandle(forWritingToURL:error:), it says:
The initialized file handle object or nil if no file exists at url.
So this only works if the file already exists. Which is probably not what you want.
It looks like NSFileHandle cannot create new files at all, so I would just use the following before you try to open the file:
NSFileManager.defaultManager()
.createFileAtPath(saveDialog.URL.path, contents: NSData(), attributes: nil)
Which will create an empty file, which you can then open and write your data to.

Is it possible require file content "as is" in TypeScript?

Typescript defines comment with xml tag <reference path=""/> to source local files to current file. But that tag could be placed only in file header before declaring any structures such us other modules.
So,
// File1.ts - correct
///<reference path="./Common.ts"/>
module Test {
export class TestClass {
}
}
// File2.ts - incorrect
module Test {
///<reference path="./Common.ts"/> // <<< Here is an compile error
export class TestClass {
}
}
Is it possible to source content of other typescript file to custom place of current file?
No. You cannot require code inplace as you have already found:
// File2.ts - incorrect
module Test {
///<reference path="./Common.ts"/> // <<< Here is an compile error
export class TestClass {
}
}
However you can effectively get the same effect by using functions.
// File1.ts - correct
///<reference path="./Common.ts"/>
module Test {
callAFunctionFoundInCommon();
export class TestClass {
}
}
In the latest version of TypeScript, it is not necessary to reference files manually like that. You can simply remove the reference and TypeScript will be able to figure everything out automatically.

Resources