Laravel 5.3 migration - laravel-5

I just upgrade to Laravel to 5.x and using "jenssegers/Date": "^3.0".
So while migrating, there seems to be an error:
[ErrorException] Declaration of
Jenssegers\Date\Date::diffForHumans(Carbon\Carbon $since = NULL,
$absolute = false) should be compatible with
Carbon\Carbon::diffForHumans(Carbon\Carbon $other = NULL, $absolute =
false, $short = false)
Please suggest what can be done to fix it.

Actually your problem is with this package jenssegers/date. As you can see Jenssegers\Date extends Carbon and on line 104
public function diffForHumans(Carbon $since = null, $absolute = false, $short = false)
has different implementation than Carbon
public function diffForHumans(Carbon $other = null, $absolute = false)
The way to overcome this is to redefine the method on either class, which is not recommended because they are both within Vendor folder. So I guess your options would be to either open up an issue on jassegers/date, or try not to use that package (write your own replacement if you don't use it that much).
The problem can be even more difficult if you don't have this package in your projects Composer.json, but some other package you use has jassegers/date as a dependency. You can check this in the Vendor in Composer.json of each of your projects dependencies. In this case you might consider using a different package than the one that uses jassegers/date as a dependency, at least until it's updated.
Perhaps someone has better suggestions, this is just of the top of my head..
P.S. Just remembered.. you can also fork jassegers/date if you're using it directly in your Composer.json, and change the method implementation by yourself and use that forked version until the genuine one is fixed. If you use it indirectly (some other package you use has this as a dependency), that would be a bit more complicated, meaning you would have to fork packages all the way down until you get to jassegers/date. This would be quite tedious work, but should fix the problem temporarily.

If you compare current Carbon source code:
public function diffForHumans(Carbon $other = null, $absolute = false, $short = false)
with current jenssegers/Date source code:
public function diffForHumans(Carbon $since = null, $absolute = false, $short = false)
you see there shouldn't be any issues. It seems that you're using newer Carbon than jenssegers/Date, and versions are incompatible. You need to update your jenssegers/Date.
3.2.8 seems to be the latest release, I'd test going there. 3.2.3 seems to be the first version including the third parameter, with this commit:
Carbon\Carbon::diffForHumans(Carbon\Carbon $other = NULL, $absolute =
false, $short = false) has a new third argument and lack of it in
Jenssegers\Date\Date::diffForHumans is not playing nicely.
so your version needs to be at least that.

Related

testReport destinationDir is deprecated in gradle 7.4.2 so how to set it?

task<TestReport>("testReport") {
destinationDir = file("$buildDir/reports/allTests")
}
This is apparently deprecated, but the deprecation message doesn't make sense to me in this context. How am I actually supposed to set this value now?
/**
* Sets the directory to write the HTML report to.
*
* <strong>This method will be {#code #Deprecated} soon, please use {#link #getTestResults()} instead to access the new collection property.</strong>
*/
public void setDestinationDir(File destinationDir) {
DeprecationLogger.deprecateProperty(TestReport.class, "destinationDir").replaceWith("destinationDirectory")
.willBeRemovedInGradle8()
.withDslReference()
.nagUser();
getDestinationDirectory().set(destinationDir);
}
Please try like this.
Older version:
destinationDir = file("$buildDir/reports/tests/test")
With latest version:
getDestinationDirectory().set(file("$buildDir/reports/tests/test"))
It worked for me. Hope it'll work for you. Thanks

Problem with Protostream and UUID in Infinispan 13.0.0.Final

I'm using Infinispan 13.0.0.final with the default marshaller (protobuf). When I try to use UUID fields in my datatypes
data class CounterState(
#get:ProtoField(number = 1) var index: Long? = null,
#get:ProtoField(number = 2) var uuid: UUID? = null
)
I get the following error at build time:
.../gradle-kotlin-protobuf/build/tmp/kapt3/stubs/main/io/radiosphere/ProtoSchema.java:8: error: org.infinispan.protostream.annotations.ProtoSchemaBuilderException: The class java.util.UUID must be instantiable using an accessible no-argument constructor.
public abstract interface ProtoSchema extends org.infinispan.protostream.GeneratedSchema {
It seems like I'm not allowed to use UUID in my types unless I generate a protoschema for it, but since UUID is a class outside of my control I can't do this.
Previous questions on the topic have gotten the suggestion to use the JavaSerializationMarshaller, but I want to solve this while still using the Protostream Marshaller. It has also been suggested that this would be fixed in version 12.0.0 here.
An example of this not working can be found here. Note that this project will not build because of the annotation processing failing as mentioned above. If it would build the proof that it is working would be shown by running the main project (ie. not the tests).
The question becomes: What do I need to do to configure UUID to be usable in my protobuf marshalled classes in Infinispan 13? Both for embedded and for a program using the hotrod client?
EDIT:
Based on a given answer I have also tried doing the following:
#AutoProtoSchemaBuilder(
includeClasses = [UUIDAdapter::class, CounterState::class],
schemaPackageName = "tutorial")
interface ProtoSchema : GeneratedSchema {
}
This makes the build work, but when starting Quarkus I get the following error:
Caused by: org.infinispan.protostream.DescriptorParserException: Duplicate type id 1005 for type org.infinispan.protostream.commons.UUID. Already used by tutorial.UUID
at org.infinispan.protostream.descriptors.ResolutionContext.checkUniqueTypeId(ResolutionContext.java:151)
at org.infinispan.protostream.descriptors.ResolutionContext.addGenericDescriptor(ResolutionContext.java:97)
at org.infinispan.protostream.descriptors.FileDescriptor.collectDescriptors(FileDescriptor.java:313)
at org.infinispan.protostream.descriptors.FileDescriptor.resolveDependencies(FileDescriptor.java:245)
at org.infinispan.protostream.descriptors.FileDescriptor.resolveDependencies(FileDescriptor.java:210)
at org.infinispan.protostream.descriptors.ResolutionContext.resolve(ResolutionContext.java:57)
at org.infinispan.protostream.impl.SerializationContextImpl.registerProtoFiles(SerializationContextImpl.java:127)
at org.infinispan.protostream.types.java.CommonTypesSchema.registerSchema(CommonTypesSchema.java:49)
at org.infinispan.client.hotrod.RemoteCacheManager.registerSerializationContextInitializer(RemoteCacheManager.java:422)
at org.infinispan.client.hotrod.RemoteCacheManager.registerDefaultSchemas(RemoteCacheManager.java:437)
at org.infinispan.client.hotrod.RemoteCacheManager.initializeProtoStreamMarshaller(RemoteCacheManager.java:409)
at org.infinispan.client.hotrod.RemoteCacheManager.actualStart(RemoteCacheManager.java:365)
at org.infinispan.client.hotrod.RemoteCacheManager.start(RemoteCacheManager.java:334)
at org.infinispan.client.hotrod.RemoteCacheManager.<init>(RemoteCacheManager.java:192)
at org.infinispan.client.hotrod.RemoteCacheManager.<init>(RemoteCacheManager.java:149)
at io.quarkus.infinispan.client.runtime.InfinispanClientProducer.initialize(InfinispanClientProducer.java:68)
If I instead change to use dependsOn like this:
#AutoProtoSchemaBuilder(
includeClasses = [CounterState::class],
dependsOn = [org.infinispan.protostream.types.java.CommonTypes::class, org.infinispan.protostream.types.java.CommonContainerTypes::class],
schemaPackageName = "tutorial")
I'm back to the build failing with:
error: org.infinispan.protostream.annotations.ProtoSchemaBuilderException: The class java.util.UUID must be instantiable using an accessible no-argument constructor.
public abstract interface ProtoSchema extends org.infinispan.protostream.GeneratedSchema {
It seems to be like Quarkus and the Annotation processor are getting in each others way here when it comes to having a simple working solution for UUID marshalling.
You have to include the org.infinispan.protostream.types.java.util.UUIDAdapter class in your annotation:
#AutoProtoSchemaBuilder(includeClasses = [CounterState::class, UUIDAdapter::class] , schemaPackageName = "tutorial")
For more info, check the documentation page.

Getting Webpack 2 to support IE8

I want to use Webpack 2 in a large project which must still support IE8.
I've installed babel-preset-env so I can easily deprecate any IE < 11 in future, one by one, once each of the browsers becomes unsupported by this project.
According to the babel-preset-env readme "If you are targeting IE 8 and Chrome 55 [babel-preset-env] will include all plugins required by IE 8 since you would need to support both still."
As I understand it, I also need to install babel-polyfill mostly for its IE5 shim, but also for its polyfills for ES6 and 7 features that I may wish to use.
However having installed these things, my code still falls over on IE8 (in Browserstack) at the point where Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); is first run. A function I thought was getting 'fixed' by the shims.
Is it not getting shimmed properly? Have I missed out a step?
I had the same problem before and here is what I did to solve.
In es6 features,
a class can define a property with get and set to encapsulate a field.
but it is not woroking on IE8.
because the defineProperty method is not supported see the docs,
so we changed the whole code pattern to like below
let val1;
class className {
methodName() {
this.val2 = 'test';
//code here
}
getVal1() {
return val1;
}
setVal1(_val1) {
val1 = _val1;
}
getVal2() {
return this.val2;
}
setVal2(_val2) {
this.val2 = _val2;
}
}
module.exports = className;
and I recommend that adding 'es3ify' see the link,github es3ify to your webpack build for IE7/8

Conditional get in Spring framework

I am trying to learn Scala using Spring framework. I have to implement conditional get logic in my code. I understand it could be done using etag or Last-Modified option.
Here is my piece of code:
var lastModifiedTime: Long = _;
#RequestMapping(value= Array("/users/{id}"),method=Array(RequestMethod.GET),headers = Array("Content-Type=application/json"))
#ResponseBody
def getmeth(request: User_details, web: WebRequest): User_details = {
if (web.checkNotModified(lastModifiedTime)) {
return null
} else {
lastModifiedTime = System.currentTimeMillis()
}
Could you please help me to fix this code?
Disclaimer: I don't know Spring Web.
But according to the documentation fist of all you should take action if request is modified so you should remove bang (!) from condition. Also lastModifiedTime should be computed from the outside of the getmeth method.
Notice that unlike in Java if statement is an expression and it returns value so you shouldn't use return statement.
As it was said in comment conditional code can be easy and safely done using Scala's Option. In Scala you should always avoid null, as it is hard to distinguish it from incorrect behavior of your code, and it is very easy to forget or don't know that it is required to write logic dealing with it - you must always read the javadoc (assuming it exists and it is up to date). When you use Option type compiler will force you to deal with "nullability".
def getmeth(request: User_details, web: WebRequest): Option[User_details] =
if (web.checkNotModified(lastModifiedTime)) {
None
} else {
val userDetails = yourLogic()
Some(userDetails)
}
Then you can perform an action when option is a Some instance. To do that you can use map method.
getmeth(req, web) map { userDetails =>
userDetails.getName
}
EDIT: #optimus Now when you gave wider scope I see that your method signature is forced by framework and yon can't wrap your value with Option. I think that your problem may be that you update lastModifiedTime on every request so it seems reasonable to me that checkNotModified is always false. I think that you should use that feature only on requests that not always update checkNotModified to current time. It becomes pointless otherwise.
Update lastModifiedTime once your resource has become outdated.
#ResponseStatus(HttpStatus.OK)
#RequestMapping(value = Array("/users/{user_id}"),method = Array(RequestMethod.GET))
def getUser(#PathVariable("user_id") user_id: String,
#Context req : Request ): Any = {
val u = hm.get(user_id).asInstanceOf[User]
val tag = u.hashCode().asInstanceOf[EntityTag]
if (req.getMethod().equals("GET")) {
val rb : Response.ResponseBuilder = req.evaluatePreconditions(tag);
if (rb != null)
{
rb
}
else
{
// val u = hm.get(user_id).asInstanceOf[User]
u
}
}

why can a CacheDependency be invalid right after creating it! (ASP.NET-MVC3)

Whenever I make a CacheDependency in a testbed, it works fine.
If I write
var dep = new CacheDependency(null, new string[] { "dep" });
dep will be a new CacheDependency, with the properties: HasChanged = false, UtcLastModified = the current datetime.
But somehow in one of my projects the same line of code instantiates a cachedependency with HasChanged = true, UtcLastModified = 1/1/0001 12:00:00 AM
This dependency is invalid/useless by default. What can cause this? Is it possible that it is because I don't instantiate the dependency directly in the controller, but in an extension method of one of my objects?
But HttpRuntime.Cache works fine there without dependencies.
If you have any idea what can cause this please share.
I have found out that if the cache item that you depend on is null, then the cache dependency is automatically invalid.

Resources